blob: d96c0c59b00a0204228743c06849e92925668134 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshinfa314642021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080032import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000033import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080034import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070035import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070036import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.content.Context;
38import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070039import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070040import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080041import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070042import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.net.Uri;
44import android.os.AsyncResult;
45import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080046import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.Bundle;
48import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070049import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Looper;
51import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080053import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070054import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070055import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080056import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080057import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070058import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070059import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080060import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070062import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070063import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070064import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070065import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080066import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070067import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090068import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080069import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080070import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070071import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070072import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080073import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080074import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070075import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080076import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070077import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080078import android.telephony.CellIdentityCdma;
79import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070081import android.telephony.CellInfoGsm;
82import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070083import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080084import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070085import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070086import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070087import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080088import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070089import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080090import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070091import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080092import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080093import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070094import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080095import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080097import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080098import android.telephony.SignalStrengthUpdateRequest;
99import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800100import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800101import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800102import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700103import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700104import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800105import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800106import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800107import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000108import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700109import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700110import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800111import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800112import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800113import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700114import android.telephony.gba.GbaAuthRequest;
115import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700116import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800117import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000118import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000119import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700120import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700121import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800122import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700123import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800124import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700125import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000126import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700127import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800128import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800129import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800130import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800131import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800133import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700134import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800136import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800137
Andrew Lee312e8172014-10-23 17:01:36 -0700138import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800139import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800140import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800141import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800142import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700143import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700144import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700145import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800146import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700147import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700148import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800149import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700151import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800152import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800153import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800154import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700155import com.android.internal.telephony.ICallForwardingInfoCallback;
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;
joonhunshinfa314642021-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;
Nathan Haroldb3014052017-01-25 15:57:32 -0800190import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700191import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800192import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700193import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800194import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000195import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800196import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700197import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700198import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800199import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800200import com.android.phone.callcomposer.CallComposerPictureManager;
201import com.android.phone.callcomposer.CallComposerPictureTransfer;
202import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700203import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700204import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800205import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700206import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700207import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800208import com.android.services.telephony.TelecomAccountRegistry;
209import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800210import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800211
Hall Liu82694d52020-12-11 18:22:04 -0800212import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700213import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800214import java.io.IOException;
215import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700216import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800218import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800219import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800220import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800221import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100222import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800223import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700224import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800226import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800227import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800228import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800229import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700230
231/**
232 * Implementation of the ITelephony interface.
233 */
Santos Cordon117fee72014-05-16 17:56:12 -0700234public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235 private static final String LOG_TAG = "PhoneInterfaceManager";
236 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
237 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800238 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239
240 // Message codes used with mMainThreadHandler
241 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700242 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
243 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700244 private static final int CMD_OPEN_CHANNEL = 9;
245 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
246 private static final int CMD_CLOSE_CHANNEL = 11;
247 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800248 private static final int CMD_NV_READ_ITEM = 13;
249 private static final int EVENT_NV_READ_ITEM_DONE = 14;
250 private static final int CMD_NV_WRITE_ITEM = 15;
251 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
252 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
253 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700254 private static final int CMD_RESET_MODEM_CONFIG = 19;
255 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800256 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
257 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800258 private static final int CMD_SEND_ENVELOPE = 25;
259 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000260 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
261 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700262 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
263 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
264 private static final int CMD_EXCHANGE_SIM_IO = 31;
265 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800266 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
267 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700268 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
269 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700270 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
271 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700272 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
273 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
274 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
275 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700276 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
277 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
278 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
279 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700280 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800281 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
282 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000283 private static final int CMD_SWITCH_SLOTS = 50;
284 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700285 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
286 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
287 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
288 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
289 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
290 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
291 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
292 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700293 private static final int CMD_GET_ALL_CELL_INFO = 60;
294 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
295 private static final int CMD_GET_CELL_LOCATION = 62;
296 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700297 private static final int CMD_MODEM_REBOOT = 64;
298 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700299 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
300 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800301 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
302 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700303 private static final int CMD_GET_MODEM_STATUS = 70;
304 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700305 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
306 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700307 private static final int CMD_ERASE_MODEM_CONFIG = 74;
308 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800309 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
310 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
311 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
312 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800313 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
314 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800315 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800316 private static final int CMD_GET_CALL_FORWARDING = 83;
317 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
318 private static final int CMD_SET_CALL_FORWARDING = 85;
319 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
320 private static final int CMD_GET_CALL_WAITING = 87;
321 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
322 private static final int CMD_SET_CALL_WAITING = 89;
323 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700324 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
325 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
326 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
327 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700328 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
329 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800330 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
331 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800332 private static final int CMD_SET_DATA_THROTTLING = 99;
333 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800334 private static final int CMD_SET_SIM_POWER = 101;
335 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800336 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
337 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
338 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
339 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800340 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
341 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000342 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800343 private static final int CMD_GET_SLICING_CONFIG = 110;
344 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800345 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700346 private static final int CMD_ENABLE_VONR = 113;
347 private static final int EVENT_ENABLE_VONR_DONE = 114;
348 private static final int CMD_IS_VONR_ENABLED = 115;
349 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800351 // Parameters of select command.
352 private static final int SELECT_COMMAND = 0xA4;
353 private static final int SELECT_P1 = 0x04;
354 private static final int SELECT_P2 = 0;
355 private static final int SELECT_P3 = 0x10;
356
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357 /** The singleton instance. */
358 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800359 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
Wink Saville3ab207e2014-11-20 13:07:20 -0800361 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800362 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800363 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700364 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800365 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700366 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800367 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800368 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800369 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700370 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800371 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
Peter Wangdafb9ac2020-01-15 14:13:38 -0800373 /** User Activity */
374 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800375 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
376
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700377 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
378
Derek Tan97ebb422014-09-05 16:55:38 -0700379 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
380 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800381 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800382 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700383
Michelecea4cf22018-12-21 15:00:11 -0800384 // String to store multi SIM allowed
385 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
386
Derek Tan740e1672017-06-27 14:56:27 -0700387 // The AID of ISD-R.
388 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
389
yinxub1bed742017-04-17 11:45:04 -0700390 private NetworkScanRequestTracker mNetworkScanRequestTracker;
391
David Kelly5e06a7f2018-03-12 14:10:59 +0000392 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
393 private static final int MANUFACTURER_CODE_LENGTH = 8;
394
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800395 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800396 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800397
Derek Tan89e89d42014-07-08 17:00:10 -0700398 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700399 * Experiment flag to enable erase modem config on reset network, default value is false
400 */
401 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
402 "reset_network_erase_modem_config_enabled";
403
Rambo Wang0f050d82021-02-12 11:43:36 -0800404 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
405
Naina Nallurid63128d2019-09-17 14:10:30 -0700406 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700407 * A request object to use for transmitting data to an ICC.
408 */
409 private static final class IccAPDUArgument {
410 public int channel, cla, command, p1, p2, p3;
411 public String data;
412
413 public IccAPDUArgument(int channel, int cla, int command,
414 int p1, int p2, int p3, String data) {
415 this.channel = channel;
416 this.cla = cla;
417 this.command = command;
418 this.p1 = p1;
419 this.p2 = p2;
420 this.p3 = p3;
421 this.data = data;
422 }
423 }
424
425 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700426 * A request object to use for transmitting data to an ICC.
427 */
428 private static final class ManualNetworkSelectionArgument {
429 public OperatorInfo operatorInfo;
430 public boolean persistSelection;
431
432 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
433 this.operatorInfo = operatorInfo;
434 this.persistSelection = persistSelection;
435 }
436 }
437
438 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
440 * request after sending. The main thread will notify the request when it is complete.
441 */
442 private static final class MainThreadRequest {
443 /** The argument to use for the request */
444 public Object argument;
445 /** The result of the request that is run on the main thread */
446 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800447 // The subscriber id that this request applies to. Defaults to
448 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
449 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450
Nathan Harold92bed182018-10-12 18:16:49 -0700451 // In cases where subId is unavailable, the caller needs to specify the phone.
452 public Phone phone;
453
vagdeviaf9a5b92018-08-15 16:01:53 -0700454 public WorkSource workSource;
455
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 public MainThreadRequest(Object argument) {
457 this.argument = argument;
458 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800459
Nathan Harold92bed182018-10-12 18:16:49 -0700460 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
461 this.argument = argument;
462 if (phone != null) {
463 this.phone = phone;
464 }
465 this.workSource = workSource;
466 }
467
vagdeviaf9a5b92018-08-15 16:01:53 -0700468 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800469 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800470 if (subId != null) {
471 this.subId = subId;
472 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700473 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800474 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 }
476
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800477 private static final class IncomingThirdPartyCallArgs {
478 public final ComponentName component;
479 public final String callId;
480 public final String callerDisplayName;
481
482 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
483 String callerDisplayName) {
484 this.component = component;
485 this.callId = callId;
486 this.callerDisplayName = callerDisplayName;
487 }
488 }
489
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490 /**
491 * A handler that processes messages on the main thread in the phone process. Since many
492 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
493 * inbound binder threads to the main thread in the phone process. The Binder thread
494 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
495 * on, which will be notified when the operation completes and will contain the result of the
496 * request.
497 *
498 * <p>If a MainThreadRequest object is provided in the msg.obj field,
499 * note that request.result must be set to something non-null for the calling thread to
500 * unblock.
501 */
502 private final class MainThreadHandler extends Handler {
503 @Override
504 public void handleMessage(Message msg) {
505 MainThreadRequest request;
506 Message onCompleted;
507 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800508 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800510 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511
512 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700513 case CMD_HANDLE_USSD_REQUEST: {
514 request = (MainThreadRequest) msg.obj;
515 final Phone phone = getPhoneFromRequest(request);
516 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
517 String ussdRequest = ussdObject.first;
518 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700519
Pengquan Menga1bb6272018-09-06 09:59:22 -0700520 if (!isUssdApiAllowed(request.subId)) {
521 // Carrier does not support use of this API, return failure.
522 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
523 UssdResponse response = new UssdResponse(ussdRequest, null);
524 Bundle returnData = new Bundle();
525 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
526 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700527
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 request.result = true;
529 notifyRequester(request);
530 return;
531 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700532
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 try {
534 request.result = phone != null
535 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
536 } catch (CallStateException cse) {
537 request.result = false;
538 }
539 // Wake up the requesting thread
540 notifyRequester(request);
541 break;
pkanwar32d516d2016-10-14 19:37:38 -0700542 }
543
Yorke Lee716f67e2015-06-17 15:39:16 -0700544 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700546 final Phone phone = getPhoneFromRequest(request);
547 request.result = phone != null ?
548 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
549 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700554
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800558 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700559 if (uiccCard == null) {
560 loge("iccTransmitApduLogicalChannel: No UICC");
561 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700562 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
565 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 iccArgument.channel, iccArgument.cla, iccArgument.command,
568 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 break;
572
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 ar = (AsyncResult) msg.obj;
575 request = (MainThreadRequest) ar.userObj;
576 if (ar.exception == null && ar.result != null) {
577 request.result = ar.result;
578 } else {
579 request.result = new IccIoResult(0x6F, 0, (byte[])null);
580 if (ar.result == null) {
581 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800582 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800584 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 } else {
586 loge("iccTransmitApduLogicalChannel: Unknown exception");
587 }
588 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 break;
591
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
593 request = (MainThreadRequest) msg.obj;
594 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800595 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 if (uiccCard == null) {
597 loge("iccTransmitApduBasicChannel: No UICC");
598 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 } else {
601 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
602 request);
603 uiccCard.iccTransmitApduBasicChannel(
604 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
605 iccArgument.p3, iccArgument.data, onCompleted);
606 }
607 break;
608
609 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
610 ar = (AsyncResult) msg.obj;
611 request = (MainThreadRequest) ar.userObj;
612 if (ar.exception == null && ar.result != null) {
613 request.result = ar.result;
614 } else {
615 request.result = new IccIoResult(0x6F, 0, (byte[])null);
616 if (ar.result == null) {
617 loge("iccTransmitApduBasicChannel: Empty response");
618 } else if (ar.exception instanceof CommandException) {
619 loge("iccTransmitApduBasicChannel: CommandException: " +
620 ar.exception);
621 } else {
622 loge("iccTransmitApduBasicChannel: Unknown exception");
623 }
624 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700625 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 break;
627
628 case CMD_EXCHANGE_SIM_IO:
629 request = (MainThreadRequest) msg.obj;
630 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800631 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 if (uiccCard == null) {
633 loge("iccExchangeSimIO: No UICC");
634 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700636 } else {
637 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
638 request);
639 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
640 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
641 iccArgument.data, onCompleted);
642 }
643 break;
644
645 case EVENT_EXCHANGE_SIM_IO_DONE:
646 ar = (AsyncResult) msg.obj;
647 request = (MainThreadRequest) ar.userObj;
648 if (ar.exception == null && ar.result != null) {
649 request.result = ar.result;
650 } else {
651 request.result = new IccIoResult(0x6f, 0, (byte[])null);
652 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700653 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 break;
655
Derek Tan4d5e5c12014-02-04 11:54:58 -0800656 case CMD_SEND_ENVELOPE:
657 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800658 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 if (uiccCard == null) {
660 loge("sendEnvelopeWithStatus: No UICC");
661 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700662 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700663 } else {
664 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
665 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
666 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800667 break;
668
669 case EVENT_SEND_ENVELOPE_DONE:
670 ar = (AsyncResult) msg.obj;
671 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700672 if (ar.exception == null && ar.result != null) {
673 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800674 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700675 request.result = new IccIoResult(0x6F, 0, (byte[])null);
676 if (ar.result == null) {
677 loge("sendEnvelopeWithStatus: Empty response");
678 } else if (ar.exception instanceof CommandException) {
679 loge("sendEnvelopeWithStatus: CommandException: " +
680 ar.exception);
681 } else {
682 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
683 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800684 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800686 break;
687
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 case CMD_OPEN_CHANNEL:
689 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800690 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800691 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 if (uiccCard == null) {
693 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800694 request.result = new IccOpenLogicalChannelResponse(-1,
695 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 } else {
698 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800699 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
700 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700701 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 break;
703
704 case EVENT_OPEN_CHANNEL_DONE:
705 ar = (AsyncResult) msg.obj;
706 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 int[] result = (int[]) ar.result;
710 int channelId = result[0];
711 byte[] selectResponse = null;
712 if (result.length > 1) {
713 selectResponse = new byte[result.length - 1];
714 for (int i = 1; i < result.length; ++i) {
715 selectResponse[i - 1] = (byte) result[i];
716 }
717 }
718 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700719 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 if (ar.result == null) {
722 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700723 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700724 if (ar.exception != null) {
725 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
726 }
727
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700728 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700729 if (ar.exception instanceof CommandException) {
730 CommandException.Error error =
731 ((CommandException) (ar.exception)).getCommandError();
732 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700733 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700734 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700735 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700736 }
737 }
738 openChannelResp = new IccOpenLogicalChannelResponse(
739 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700741 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 break;
744
745 case CMD_CLOSE_CHANNEL:
746 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800747 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700748 if (uiccCard == null) {
749 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900750 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700751 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700752 } else {
753 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
754 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
755 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 break;
757
758 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800759 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
760 break;
761
762 case CMD_NV_READ_ITEM:
763 request = (MainThreadRequest) msg.obj;
764 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800765 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
766 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800767 break;
768
769 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 ar = (AsyncResult) msg.obj;
771 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800772 if (ar.exception == null && ar.result != null) {
773 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700774 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800775 request.result = "";
776 if (ar.result == null) {
777 loge("nvReadItem: Empty response");
778 } else if (ar.exception instanceof CommandException) {
779 loge("nvReadItem: CommandException: " +
780 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800782 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700783 }
784 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700785 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700786 break;
787
Jake Hambye994d462014-02-03 13:10:13 -0800788 case CMD_NV_WRITE_ITEM:
789 request = (MainThreadRequest) msg.obj;
790 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
791 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800792 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700793 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800794 break;
795
796 case EVENT_NV_WRITE_ITEM_DONE:
797 handleNullReturnEvent(msg, "nvWriteItem");
798 break;
799
800 case CMD_NV_WRITE_CDMA_PRL:
801 request = (MainThreadRequest) msg.obj;
802 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800803 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800804 break;
805
806 case EVENT_NV_WRITE_CDMA_PRL_DONE:
807 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
808 break;
809
chen xu6dac5ab2018-10-26 17:39:23 -0700810 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800811 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700812 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800813 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800814 break;
815
chen xu6dac5ab2018-10-26 17:39:23 -0700816 case EVENT_RESET_MODEM_CONFIG_DONE:
817 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800818 break;
819
Sooraj Sasindran37444802020-08-11 10:40:43 -0700820 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
821 request = (MainThreadRequest) msg.obj;
822 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
823 request);
824 Phone phone = getPhoneFromRequest(request);
825 if (phone != null) {
826 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
827 } else {
828 loge("isNRDualConnectivityEnabled: No phone object");
829 request.result = false;
830 notifyRequester(request);
831 }
832 break;
833 }
834
835 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
836 ar = (AsyncResult) msg.obj;
837 request = (MainThreadRequest) ar.userObj;
838 if (ar.exception == null && ar.result != null) {
839 request.result = ar.result;
840 } else {
841 // request.result must be set to something non-null
842 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700843 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700844 request.result = ar.result;
845 } else {
846 request.result = false;
847 }
848 if (ar.result == null) {
849 loge("isNRDualConnectivityEnabled: Empty response");
850 } else if (ar.exception instanceof CommandException) {
851 loge("isNRDualConnectivityEnabled: CommandException: "
852 + ar.exception);
853 } else {
854 loge("isNRDualConnectivityEnabled: Unknown exception");
855 }
856 }
857 notifyRequester(request);
858 break;
859
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700860 case CMD_IS_VONR_ENABLED: {
861 request = (MainThreadRequest) msg.obj;
862 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
863 request);
864 Phone phone = getPhoneFromRequest(request);
865 if (phone != null) {
866 phone.isVoNrEnabled(onCompleted, request.workSource);
867 } else {
868 loge("isVoNrEnabled: No phone object");
869 request.result = false;
870 notifyRequester(request);
871 }
872 break;
873 }
874
875 case EVENT_IS_VONR_ENABLED_DONE:
876 ar = (AsyncResult) msg.obj;
877 request = (MainThreadRequest) ar.userObj;
878 if (ar.exception == null && ar.result != null) {
879 request.result = ar.result;
880 } else {
881 // request.result must be set to something non-null
882 // for the calling thread to unblock
883 if (ar.result != null) {
884 request.result = ar.result;
885 } else {
886 request.result = false;
887 }
888 if (ar.result == null) {
889 loge("isVoNrEnabled: Empty response");
890 } else if (ar.exception instanceof CommandException) {
891 loge("isVoNrEnabled: CommandException: "
892 + ar.exception);
893 } else {
894 loge("isVoNrEnabled: Unknown exception");
895 }
896 }
897 notifyRequester(request);
898 break;
899
Sooraj Sasindran37444802020-08-11 10:40:43 -0700900 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
901 request = (MainThreadRequest) msg.obj;
902 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
903 Phone phone = getPhoneFromRequest(request);
904 if (phone != null) {
905 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
906 request.workSource);
907 } else {
908 loge("enableNrDualConnectivity: No phone object");
909 request.result =
910 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
911 notifyRequester(request);
912 }
913 break;
914 }
915
916 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 if (ar.exception == null) {
920 request.result =
921 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
922 } else {
923 request.result =
924 TelephonyManager
925 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
926 if (ar.exception instanceof CommandException) {
927 CommandException.Error error =
928 ((CommandException) (ar.exception)).getCommandError();
929 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
930 request.result =
931 TelephonyManager
932 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000933 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
934 request.result =
935 TelephonyManager
936 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700937 }
938 loge("enableNrDualConnectivity" + ": CommandException: "
939 + ar.exception);
940 } else {
941 loge("enableNrDualConnectivity" + ": Unknown exception");
942 }
943 }
944 notifyRequester(request);
945 break;
946 }
947
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700948 case CMD_ENABLE_VONR: {
949 request = (MainThreadRequest) msg.obj;
950 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
951 Phone phone = getPhoneFromRequest(request);
952 if (phone != null) {
953 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
954 request.workSource);
955 } else {
956 loge("setVoNrEnabled: No phone object");
957 request.result =
958 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
959 notifyRequester(request);
960 }
961 break;
962 }
963
964 case EVENT_ENABLE_VONR_DONE: {
965 ar = (AsyncResult) msg.obj;
966 request = (MainThreadRequest) ar.userObj;
967 if (ar.exception == null) {
968 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
969 } else {
970 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
971 if (ar.exception instanceof CommandException) {
972 CommandException.Error error =
973 ((CommandException) (ar.exception)).getCommandError();
974 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
975 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
976 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
977 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
978 } else {
979 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
980 }
981 loge("setVoNrEnabled" + ": CommandException: "
982 + ar.exception);
983 } else {
984 loge("setVoNrEnabled" + ": Unknown exception");
985 }
986 }
987 notifyRequester(request);
988 break;
989 }
990
SongFerngWang3ef3e072020-12-21 16:41:52 +0800991 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800992 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800993 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
994 request);
995 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800996 break;
997
SongFerngWang3ef3e072020-12-21 16:41:52 +0800998 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 if (ar.exception == null && ar.result != null) {
1002 request.result = ar.result; // Integer
1003 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301004 // request.result must be set to something non-null
1005 // for the calling thread to unblock
1006 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001007 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001008 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001009 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001010 loge("getAllowedNetworkTypesBitmask: CommandException: "
1011 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001012 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001013 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001014 }
1015 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001016 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001017 break;
1018
SongFerngWang3ef3e072020-12-21 16:41:52 +08001019 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001020 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001021 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1022 request);
1023 Pair<Integer, Long> reasonWithNetworkTypes =
1024 (Pair<Integer, Long>) request.argument;
1025 getPhoneFromRequest(request).setAllowedNetworkTypes(
1026 reasonWithNetworkTypes.first,
1027 reasonWithNetworkTypes.second,
1028 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001029 break;
1030
SongFerngWang3ef3e072020-12-21 16:41:52 +08001031 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1032 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001033 break;
1034
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001035 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1036 request = (MainThreadRequest)msg.obj;
1037 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001038 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001039 break;
1040
1041 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1042 ar = (AsyncResult)msg.obj;
1043 request = (MainThreadRequest)ar.userObj;
1044 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001045 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001046 break;
1047
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001048 case CMD_SET_VOICEMAIL_NUMBER:
1049 request = (MainThreadRequest) msg.obj;
1050 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1051 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001052 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1053 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001054 break;
1055
1056 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1057 handleNullReturnEvent(msg, "setVoicemailNumber");
1058 break;
1059
Stuart Scott54788802015-03-30 13:18:01 -07001060 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1061 request = (MainThreadRequest) msg.obj;
1062 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1063 request);
1064 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1065 break;
1066
1067 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1068 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1069 break;
1070
Shishir Agrawal302c8692015-06-19 13:49:39 -07001071 case CMD_PERFORM_NETWORK_SCAN:
1072 request = (MainThreadRequest) msg.obj;
1073 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1074 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1075 break;
1076
Hall Liu27d24262020-09-18 19:04:59 -07001077 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001078 request = (MainThreadRequest) msg.obj;
1079 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001080 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1081 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1082 request.argument;
1083 int callForwardingReason = args.first;
1084 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001085 break;
Hall Liu27d24262020-09-18 19:04:59 -07001086 }
1087 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001088 ar = (AsyncResult) msg.obj;
1089 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001090 TelephonyManager.CallForwardingInfoCallback callback =
1091 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1092 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001093 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001094 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001095 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1096 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1097 // Service Class is a bit mask per 3gpp 27.007. Search for
1098 // any service for voice call.
1099 if ((callForwardInfo.serviceClass
1100 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001101 callForwardingInfo = new CallForwardingInfo(true,
1102 callForwardInfo.reason,
1103 callForwardInfo.number,
1104 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001105 break;
1106 }
1107 }
1108 // Didn't find a call forward info for voice call.
1109 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001110 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1111 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001112 }
Hall Liu27d24262020-09-18 19:04:59 -07001113 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001114 } else {
1115 if (ar.result == null) {
1116 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1117 }
1118 if (ar.exception != null) {
1119 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1120 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001121 int errorCode = TelephonyManager
1122 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001123 if (ar.exception instanceof CommandException) {
1124 CommandException.Error error =
1125 ((CommandException) (ar.exception)).getCommandError();
1126 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001127 errorCode = TelephonyManager
1128 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001129 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001130 errorCode = TelephonyManager
1131 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001132 }
1133 }
Hall Liu27d24262020-09-18 19:04:59 -07001134 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001135 }
Shuo Qian4a594052020-01-23 11:59:30 -08001136 break;
Hall Liu27d24262020-09-18 19:04:59 -07001137 }
Shuo Qian4a594052020-01-23 11:59:30 -08001138
Hall Liu27d24262020-09-18 19:04:59 -07001139 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001140 request = (MainThreadRequest) msg.obj;
1141 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001142 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001143 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001144 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1145 request.argument).first;
1146 request.phone.setCallForwardingOption(
1147 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001148 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001149 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001150 callForwardingInfoToSet.getReason(),
1151 callForwardingInfoToSet.getNumber(),
1152 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1153 break;
Hall Liu27d24262020-09-18 19:04:59 -07001154 }
Shuo Qian4a594052020-01-23 11:59:30 -08001155
Hall Liu27d24262020-09-18 19:04:59 -07001156 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001157 ar = (AsyncResult) msg.obj;
1158 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001159 Consumer<Integer> callback =
1160 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1161 request.argument).second;
1162 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001163 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001164 int errorCode = TelephonyManager.CallForwardingInfoCallback
1165 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001166 if (ar.exception instanceof CommandException) {
1167 CommandException.Error error =
1168 ((CommandException) (ar.exception)).getCommandError();
1169 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001170 errorCode = TelephonyManager.CallForwardingInfoCallback
1171 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001172 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001173 errorCode = TelephonyManager.CallForwardingInfoCallback
1174 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001175 }
1176 }
1177 callback.accept(errorCode);
1178 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001179 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001180 }
Shuo Qian4a594052020-01-23 11:59:30 -08001181 break;
Hall Liu27d24262020-09-18 19:04:59 -07001182 }
Shuo Qian4a594052020-01-23 11:59:30 -08001183
Hall Liu27d24262020-09-18 19:04:59 -07001184 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001185 request = (MainThreadRequest) msg.obj;
1186 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1187 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1188 break;
Hall Liu27d24262020-09-18 19:04:59 -07001189 }
Shuo Qian4a594052020-01-23 11:59:30 -08001190
Hall Liu27d24262020-09-18 19:04:59 -07001191 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001192 ar = (AsyncResult) msg.obj;
1193 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001194 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001195 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1196 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001197 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001198 // Service Class is a bit mask per 3gpp 27.007.
1199 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001200 if (callForwardResults.length > 1
1201 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001202 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001203 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001204 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1205 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001206 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001207 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001208 }
1209 } else {
1210 if (ar.result == null) {
1211 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1212 }
1213 if (ar.exception != null) {
1214 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1215 }
1216 if (ar.exception instanceof CommandException) {
1217 CommandException.Error error =
1218 ((CommandException) (ar.exception)).getCommandError();
1219 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1220 callForwardingStatus =
1221 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1222 }
1223 }
1224 }
Hall Liu27d24262020-09-18 19:04:59 -07001225 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001226 break;
Hall Liu27d24262020-09-18 19:04:59 -07001227 }
Shuo Qian4a594052020-01-23 11:59:30 -08001228
Hall Liu27d24262020-09-18 19:04:59 -07001229 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001230 request = (MainThreadRequest) msg.obj;
1231 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001232 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1233 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001234 break;
Hall Liu27d24262020-09-18 19:04:59 -07001235 }
Shuo Qian4a594052020-01-23 11:59:30 -08001236
Hall Liu27d24262020-09-18 19:04:59 -07001237 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001238 ar = (AsyncResult) msg.obj;
1239 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001240 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1241 Consumer<Integer> callback =
1242 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1243 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001244 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001245 if (ar.exception instanceof CommandException) {
1246 CommandException.Error error =
1247 ((CommandException) (ar.exception)).getCommandError();
1248 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1249 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1250 } else {
1251 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1252 }
1253 } else {
1254 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1255 }
1256 } else {
1257 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1258 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001259 }
Shuo Qian4a594052020-01-23 11:59:30 -08001260 break;
Hall Liu27d24262020-09-18 19:04:59 -07001261 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001262 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1263 ar = (AsyncResult) msg.obj;
1264 request = (MainThreadRequest) ar.userObj;
1265 CellNetworkScanResult cellScanResult;
1266 if (ar.exception == null && ar.result != null) {
1267 cellScanResult = new CellNetworkScanResult(
1268 CellNetworkScanResult.STATUS_SUCCESS,
1269 (List<OperatorInfo>) ar.result);
1270 } else {
1271 if (ar.result == null) {
1272 loge("getCellNetworkScanResults: Empty response");
1273 }
1274 if (ar.exception != null) {
1275 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1276 }
1277 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1278 if (ar.exception instanceof CommandException) {
1279 CommandException.Error error =
1280 ((CommandException) (ar.exception)).getCommandError();
1281 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1282 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1283 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1284 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1285 }
1286 }
1287 cellScanResult = new CellNetworkScanResult(errorCode, null);
1288 }
1289 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001290 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001291 break;
1292
1293 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1294 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001295 ManualNetworkSelectionArgument selArg =
1296 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001297 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1298 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001299 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1300 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001301 break;
1302
1303 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001304 ar = (AsyncResult) msg.obj;
1305 request = (MainThreadRequest) ar.userObj;
1306 if (ar.exception == null) {
1307 request.result = true;
1308 } else {
1309 request.result = false;
1310 loge("setNetworkSelectionModeManual " + ar.exception);
1311 }
1312 notifyRequester(request);
1313 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001314 break;
1315
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001316 case CMD_GET_MODEM_ACTIVITY_INFO:
1317 request = (MainThreadRequest) msg.obj;
1318 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001319 if (defaultPhone != null) {
1320 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001321 } else {
1322 ResultReceiver result = (ResultReceiver) request.argument;
1323 Bundle bundle = new Bundle();
1324 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001325 new ModemActivityInfo(0, 0, 0,
1326 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001327 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001328 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001329 break;
1330
Hall Liud0f208c2020-10-14 16:54:44 -07001331 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001332 ar = (AsyncResult) msg.obj;
1333 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001334 ResultReceiver result = (ResultReceiver) request.argument;
1335
Hall Liud0f208c2020-10-14 16:54:44 -07001336 ModemActivityInfo ret = null;
1337 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001338 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001339 // Update the last modem activity info and the result of the request.
1340 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1341 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001342 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001343 int[] txTimeMs = info.getTransmitTimeMillis();
1344 int[] lastModemTxTimeMs = mLastModemActivityInfo
1345 .getTransmitTimeMillis();
1346 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1347 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1348 }
Hall Liu49656c02020-10-09 19:00:11 -07001349 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001350 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1351 + mLastModemActivityInfo.getSleepTimeMillis());
1352 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1353 + mLastModemActivityInfo.getIdleTimeMillis());
1354 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1355 mLastModemActivityInfo.setReceiveTimeMillis(
1356 info.getReceiveTimeMillis()
1357 + mLastModemActivityInfo.getReceiveTimeMillis());
1358 }
Hall Liu49656c02020-10-09 19:00:11 -07001359 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001360 mLastModemActivityInfo.getSleepTimeMillis(),
1361 mLastModemActivityInfo.getIdleTimeMillis(),
1362 mLastModemActivityInfo.getTransmitTimeMillis(),
1363 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001364 } else {
1365 if (ar.result == null) {
1366 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001367 error = TelephonyManager.ModemActivityInfoException
1368 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001369 } else if (ar.exception instanceof CommandException) {
1370 loge("queryModemActivityInfo: CommandException: " +
1371 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001372 error = TelephonyManager.ModemActivityInfoException
1373 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001374 } else {
1375 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001376 error = TelephonyManager.ModemActivityInfoException
1377 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001378 }
1379 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001380 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001381 if (ret != null) {
1382 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1383 } else {
1384 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1385 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001386 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001387 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001388 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001389 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001390
Meng Wang1a7c35a2016-05-05 20:56:15 -07001391 case CMD_SET_ALLOWED_CARRIERS:
1392 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001393 CarrierRestrictionRules argument =
1394 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001395 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001396 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001397 break;
1398
1399 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 if (ar.exception == null && ar.result != null) {
1403 request.result = ar.result;
1404 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001405 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1406 if (ar.exception instanceof CommandException) {
1407 loge("setAllowedCarriers: CommandException: " + ar.exception);
1408 CommandException.Error error =
1409 ((CommandException) (ar.exception)).getCommandError();
1410 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1411 request.result =
1412 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1413 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001414 } else {
1415 loge("setAllowedCarriers: Unknown exception");
1416 }
1417 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001418 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001419 break;
1420
1421 case CMD_GET_ALLOWED_CARRIERS:
1422 request = (MainThreadRequest) msg.obj;
1423 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001424 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001425 break;
1426
1427 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1428 ar = (AsyncResult) msg.obj;
1429 request = (MainThreadRequest) ar.userObj;
1430 if (ar.exception == null && ar.result != null) {
1431 request.result = ar.result;
1432 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001433 request.result = new IllegalStateException(
1434 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001435 if (ar.result == null) {
1436 loge("getAllowedCarriers: Empty response");
1437 } else if (ar.exception instanceof CommandException) {
1438 loge("getAllowedCarriers: CommandException: " +
1439 ar.exception);
1440 } else {
1441 loge("getAllowedCarriers: Unknown exception");
1442 }
1443 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001444 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001445 break;
1446
Nathan Haroldb3014052017-01-25 15:57:32 -08001447 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 if (ar.exception == null && ar.result != null) {
1451 request.result = ar.result;
1452 } else {
1453 request.result = new IllegalArgumentException(
1454 "Failed to retrieve Forbidden Plmns");
1455 if (ar.result == null) {
1456 loge("getForbiddenPlmns: Empty response");
1457 } else {
1458 loge("getForbiddenPlmns: Unknown exception");
1459 }
1460 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001461 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001462 break;
1463
1464 case CMD_GET_FORBIDDEN_PLMNS:
1465 request = (MainThreadRequest) msg.obj;
1466 uiccCard = getUiccCardFromRequest(request);
1467 if (uiccCard == null) {
1468 loge("getForbiddenPlmns() UiccCard is null");
1469 request.result = new IllegalArgumentException(
1470 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001471 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001472 break;
1473 }
1474 Integer appType = (Integer) request.argument;
1475 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1476 if (uiccApp == null) {
1477 loge("getForbiddenPlmns() no app with specified type -- "
1478 + appType);
1479 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001480 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001481 break;
1482 } else {
1483 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1484 + " specified type -- " + appType);
1485 }
1486 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1487 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1488 onCompleted);
1489 break;
1490
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001491 case CMD_SWITCH_SLOTS:
1492 request = (MainThreadRequest) msg.obj;
1493 int[] physicalSlots = (int[]) request.argument;
1494 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1495 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1496 break;
1497
1498 case EVENT_SWITCH_SLOTS_DONE:
1499 ar = (AsyncResult) msg.obj;
1500 request = (MainThreadRequest) ar.userObj;
1501 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001502 notifyRequester(request);
1503 break;
1504 case CMD_GET_NETWORK_SELECTION_MODE:
1505 request = (MainThreadRequest) msg.obj;
1506 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1507 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1508 break;
1509
1510 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1511 ar = (AsyncResult) msg.obj;
1512 request = (MainThreadRequest) ar.userObj;
1513 if (ar.exception != null) {
1514 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1515 } else {
1516 int mode = ((int[]) ar.result)[0];
1517 if (mode == 0) {
1518 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1519 } else {
1520 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1521 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001523 notifyRequester(request);
1524 break;
1525 case CMD_GET_CDMA_ROAMING_MODE:
1526 request = (MainThreadRequest) msg.obj;
1527 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1528 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1529 break;
1530 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1531 ar = (AsyncResult) msg.obj;
1532 request = (MainThreadRequest) ar.userObj;
1533 if (ar.exception != null) {
1534 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1535 } else {
1536 request.result = ((int[]) ar.result)[0];
1537 }
1538 notifyRequester(request);
1539 break;
1540 case CMD_SET_CDMA_ROAMING_MODE:
1541 request = (MainThreadRequest) msg.obj;
1542 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1543 int mode = (int) request.argument;
1544 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1545 break;
1546 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1547 ar = (AsyncResult) msg.obj;
1548 request = (MainThreadRequest) ar.userObj;
1549 request.result = ar.exception == null;
1550 notifyRequester(request);
1551 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001552 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1553 request = (MainThreadRequest) msg.obj;
1554 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1555 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1556 break;
1557 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1558 ar = (AsyncResult) msg.obj;
1559 request = (MainThreadRequest) ar.userObj;
1560 if (ar.exception != null) {
1561 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1562 } else {
1563 request.result = ((int[]) ar.result)[0];
1564 }
1565 notifyRequester(request);
1566 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001567 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1568 request = (MainThreadRequest) msg.obj;
1569 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1570 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001571 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1572 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001573 break;
1574 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1575 ar = (AsyncResult) msg.obj;
1576 request = (MainThreadRequest) ar.userObj;
1577 request.result = ar.exception == null;
1578 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001579 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001580 case CMD_GET_ALL_CELL_INFO:
1581 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001582 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001583 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001584 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001585 case EVENT_GET_ALL_CELL_INFO_DONE:
1586 ar = (AsyncResult) msg.obj;
1587 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001588 // If a timeout occurs, the response will be null
1589 request.result = (ar.exception == null && ar.result != null)
1590 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001591 synchronized (request) {
1592 request.notifyAll();
1593 }
1594 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001595 case CMD_REQUEST_CELL_INFO_UPDATE:
1596 request = (MainThreadRequest) msg.obj;
1597 request.phone.requestCellInfoUpdate(request.workSource,
1598 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1599 break;
1600 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1601 ar = (AsyncResult) msg.obj;
1602 request = (MainThreadRequest) ar.userObj;
1603 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1604 try {
1605 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001606 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001607 cb.onError(
1608 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1609 ar.exception.getClass().getName(),
1610 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001611 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001612 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001613 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001614 } else {
1615 // use the result as returned
1616 cb.onCellInfo((List<CellInfo>) ar.result);
1617 }
1618 } catch (RemoteException re) {
1619 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1620 }
1621 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001622 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001623 request = (MainThreadRequest) msg.obj;
1624 WorkSource ws = (WorkSource) request.argument;
1625 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001626 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001627 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001628 }
1629 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001630 ar = (AsyncResult) msg.obj;
1631 request = (MainThreadRequest) ar.userObj;
1632 if (ar.exception == null) {
1633 request.result = ar.result;
1634 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001635 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001636 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001637 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001638 }
1639
1640 synchronized (request) {
1641 request.notifyAll();
1642 }
1643 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001644 }
chen xu6dac5ab2018-10-26 17:39:23 -07001645 case CMD_MODEM_REBOOT:
1646 request = (MainThreadRequest) msg.obj;
1647 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001648 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001649 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001650 case EVENT_CMD_MODEM_REBOOT_DONE:
1651 handleNullReturnEvent(msg, "rebootModem");
1652 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001653 case CMD_REQUEST_ENABLE_MODEM:
1654 request = (MainThreadRequest) msg.obj;
1655 boolean enable = (boolean) request.argument;
1656 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001657 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001658 PhoneConfigurationManager.getInstance()
1659 .enablePhone(request.phone, enable, onCompleted);
1660 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001661 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001662 ar = (AsyncResult) msg.obj;
1663 request = (MainThreadRequest) ar.userObj;
1664 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001665 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001666 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001667 if ((boolean) request.result) {
1668 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1669 updateModemStateMetrics();
1670 } else {
1671 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1672 + ar.exception);
1673 }
1674 notifyRequester(request);
1675 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001676 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001677 case CMD_GET_MODEM_STATUS:
1678 request = (MainThreadRequest) msg.obj;
1679 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1680 PhoneConfigurationManager.getInstance()
1681 .getPhoneStatusFromModem(request.phone, onCompleted);
1682 break;
1683 case EVENT_GET_MODEM_STATUS_DONE:
1684 ar = (AsyncResult) msg.obj;
1685 request = (MainThreadRequest) ar.userObj;
1686 int id = request.phone.getPhoneId();
1687 if (ar.exception == null && ar.result != null) {
1688 request.result = ar.result;
1689 //update the cache as modem status has changed
1690 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1691 (boolean) request.result);
1692 } else {
1693 // Return true if modem status cannot be retrieved. For most cases,
1694 // modem status is on. And for older version modems, GET_MODEM_STATUS
1695 // and disable modem are not supported. Modem is always on.
1696 // TODO: this should be fixed in R to support a third
1697 // status UNKNOWN b/131631629
1698 request.result = true;
1699 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1700 + ar.exception);
1701 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001702 notifyRequester(request);
1703 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001704 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1705 request = (MainThreadRequest) msg.obj;
1706 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1707 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1708 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1709 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1710 break;
1711 }
1712 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1716 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1717 args.second.accept(ar.exception == null);
1718 notifyRequester(request);
1719 break;
1720 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001721 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1722 request = (MainThreadRequest) msg.obj;
1723 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1724 Phone phone = getPhoneFromRequest(request);
1725 if (phone != null) {
1726 phone.getSystemSelectionChannels(onCompleted);
1727 } else {
1728 loge("getSystemSelectionChannels: No phone object");
1729 request.result = new ArrayList<RadioAccessSpecifier>();
1730 notifyRequester(request);
1731 }
1732 break;
1733 }
1734 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1735 ar = (AsyncResult) msg.obj;
1736 request = (MainThreadRequest) ar.userObj;
1737 if (ar.exception == null && ar.result != null) {
1738 request.result = ar.result;
1739 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001740 request.result = new IllegalStateException(
1741 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001742 if (ar.result == null) {
1743 loge("getSystemSelectionChannels: Empty response");
1744 } else {
1745 loge("getSystemSelectionChannels: Unknown exception");
1746 }
1747 }
1748 notifyRequester(request);
1749 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001750 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1751 ar = (AsyncResult) msg.obj;
1752 request = (MainThreadRequest) ar.userObj;
1753 if (ar.exception == null && ar.result != null) {
1754 request.result = ar.result;
1755 } else {
1756 request.result = -1;
1757 loge("Failed to set Forbidden Plmns");
1758 if (ar.result == null) {
1759 loge("setForbidenPlmns: Empty response");
1760 } else if (ar.exception != null) {
1761 loge("setForbiddenPlmns: Exception: " + ar.exception);
1762 request.result = -1;
1763 } else {
1764 loge("setForbiddenPlmns: Unknown exception");
1765 }
1766 }
1767 notifyRequester(request);
1768 break;
1769 case CMD_SET_FORBIDDEN_PLMNS:
1770 request = (MainThreadRequest) msg.obj;
1771 uiccCard = getUiccCardFromRequest(request);
1772 if (uiccCard == null) {
1773 loge("setForbiddenPlmns: UiccCard is null");
1774 request.result = -1;
1775 notifyRequester(request);
1776 break;
1777 }
1778 Pair<Integer, List<String>> setFplmnsArgs =
1779 (Pair<Integer, List<String>>) request.argument;
1780 appType = setFplmnsArgs.first;
1781 List<String> fplmns = setFplmnsArgs.second;
1782 uiccApp = uiccCard.getApplicationByType(appType);
1783 if (uiccApp == null) {
1784 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1785 request.result = -1;
1786 loge("Failed to get UICC App");
1787 notifyRequester(request);
1788 } else {
1789 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1790 ((SIMRecords) uiccApp.getIccRecords())
1791 .setForbiddenPlmns(onCompleted, fplmns);
1792 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001793 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001794 case CMD_ERASE_MODEM_CONFIG:
1795 request = (MainThreadRequest) msg.obj;
1796 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1797 defaultPhone.eraseModemConfig(onCompleted);
1798 break;
1799 case EVENT_ERASE_MODEM_CONFIG_DONE:
1800 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001801 break;
zoey chene02881a2019-12-30 16:11:23 +08001802
Kai Shif70f46f2021-03-03 13:59:46 -08001803 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1804 request = (MainThreadRequest) msg.obj;
1805 request.result = defaultPhone.eraseDataInSharedPreferences();
1806 notifyRequester(request);
1807 break;
1808
zoey chene02881a2019-12-30 16:11:23 +08001809 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1810 request = (MainThreadRequest) msg.obj;
1811 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1812 Pair<String, String> changed = (Pair<String, String>) request.argument;
1813 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1814 changed.first, changed.second, onCompleted);
1815 break;
1816 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1817 ar = (AsyncResult) msg.obj;
1818 request = (MainThreadRequest) ar.userObj;
1819 if (ar.exception == null) {
1820 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001821 // If the operation is successful, update the PIN storage
1822 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1823 int phoneId = getPhoneFromRequest(request).getPhoneId();
1824 UiccController.getInstance().getPinStorage()
1825 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001826 } else {
1827 request.result = msg.arg1;
1828 }
1829 notifyRequester(request);
1830 break;
1831
Michele Berionne5e411512020-11-13 02:36:59 +00001832 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001833 request = (MainThreadRequest) msg.obj;
1834 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1835 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1836 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1837 enabled.first, enabled.second, onCompleted);
1838 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001839 }
zoey chene02881a2019-12-30 16:11:23 +08001840 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1841 ar = (AsyncResult) msg.obj;
1842 request = (MainThreadRequest) ar.userObj;
1843 if (ar.exception == null) {
1844 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001845 // If the operation is successful, update the PIN storage
1846 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1847 int phoneId = getPhoneFromRequest(request).getPhoneId();
1848 if (enabled.first) {
1849 UiccController.getInstance().getPinStorage()
1850 .storePin(enabled.second, phoneId);
1851 } else {
1852 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1853 }
zoey chene02881a2019-12-30 16:11:23 +08001854 } else {
1855 request.result = msg.arg1;
1856 }
Michele Berionne5e411512020-11-13 02:36:59 +00001857
1858
zoey chene02881a2019-12-30 16:11:23 +08001859 notifyRequester(request);
1860 break;
1861
Peter Wangdafb9ac2020-01-15 14:13:38 -08001862 case MSG_NOTIFY_USER_ACTIVITY:
1863 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001864 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001865 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1866 getDefaultPhone().getContext().sendBroadcastAsUser(
1867 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1868 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001869
1870 case CMD_SET_DATA_THROTTLING: {
1871 request = (MainThreadRequest) msg.obj;
1872 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1873 DataThrottlingRequest dataThrottlingRequest =
1874 (DataThrottlingRequest) request.argument;
1875 Phone phone = getPhoneFromRequest(request);
1876 if (phone != null) {
1877 phone.setDataThrottling(onCompleted,
1878 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1879 dataThrottlingRequest.getCompletionDurationMillis());
1880 } else {
1881 loge("setDataThrottling: No phone object");
1882 request.result =
1883 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1884 notifyRequester(request);
1885 }
1886
1887 break;
1888 }
1889 case EVENT_SET_DATA_THROTTLING_DONE:
1890 ar = (AsyncResult) msg.obj;
1891 request = (MainThreadRequest) ar.userObj;
1892
1893 if (ar.exception == null) {
1894 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1895 } else if (ar.exception instanceof CommandException) {
1896 loge("setDataThrottling: CommandException: " + ar.exception);
1897 CommandException.Error error =
1898 ((CommandException) (ar.exception)).getCommandError();
1899
1900 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1901 request.result = TelephonyManager
1902 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1903 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1904 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001905 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1906 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001907 } else {
1908 request.result =
1909 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1910 }
1911 } else {
1912 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1913 }
1914 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1915 notifyRequester(request);
1916 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001917
1918 case CMD_SET_SIM_POWER: {
1919 request = (MainThreadRequest) msg.obj;
1920 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1921 request = (MainThreadRequest) msg.obj;
1922 int stateToSet =
1923 ((Pair<Integer, IIntegerConsumer>)
1924 request.argument).first;
1925 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1926 break;
1927 }
1928 case EVENT_SET_SIM_POWER_DONE: {
1929 ar = (AsyncResult) msg.obj;
1930 request = (MainThreadRequest) ar.userObj;
1931 IIntegerConsumer callback =
1932 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1933 if (ar.exception != null) {
1934 loge("setSimPower exception: " + ar.exception);
1935 int errorCode = TelephonyManager.CallForwardingInfoCallback
1936 .RESULT_ERROR_UNKNOWN;
1937 if (ar.exception instanceof CommandException) {
1938 CommandException.Error error =
1939 ((CommandException) (ar.exception)).getCommandError();
1940 if (error == CommandException.Error.SIM_ERR) {
1941 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1942 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1943 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1944 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1945 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1946 } else {
1947 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1948 }
1949 }
1950 try {
1951 callback.accept(errorCode);
1952 } catch (RemoteException e) {
1953 // Ignore if the remote process is no longer available to call back.
1954 Log.w(LOG_TAG, "setSimPower: callback not available.");
1955 }
1956 } else {
1957 try {
1958 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1959 } catch (RemoteException e) {
1960 // Ignore if the remote process is no longer available to call back.
1961 Log.w(LOG_TAG, "setSimPower: callback not available.");
1962 }
1963 }
1964 break;
1965 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001966 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1967 request = (MainThreadRequest) msg.obj;
1968
1969 final Phone phone = getPhoneFromRequest(request);
1970 if (phone == null || phone.getServiceStateTracker() == null) {
1971 request.result = new IllegalStateException("Phone or SST is null");
1972 notifyRequester(request);
1973 break;
1974 }
1975
1976 Pair<Integer, SignalStrengthUpdateRequest> pair =
1977 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1978 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1979 request);
1980 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1981 request.subId, pair.first /*callingUid*/,
1982 pair.second /*request*/, onCompleted);
1983 break;
1984 }
1985 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1986 ar = (AsyncResult) msg.obj;
1987 request = (MainThreadRequest) ar.userObj;
1988 // request.result will be the exception of ar if present, true otherwise.
1989 // Be cautious not to leave result null which will wait() forever
1990 request.result = ar.exception != null ? ar.exception : true;
1991 notifyRequester(request);
1992 break;
1993 }
1994 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1995 request = (MainThreadRequest) msg.obj;
1996
1997 Phone phone = getPhoneFromRequest(request);
1998 if (phone == null || phone.getServiceStateTracker() == null) {
1999 request.result = new IllegalStateException("Phone or SST is null");
2000 notifyRequester(request);
2001 break;
2002 }
2003
2004 Pair<Integer, SignalStrengthUpdateRequest> pair =
2005 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2006 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2007 request);
2008 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
2009 request.subId, pair.first /*callingUid*/,
2010 pair.second /*request*/, onCompleted);
2011 break;
2012 }
2013 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2014 ar = (AsyncResult) msg.obj;
2015 request = (MainThreadRequest) ar.userObj;
2016 request.result = ar.exception != null ? ar.exception : true;
2017 notifyRequester(request);
2018 break;
2019 }
Jordan Liu109698e2020-11-24 14:50:34 -08002020
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002021 case CMD_GET_SLICING_CONFIG: {
2022 request = (MainThreadRequest) msg.obj;
2023 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2024 request.phone.getSlicingConfig(onCompleted);
2025 break;
2026 }
2027 case EVENT_GET_SLICING_CONFIG_DONE: {
2028 ar = (AsyncResult) msg.obj;
2029 request = (MainThreadRequest) ar.userObj;
2030 ResultReceiver result = (ResultReceiver) request.argument;
2031
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002032 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002033 Bundle bundle = new Bundle();
2034 int resultCode = 0;
2035 if (ar.exception != null) {
2036 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2037 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002038 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002039 } else if (ar.result == null) {
2040 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002041 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002042 } else {
2043 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002044 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2045 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002046 }
2047
2048 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002049 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002050 }
2051 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2052 result.send(resultCode, bundle);
2053 notifyRequester(request);
2054 break;
2055 }
2056
Michele Berionne5e411512020-11-13 02:36:59 +00002057 case CMD_PREPARE_UNATTENDED_REBOOT:
2058 request = (MainThreadRequest) msg.obj;
2059 request.result =
Rafael Higuera Silva7badcc42021-09-20 15:32:01 +00002060 UiccController.getInstance().getPinStorage()
2061 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002062 notifyRequester(request);
2063 break;
2064
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002065 default:
2066 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2067 break;
2068 }
2069 }
Jake Hambye994d462014-02-03 13:10:13 -08002070
Pengquan Menga1bb6272018-09-06 09:59:22 -07002071 private void notifyRequester(MainThreadRequest request) {
2072 synchronized (request) {
2073 request.notifyAll();
2074 }
2075 }
2076
Jake Hambye994d462014-02-03 13:10:13 -08002077 private void handleNullReturnEvent(Message msg, String command) {
2078 AsyncResult ar = (AsyncResult) msg.obj;
2079 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2080 if (ar.exception == null) {
2081 request.result = true;
2082 } else {
2083 request.result = false;
2084 if (ar.exception instanceof CommandException) {
2085 loge(command + ": CommandException: " + ar.exception);
2086 } else {
2087 loge(command + ": Unknown exception");
2088 }
2089 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002090 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002092 }
2093
2094 /**
2095 * Posts the specified command to be executed on the main thread,
2096 * waits for the request to complete, and returns the result.
2097 * @see #sendRequestAsync
2098 */
2099 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002100 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2101 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002102 }
2103
2104 /**
2105 * Posts the specified command to be executed on the main thread,
2106 * waits for the request to complete, and returns the result.
2107 * @see #sendRequestAsync
2108 */
2109 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2110 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002111 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002112 }
2113
2114 /**
2115 * Posts the specified command to be executed on the main thread,
2116 * waits for the request to complete, and returns the result.
2117 * @see #sendRequestAsync
2118 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002119 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002120 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2121 }
2122
2123 /**
2124 * Posts the specified command to be executed on the main thread,
2125 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2126 * if not timeout or null otherwise.
2127 * @see #sendRequestAsync
2128 */
2129 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2130 long timeoutInMs) {
2131 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002132 }
2133
2134 /**
2135 * Posts the specified command to be executed on the main thread,
2136 * waits for the request to complete, and returns the result.
2137 * @see #sendRequestAsync
2138 */
Nathan Harold92bed182018-10-12 18:16:49 -07002139 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002140 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002141 }
2142
2143 /**
2144 * Posts the specified command to be executed on the main thread,
2145 * waits for the request to complete, and returns the result.
2146 * @see #sendRequestAsync
2147 */
2148 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002149 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2150 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002151 }
2152
2153 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002154 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2155 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2156 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002157 * @see #sendRequestAsync
2158 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002159 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2160 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2162 throw new RuntimeException("This method will deadlock if called from the main thread.");
2163 }
2164
Nathan Harold92bed182018-10-12 18:16:49 -07002165 MainThreadRequest request = null;
2166 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2167 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2168 } else if (phone != null) {
2169 request = new MainThreadRequest(argument, phone, workSource);
2170 } else {
2171 request = new MainThreadRequest(argument, subId, workSource);
2172 }
2173
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174 Message msg = mMainThreadHandler.obtainMessage(command, request);
2175 msg.sendToTarget();
2176
Rambo Wang0f050d82021-02-12 11:43:36 -08002177
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002179 if (timeoutInMs >= 0) {
2180 // Wait for at least timeoutInMs before returning null request result
2181 long now = SystemClock.elapsedRealtime();
2182 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002183 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002184 try {
2185 request.wait(deadline - now);
2186 } catch (InterruptedException e) {
2187 // Do nothing, go back and check if request is completed or timeout
2188 } finally {
2189 now = SystemClock.elapsedRealtime();
2190 }
2191 }
2192 } else {
2193 // Wait for the request to complete
2194 while (request.result == null) {
2195 try {
2196 request.wait();
2197 } catch (InterruptedException e) {
2198 // Do nothing, go back and wait until the request is complete
2199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
2201 }
2202 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002203 if (request.result == null) {
2204 Log.wtf(LOG_TAG,
2205 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2206 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207 return request.result;
2208 }
2209
2210 /**
2211 * Asynchronous ("fire and forget") version of sendRequest():
2212 * Posts the specified command to be executed on the main thread, and
2213 * returns immediately.
2214 * @see #sendRequest
2215 */
2216 private void sendRequestAsync(int command) {
2217 mMainThreadHandler.sendEmptyMessage(command);
2218 }
2219
2220 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002221 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002222 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002223 */
2224 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002225 sendRequestAsync(command, argument, null, null);
2226 }
2227
2228 /**
2229 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2230 * @see {@link #sendRequest(int,Object)}
2231 */
2232 private void sendRequestAsync(
2233 int command, Object argument, Phone phone, WorkSource workSource) {
2234 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002235 Message msg = mMainThreadHandler.obtainMessage(command, request);
2236 msg.sendToTarget();
2237 }
2238
2239 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 * Initialize the singleton PhoneInterfaceManager instance.
2241 * This is only done once, at startup, from PhoneApp.onCreate().
2242 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002243 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 synchronized (PhoneInterfaceManager.class) {
2245 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002246 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 } else {
2248 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2249 }
2250 return sInstance;
2251 }
2252 }
2253
2254 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002255 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002258 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002259 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002261 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002263 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002264 mTelephonySharedPreferences =
2265 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002266 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002267 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002268 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002269 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002270
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 publish();
2272 }
2273
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002274 private Phone getDefaultPhone() {
2275 Phone thePhone = getPhone(getDefaultSubscription());
2276 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2277 }
2278
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 private void publish() {
2280 if (DBG) log("publish: " + this);
2281
Peter Wangc035ce42020-01-08 21:00:22 -08002282 TelephonyFrameworkInitializer
2283 .getTelephonyServiceManager()
2284 .getTelephonyServiceRegisterer()
2285 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 }
2287
Stuart Scott584921c2015-01-15 17:10:34 -08002288 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002289 if (request.phone != null) {
2290 return request.phone;
2291 } else {
2292 return getPhoneFromSubId(request.subId);
2293 }
2294 }
2295
2296 private Phone getPhoneFromSubId(int subId) {
2297 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2298 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002299 }
2300
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002301 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2302 Phone phone = getPhoneFromRequest(request);
2303 return phone == null ? null :
2304 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2305 }
2306
Wink Saville36469e72014-06-11 15:17:00 -07002307 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002308 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002309 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002310 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311
Kai Shif70f46f2021-03-03 13:59:46 -08002312 private void sendEraseModemConfig(@NonNull Phone phone) {
2313 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2314 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2315 }
2316
2317 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2318 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2319 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002320 }
2321
Peter Wang44b186e2020-01-13 23:33:09 -08002322 private boolean isImsAvailableOnDevice() {
2323 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2324 if (pm == null) {
2325 // For some reason package manger is not available.. This will fail internally anyway,
2326 // so do not throw error and allow.
2327 return true;
2328 }
2329 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2330 }
2331
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002333 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002334 }
2335
Wink Savilleb564aae2014-10-23 10:18:09 -07002336 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 if (DBG) log("dial: " + number);
2338 // No permission check needed here: This is just a wrapper around the
2339 // ACTION_DIAL intent, which is available to any app since it puts up
2340 // the UI before it does anything.
2341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002342 final long identity = Binder.clearCallingIdentity();
2343 try {
2344 String url = createTelUrl(number);
2345 if (url == null) {
2346 return;
2347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002349 // PENDING: should we just silently fail if phone is offhook or ringing?
2350 PhoneConstants.State state = mCM.getState(subId);
2351 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2352 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2353 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2354 mApp.startActivity(intent);
2355 }
2356 } finally {
2357 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 }
2359 }
2360
2361 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002362 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002363 }
2364
Wink Savilleb564aae2014-10-23 10:18:09 -07002365 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 if (DBG) log("call: " + number);
2367
2368 // This is just a wrapper around the ACTION_CALL intent, but we still
2369 // need to do a permission check since we're calling startActivity()
2370 // from the context of the phone app.
2371 enforceCallPermission();
2372
Jordan Liu1617b712019-07-10 15:06:26 -07002373 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 != AppOpsManager.MODE_ALLOWED) {
2375 return;
2376 }
2377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 String url = createTelUrl(number);
2381 if (url == null) {
2382 return;
2383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002385 boolean isValid = false;
2386 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2387 if (slist != null) {
2388 for (SubscriptionInfo subInfoRecord : slist) {
2389 if (subInfoRecord.getSubscriptionId() == subId) {
2390 isValid = true;
2391 break;
2392 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002393 }
Wink Saville08874612014-08-31 19:19:58 -07002394 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002395 if (!isValid) {
2396 return;
2397 }
Wink Saville08874612014-08-31 19:19:58 -07002398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002399 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2400 intent.putExtra(SUBSCRIPTION_KEY, subId);
2401 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2402 mApp.startActivity(intent);
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
2405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 }
2407
Wink Savilleb564aae2014-10-23 10:18:09 -07002408 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002409 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002410 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2411 }
2412
Wink Savilleb564aae2014-10-23 10:18:09 -07002413 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002414 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002415 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2416 }
2417
Wink Savilleb564aae2014-10-23 10:18:09 -07002418 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002420
2421 final long identity = Binder.clearCallingIdentity();
2422 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002423 Phone phone = getPhone(subId);
2424 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002425 checkSimPin.start();
2426 return checkSimPin.unlockSim(null, pin);
2427 } finally {
2428 Binder.restoreCallingIdentity(identity);
2429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 }
2431
Wink Savilleb564aae2014-10-23 10:18:09 -07002432 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434
2435 final long identity = Binder.clearCallingIdentity();
2436 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002437 Phone phone = getPhone(subId);
2438 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002439 checkSimPuk.start();
2440 return checkSimPuk.unlockSim(puk, pin);
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
2443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 }
2445
2446 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002447 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 * a synchronous one.
2449 */
2450 private static class UnlockSim extends Thread {
2451
2452 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002453 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454
2455 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002456 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2457 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458
2459 // For replies from SimCard interface
2460 private Handler mHandler;
2461
2462 // For async handler to identify request type
2463 private static final int SUPPLY_PIN_COMPLETE = 100;
2464
Michele Berionne5e411512020-11-13 02:36:59 +00002465 UnlockSim(int phoneId, IccCard simCard) {
2466 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 mSimCard = simCard;
2468 }
2469
2470 @Override
2471 public void run() {
2472 Looper.prepare();
2473 synchronized (UnlockSim.this) {
2474 mHandler = new Handler() {
2475 @Override
2476 public void handleMessage(Message msg) {
2477 AsyncResult ar = (AsyncResult) msg.obj;
2478 switch (msg.what) {
2479 case SUPPLY_PIN_COMPLETE:
2480 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2481 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002482 mRetryCount = msg.arg1;
2483 if (ar.exception != null) {
2484 if (ar.exception instanceof CommandException &&
2485 ((CommandException)(ar.exception)).getCommandError()
2486 == CommandException.Error.PASSWORD_INCORRECT) {
2487 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002488 } //When UiccCardApp dispose,handle message and return exception
2489 else if (ar.exception instanceof CommandException &&
2490 ((CommandException) (ar.exception)).getCommandError()
2491 == CommandException.Error.ABORTED) {
2492 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002493 } else {
2494 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2495 }
2496 } else {
2497 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2498 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 mDone = true;
2500 UnlockSim.this.notifyAll();
2501 }
2502 break;
2503 }
2504 }
2505 };
2506 UnlockSim.this.notifyAll();
2507 }
2508 Looper.loop();
2509 }
2510
2511 /*
2512 * Use PIN or PUK to unlock SIM card
2513 *
2514 * If PUK is null, unlock SIM card with PIN
2515 *
2516 * If PUK is not null, unlock SIM card with PUK and set PIN code
2517 */
Wink Saville9de0f752013-10-22 19:04:03 -07002518 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519
2520 while (mHandler == null) {
2521 try {
2522 wait();
2523 } catch (InterruptedException e) {
2524 Thread.currentThread().interrupt();
2525 }
2526 }
2527 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2528
2529 if (puk == null) {
2530 mSimCard.supplyPin(pin, callback);
2531 } else {
2532 mSimCard.supplyPuk(puk, pin, callback);
2533 }
2534
2535 while (!mDone) {
2536 try {
2537 Log.d(LOG_TAG, "wait for done");
2538 wait();
2539 } catch (InterruptedException e) {
2540 // Restore the interrupted status
2541 Thread.currentThread().interrupt();
2542 }
2543 }
2544 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002545 int[] resultArray = new int[2];
2546 resultArray[0] = mResult;
2547 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002548
2549 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2550 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2551 }
2552
Wink Saville9de0f752013-10-22 19:04:03 -07002553 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 }
2555 }
2556
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002557 /**
2558 * This method has been removed due to privacy and stability concerns.
2559 */
2560 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002561 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002562 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2563 return;
Wink Saville36469e72014-06-11 15:17:00 -07002564 }
2565
Nathan Harold1f889d82020-06-04 17:05:26 -07002566 @Override
2567 public void updateServiceLocationWithPackageName(String callingPackage) {
2568 mApp.getSystemService(AppOpsManager.class)
2569 .checkPackage(Binder.getCallingUid(), callingPackage);
2570
Nathan Haroldf096d982020-11-18 17:18:06 -08002571 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002572 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2573 // Callers targeting S have no business invoking this method.
2574 return;
2575 }
2576
2577 LocationAccessPolicy.LocationPermissionResult locationResult =
2578 LocationAccessPolicy.checkLocationPermission(mApp,
2579 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2580 .setCallingPackage(callingPackage)
2581 .setCallingFeatureId(null)
2582 .setCallingPid(Binder.getCallingPid())
2583 .setCallingUid(Binder.getCallingUid())
2584 .setMethod("updateServiceLocation")
2585 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2586 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2587 .build());
2588 // Apps that lack location permission have no business calling this method;
2589 // however, because no permission was declared in the public API, denials must
2590 // all be "soft".
2591 switch (locationResult) {
2592 case DENIED_HARD: /* fall through */
2593 case DENIED_SOFT:
2594 return;
2595 }
2596
2597 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 final long identity = Binder.clearCallingIdentity();
2599 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002600 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002602 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603 }
2604 } finally {
2605 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002606 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002607 }
2608
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002609 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002610 @Override
2611 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002612 return isRadioOnWithFeature(callingPackage, null);
2613 }
2614
2615
2616 @Override
2617 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2618 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2619 callingFeatureId);
2620 }
2621
2622 @Deprecated
2623 @Override
2624 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2625 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002626 }
2627
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002628 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002629 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2630 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002632 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002633 return false;
2634 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635
2636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 return isRadioOnForSubscriber(subId);
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
2641 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002642 }
2643
2644 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002645 final long identity = Binder.clearCallingIdentity();
2646 try {
2647 final Phone phone = getPhone(subId);
2648 if (phone != null) {
2649 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2650 } else {
2651 return false;
2652 }
2653 } finally {
2654 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002656 }
2657
2658 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002659 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660 }
Wink Saville36469e72014-06-11 15:17:00 -07002661
Wink Savilleb564aae2014-10-23 10:18:09 -07002662 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002664
2665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 final Phone phone = getPhone(subId);
2668 if (phone != null) {
2669 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2670 }
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002673 }
Wink Saville36469e72014-06-11 15:17:00 -07002674 }
2675
2676 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002677 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002678 }
2679
Wink Savilleb564aae2014-10-23 10:18:09 -07002680 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002681 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682
2683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 final Phone phone = getPhone(subId);
2686 if (phone == null) {
2687 return false;
2688 }
2689 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2690 toggleRadioOnOffForSubscriber(subId);
2691 }
2692 return true;
2693 } finally {
2694 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002695 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 }
Wink Saville36469e72014-06-11 15:17:00 -07002697
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002698 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002699 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002700 /*
2701 * If any of the Radios are available, it will need to be
2702 * shutdown. So return true if any Radio is available.
2703 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704 final long identity = Binder.clearCallingIdentity();
2705 try {
2706 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2707 Phone phone = PhoneFactory.getPhone(i);
2708 if (phone != null && phone.isRadioAvailable()) return true;
2709 }
2710 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2711 return false;
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002714 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002715 }
2716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002718 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 enforceModifyPermission();
2720
2721 final long identity = Binder.clearCallingIdentity();
2722 try {
2723 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2724 logv("Shutting down Phone " + i);
2725 shutdownRadioUsingPhoneId(i);
2726 }
2727 } finally {
2728 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002729 }
2730 }
2731
2732 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002733 Phone phone = PhoneFactory.getPhone(phoneId);
2734 if (phone != null && phone.isRadioAvailable()) {
2735 phone.shutdownRadio();
2736 }
2737 }
2738
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002740 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741
2742 final long identity = Binder.clearCallingIdentity();
2743 try {
2744 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2745 if (defaultPhone != null) {
2746 defaultPhone.setRadioPower(turnOn);
2747 return true;
2748 } else {
2749 loge("There's no default phone.");
2750 return false;
2751 }
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002754 }
Wink Saville36469e72014-06-11 15:17:00 -07002755 }
2756
Wink Savilleb564aae2014-10-23 10:18:09 -07002757 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002758 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759
2760 final long identity = Binder.clearCallingIdentity();
2761 try {
2762 final Phone phone = getPhone(subId);
2763 if (phone != null) {
2764 phone.setRadioPower(turnOn);
2765 return true;
2766 } else {
2767 return false;
2768 }
2769 } finally {
2770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002772 }
2773
Wink Saville36469e72014-06-11 15:17:00 -07002774 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002775 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 public boolean enableDataConnectivity() {
2777 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778
2779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 int subId = mSubscriptionController.getDefaultDataSubId();
2782 final Phone phone = getPhone(subId);
2783 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002784 phone.getDataEnabledSettings().setDataEnabled(
2785 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 return true;
2787 } else {
2788 return false;
2789 }
2790 } finally {
2791 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002793 }
2794
Wink Saville36469e72014-06-11 15:17:00 -07002795 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002796 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 public boolean disableDataConnectivity() {
2798 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799
2800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 int subId = mSubscriptionController.getDefaultDataSubId();
2803 final Phone phone = getPhone(subId);
2804 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002805 phone.getDataEnabledSettings().setDataEnabled(
2806 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807 return true;
2808 } else {
2809 return false;
2810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 }
2815
Sanket Padawe356d7632015-06-22 14:03:32 -07002816 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002817 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 final Phone phone = getPhone(subId);
2821 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002822 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823 } else {
2824 return false;
2825 }
2826 } finally {
2827 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002829 }
2830
2831 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002832 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002833 }
2834
pkanwarae03a6b2016-11-06 20:37:09 -08002835 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836 enforceCallPermission();
2837
2838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2841 return;
2842 }
2843 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2844 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2845 } finally {
2846 Binder.restoreCallingIdentity(identity);
2847 }
pkanwar32d516d2016-10-14 19:37:38 -07002848 };
2849
Wink Savilleb564aae2014-10-23 10:18:09 -07002850 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852
2853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2856 return false;
2857 }
2858 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2859 } finally {
2860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 }
2863
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002864 /**
2865 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2866 * tag on getCallState Binder call.
2867 */
2868 @Deprecated
2869 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002870 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002871 if (CompatChanges.isChangeEnabled(
2872 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2873 Binder.getCallingUid())) {
2874 // Do not allow this API to be called on API version 31+, it should only be
2875 // called on old apps using this Binder call directly.
2876 throw new SecurityException("This method can only be used for applications "
2877 + "targeting API version 30 or less.");
2878 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879 final long identity = Binder.clearCallingIdentity();
2880 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002881 Phone phone = getPhone(getDefaultSubscription());
2882 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2883 PhoneConstantConversions.convertCallState(phone.getState());
2884 } finally {
2885 Binder.restoreCallingIdentity(identity);
2886 }
2887 }
2888
2889 @Override
2890 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2891 if (CompatChanges.isChangeEnabled(
2892 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2893 Binder.getCallingUid())) {
2894 // Check READ_PHONE_STATE for API version 31+
2895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2896 featureId, "getCallStateForSubscription")) {
2897 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2898 + "targeting API level 31+.");
2899 }
2900 }
2901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002904 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2905 PhoneConstantConversions.convertCallState(phone.getState());
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
2908 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002909 }
2910
Sanket Padawe356d7632015-06-22 14:03:32 -07002911 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002912 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002913 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2914 }
2915
2916 @Override
2917 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002918 final long identity = Binder.clearCallingIdentity();
2919 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002920 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 if (phone != null) {
2922 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2923 } else {
2924 return PhoneConstantConversions.convertDataState(
2925 PhoneConstants.DataState.DISCONNECTED);
2926 }
2927 } finally {
2928 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
2931
Sanket Padawe356d7632015-06-22 14:03:32 -07002932 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002933 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002934 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2935 }
2936
2937 @Override
2938 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 final long identity = Binder.clearCallingIdentity();
2940 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002941 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942 if (phone != null) {
2943 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2944 } else {
2945 return TelephonyManager.DATA_ACTIVITY_NONE;
2946 }
2947 } finally {
2948 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002950 }
2951
2952 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002953 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002954 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002955 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002956
2957 LocationAccessPolicy.LocationPermissionResult locationResult =
2958 LocationAccessPolicy.checkLocationPermission(mApp,
2959 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2960 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002961 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002962 .setCallingPid(Binder.getCallingPid())
2963 .setCallingUid(Binder.getCallingUid())
2964 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002965 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002966 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2967 .build());
2968 switch (locationResult) {
2969 case DENIED_HARD:
2970 throw new SecurityException("Not allowed to access cell location");
2971 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002972 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2973 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002974 }
2975
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002976 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002977 final long identity = Binder.clearCallingIdentity();
2978 try {
2979 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002980 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002981 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002982 } finally {
2983 Binder.restoreCallingIdentity(identity);
2984 }
Svetoslav64fad262015-04-14 14:35:21 -07002985 }
2986
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002987 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002988 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002989 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2990 // registered cell info, so return a NULL country instead.
2991 final long identity = Binder.clearCallingIdentity();
2992 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002993 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2994 // Get default phone in this case.
2995 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2996 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002997 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002999 if (phone == null) return "";
3000 ServiceStateTracker sst = phone.getServiceStateTracker();
3001 if (sst == null) return "";
3002 LocaleTracker lt = sst.getLocaleTracker();
3003 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003004 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003008 }
3009
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003010 /**
3011 * This method was removed due to potential issues caused by performing partial
3012 * updates of service state, and lack of a credible use case.
3013 *
3014 * This has the ability to break the telephony implementation by disabling notification of
3015 * changes in device connectivity. DO NOT USE THIS!
3016 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003017 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003018 public void enableLocationUpdates() {
3019 mApp.enforceCallingOrSelfPermission(
3020 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003021 }
3022
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003023 /**
3024 * This method was removed due to potential issues caused by performing partial
3025 * updates of service state, and lack of a credible use case.
3026 *
3027 * This has the ability to break the telephony implementation by disabling notification of
3028 * changes in device connectivity. DO NOT USE THIS!
3029 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003030 @Override
3031 public void disableLocationUpdates() {
3032 mApp.enforceCallingOrSelfPermission(
3033 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003034 }
3035
3036 @Override
3037 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003038 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3039 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003040 try {
3041 mApp.getSystemService(AppOpsManager.class)
3042 .checkPackage(Binder.getCallingUid(), callingPackage);
3043 } catch (SecurityException e) {
3044 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3045 throw e;
3046 }
3047
Nathan Haroldf096d982020-11-18 17:18:06 -08003048 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003049 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3050 throw new SecurityException(
3051 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3052 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003053
Jordan Liu1617b712019-07-10 15:06:26 -07003054 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003055 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3056 return null;
3057 }
Svetoslav64fad262015-04-14 14:35:21 -07003058
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003059 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003060
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003061 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003062 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003063
Nathan Haroldf180aac2018-06-01 18:43:55 -07003064 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3065 for (CellInfo ci : info) {
3066 if (ci instanceof CellInfoGsm) {
3067 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3068 } else if (ci instanceof CellInfoWcdma) {
3069 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3070 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003071 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003072 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003073 }
3074
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003075 private List<CellInfo> getCachedCellInfo() {
3076 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3077 for (Phone phone : PhoneFactory.getPhones()) {
3078 List<CellInfo> info = phone.getAllCellInfo();
3079 if (info != null) cellInfos.addAll(info);
3080 }
3081 return cellInfos;
3082 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003083
3084 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003085 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003086 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003087 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003088
3089 LocationAccessPolicy.LocationPermissionResult locationResult =
3090 LocationAccessPolicy.checkLocationPermission(mApp,
3091 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3092 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003093 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003094 .setCallingPid(Binder.getCallingPid())
3095 .setCallingUid(Binder.getCallingUid())
3096 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003097 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003098 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3099 .build());
3100 switch (locationResult) {
3101 case DENIED_HARD:
3102 throw new SecurityException("Not allowed to access cell info");
3103 case DENIED_SOFT:
3104 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003105 }
3106
Nathan Haroldf096d982020-11-18 17:18:06 -08003107 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003108 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3109 return getCachedCellInfo();
3110 }
3111
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003112 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003113 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3117 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003118 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003119 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003120 if (info != null) cellInfos.addAll(info);
3121 }
3122 return cellInfos;
3123 } finally {
3124 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003125 }
3126 }
3127
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003128 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003129 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3130 String callingFeatureId) {
3131 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3132 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003133 }
3134
3135 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003136 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3137 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003138 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003139 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003140 }
3141
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003142 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3143 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003144 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003145 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003146
3147 LocationAccessPolicy.LocationPermissionResult locationResult =
3148 LocationAccessPolicy.checkLocationPermission(mApp,
3149 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3150 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003151 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003152 .setCallingPid(Binder.getCallingPid())
3153 .setCallingUid(Binder.getCallingUid())
3154 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003155 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3156 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003157 .build());
3158 switch (locationResult) {
3159 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003160 if (TelephonyPermissions
3161 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003162 // Safetynet logging for b/154934934
3163 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3164 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003165 throw new SecurityException("Not allowed to access cell info");
3166 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003167 if (TelephonyPermissions
3168 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003169 // Safetynet logging for b/154934934
3170 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3171 }
Nathan Harold5320c422019-05-09 10:26:08 -07003172 try {
3173 cb.onCellInfo(new ArrayList<CellInfo>());
3174 } catch (RemoteException re) {
3175 // Drop without consequences
3176 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003177 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003178 }
3179
Nathan Harolda939a962019-05-09 10:13:47 -07003180
3181 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003182 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3183
3184 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3185 }
3186
3187 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003188 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003189 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003190 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003191
3192 final long identity = Binder.clearCallingIdentity();
3193 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003194 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003195 } finally {
3196 Binder.restoreCallingIdentity(identity);
3197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003198 }
3199
Shishir Agrawala9f32182016-04-12 12:00:16 -07003200 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003201 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003202 Phone phone = PhoneFactory.getPhone(slotIndex);
3203 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003204 return null;
3205 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003206 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003207 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003208 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003209 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003210 return null;
3211 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212
3213 final long identity = Binder.clearCallingIdentity();
3214 try {
3215 return phone.getImei();
3216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003219 }
3220
3221 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003222 public String getTypeAllocationCodeForSlot(int slotIndex) {
3223 Phone phone = PhoneFactory.getPhone(slotIndex);
3224 String tac = null;
3225 if (phone != null) {
3226 String imei = phone.getImei();
3227 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3228 }
3229 return tac;
3230 }
3231
3232 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003233 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003234 try {
3235 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3236 } catch (SecurityException se) {
3237 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3238 throw new SecurityException("Package " + callingPackage + " does not belong to "
3239 + Binder.getCallingUid());
3240 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003241 Phone phone = PhoneFactory.getPhone(slotIndex);
3242 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003243 return null;
3244 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003245
Jeff Davidson913390f2018-02-23 17:11:49 -08003246 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003247 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003248 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003249 return null;
3250 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251
3252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 return phone.getMeid();
3255 } finally {
3256 Binder.restoreCallingIdentity(identity);
3257 }
Jack Yu2af8d712017-03-15 17:14:14 -07003258 }
3259
3260 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003261 public String getManufacturerCodeForSlot(int slotIndex) {
3262 Phone phone = PhoneFactory.getPhone(slotIndex);
3263 String manufacturerCode = null;
3264 if (phone != null) {
3265 String meid = phone.getMeid();
3266 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3267 }
3268 return manufacturerCode;
3269 }
3270
3271 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003272 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3273 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003274 Phone phone = PhoneFactory.getPhone(slotIndex);
3275 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003276 return null;
3277 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003278 int subId = phone.getSubId();
3279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003280 mApp, subId, callingPackage, callingFeatureId,
3281 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003282 return null;
3283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284
3285 final long identity = Binder.clearCallingIdentity();
3286 try {
3287 return phone.getDeviceSvn();
3288 } finally {
3289 Binder.restoreCallingIdentity(identity);
3290 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003291 }
3292
fionaxu43304da2017-11-27 22:51:16 -08003293 @Override
3294 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003295 final long identity = Binder.clearCallingIdentity();
3296 try {
3297 final Phone phone = getPhone(subId);
3298 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3299 } finally {
3300 Binder.restoreCallingIdentity(identity);
3301 }
fionaxu43304da2017-11-27 22:51:16 -08003302 }
3303
3304 @Override
3305 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003306 final long identity = Binder.clearCallingIdentity();
3307 try {
3308 final Phone phone = getPhone(subId);
3309 return phone == null ? null : phone.getCarrierName();
3310 } finally {
3311 Binder.restoreCallingIdentity(identity);
3312 }
fionaxu43304da2017-11-27 22:51:16 -08003313 }
3314
calvinpanffe225e2018-11-01 19:43:06 +08003315 @Override
chen xu0026ca62019-03-06 15:28:50 -08003316 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003317 final long identity = Binder.clearCallingIdentity();
3318 try {
3319 final Phone phone = getPhone(subId);
3320 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003321 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
3325 }
3326
3327 @Override
chen xu0026ca62019-03-06 15:28:50 -08003328 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003329 final long identity = Binder.clearCallingIdentity();
3330 try {
3331 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003332 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003333 } finally {
3334 Binder.restoreCallingIdentity(identity);
3335 }
3336 }
3337
chen xu651eec72018-11-11 19:03:44 -08003338 @Override
chen xu864e11c2018-12-06 22:10:03 -08003339 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3340 if (!isSubscriptionMccMnc) {
3341 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3342 }
chen xu651eec72018-11-11 19:03:44 -08003343 final Phone phone = PhoneFactory.getPhone(slotIndex);
3344 if (phone == null) {
3345 return TelephonyManager.UNKNOWN_CARRIER_ID;
3346 }
3347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3350 } finally {
3351 Binder.restoreCallingIdentity(identity);
3352 }
3353 }
3354
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003355 //
3356 // Internal helper methods.
3357 //
3358
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003359 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003360 * Make sure the caller is the calling package itself
3361 *
3362 * @throws SecurityException if the caller is not the calling package
3363 */
3364 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3365 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003366 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3367 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003368 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003369 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003370 } catch (PackageManager.NameNotFoundException e) {
3371 // packageUid is -1
3372 }
3373 if (packageUid != callingUid) {
3374 throw new SecurityException(message + ": Package " + callingPackage
3375 + " does not belong to " + callingUid);
3376 }
3377 }
3378
3379 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003380 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3381 *
3382 * @throws SecurityException if the caller does not have the required permission
3383 */
3384 private void enforceModifyPermission() {
3385 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3386 }
3387
Shuo Qiancd19c462020-01-16 20:51:11 -08003388 /**
3389 * Make sure the caller is system.
3390 *
3391 * @throws SecurityException if the caller is not system.
3392 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003393 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003394 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3395 throw new SecurityException("Caller must be system");
3396 }
3397 }
3398
Shuo Qian3b6ee772019-11-13 17:43:31 -08003399 private void enforceActiveEmergencySessionPermission() {
3400 mApp.enforceCallingOrSelfPermission(
3401 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3402 }
3403
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003404 /**
3405 * Make sure the caller has the CALL_PHONE permission.
3406 *
3407 * @throws SecurityException if the caller does not have the required permission
3408 */
3409 private void enforceCallPermission() {
3410 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3411 }
3412
paulhu5a773602019-08-23 19:17:33 +08003413 private void enforceSettingsPermission() {
3414 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003415 }
3416
Michele Berionne5e411512020-11-13 02:36:59 +00003417 private void enforceRebootPermission() {
3418 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3419 }
3420
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003421 private String createTelUrl(String number) {
3422 if (TextUtils.isEmpty(number)) {
3423 return null;
3424 }
3425
Jake Hambye994d462014-02-03 13:10:13 -08003426 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003427 }
3428
Ihab Awadf9e92732013-12-05 18:02:52 -08003429 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003430 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3431 }
3432
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003433 private static void logv(String msg) {
3434 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3435 }
3436
Ihab Awadf9e92732013-12-05 18:02:52 -08003437 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003438 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3439 }
3440
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003441 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003442 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003443 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003444 }
3445
Sanket Padawe356d7632015-06-22 14:03:32 -07003446 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003447 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 final Phone phone = PhoneFactory.getPhone(slotIndex);
3451 if (phone == null) {
3452 return PhoneConstants.PHONE_TYPE_NONE;
3453 } else {
3454 return phone.getPhoneType();
3455 }
3456 } finally {
3457 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003459 }
3460
3461 /**
3462 * Returns the CDMA ERI icon index to display
3463 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003464 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003465 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3466 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3467 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003468 }
3469
Sanket Padawe356d7632015-06-22 14:03:32 -07003470 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003471 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3472 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003474 mApp, subId, callingPackage, callingFeatureId,
3475 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003476 return -1;
3477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003478
3479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 final Phone phone = getPhone(subId);
3482 if (phone != null) {
3483 return phone.getCdmaEriIconIndex();
3484 } else {
3485 return -1;
3486 }
3487 } finally {
3488 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003489 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003490 }
3491
3492 /**
3493 * Returns the CDMA ERI icon mode,
3494 * 0 - ON
3495 * 1 - FLASHING
3496 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003497 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003498 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3499 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3500 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003501 }
3502
Sanket Padawe356d7632015-06-22 14:03:32 -07003503 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003504 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3505 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003506 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003507 mApp, subId, callingPackage, callingFeatureId,
3508 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003509 return -1;
3510 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003511
3512 final long identity = Binder.clearCallingIdentity();
3513 try {
3514 final Phone phone = getPhone(subId);
3515 if (phone != null) {
3516 return phone.getCdmaEriIconMode();
3517 } else {
3518 return -1;
3519 }
3520 } finally {
3521 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003523 }
3524
3525 /**
3526 * Returns the CDMA ERI text,
3527 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003529 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3530 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3531 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003532 }
3533
Sanket Padawe356d7632015-06-22 14:03:32 -07003534 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003535 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3536 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003538 mApp, subId, callingPackage, callingFeatureId,
3539 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003540 return null;
3541 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003542
3543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 final Phone phone = getPhone(subId);
3546 if (phone != null) {
3547 return phone.getCdmaEriText();
3548 } else {
3549 return null;
3550 }
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003554 }
3555
3556 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003557 * Returns the CDMA MDN.
3558 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003559 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003560 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3562 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003563
3564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003567 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003568 return phone.getLine1Number();
3569 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003570 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571 return null;
3572 }
3573 } finally {
3574 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003575 }
3576 }
3577
3578 /**
3579 * Returns the CDMA MIN.
3580 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003581 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003582 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3584 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003585
3586 final long identity = Binder.clearCallingIdentity();
3587 try {
3588 final Phone phone = getPhone(subId);
3589 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3590 return phone.getCdmaMin();
3591 } else {
3592 return null;
3593 }
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003596 }
3597 }
3598
Hall Liud892bec2018-11-30 14:51:45 -08003599 @Override
3600 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3601 INumberVerificationCallback callback, String callingPackage) {
3602 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3603 != PERMISSION_GRANTED) {
3604 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3605 }
3606 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3607
3608 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3609 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003610 throw new SecurityException("Calling package must be configured in the device config: "
3611 + "calling package: " + callingPackage
3612 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003613 }
3614
3615 if (range == null) {
3616 throw new NullPointerException("Range must be non-null");
3617 }
3618
3619 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003620 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003621
3622 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3623 }
3624
Junda Liuca05d5d2014-08-14 22:36:34 -07003625 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003626 * Returns true if CDMA provisioning needs to run.
3627 */
3628 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629 final long identity = Binder.clearCallingIdentity();
3630 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003631 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003632 } finally {
3633 Binder.restoreCallingIdentity(identity);
3634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003635 }
3636
3637 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003638 * Sets the voice mail number of a given subId.
3639 */
3640 @Override
3641 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003642 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3643 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003644
3645 final long identity = Binder.clearCallingIdentity();
3646 try {
3647 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3648 new Pair<String, String>(alphaTag, number), new Integer(subId));
3649 return success;
3650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003653 }
3654
Ta-wei Yen87c49842016-05-13 21:19:52 -07003655 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003656 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3657 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003658 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3659 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003660 if (!TextUtils.equals(callingPackage, systemDialer)) {
3661 throw new SecurityException("caller must be system dialer");
3662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003663
3664 final long identity = Binder.clearCallingIdentity();
3665 try {
3666 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3667 if (phoneAccountHandle == null) {
3668 return null;
3669 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003670 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003671 } finally {
3672 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003673 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003674 }
3675
3676 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003677 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3678 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003679 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003680 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003681 mApp, subId, callingPackage, callingFeatureId,
3682 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003683 return null;
3684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003685
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003686 final long identity = Binder.clearCallingIdentity();
3687 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003688 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003689 } finally {
3690 Binder.restoreCallingIdentity(identity);
3691 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003692 }
3693
3694 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003695 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3696 VisualVoicemailSmsFilterSettings settings) {
3697 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003698
3699 final long identity = Binder.clearCallingIdentity();
3700 try {
3701 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003702 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003703 } finally {
3704 Binder.restoreCallingIdentity(identity);
3705 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003706 }
3707
3708 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003709 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3710 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003711
3712 final long identity = Binder.clearCallingIdentity();
3713 try {
3714 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003715 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003719 }
3720
3721 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003722 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3723 String callingPackage, int subId) {
3724 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003725
3726 final long identity = Binder.clearCallingIdentity();
3727 try {
3728 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003729 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003730 } finally {
3731 Binder.restoreCallingIdentity(identity);
3732 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003733 }
3734
3735 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003736 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003738
3739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003742 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743 } finally {
3744 Binder.restoreCallingIdentity(identity);
3745 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003746 }
3747
3748 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003749 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3750 String callingAttributionTag, int subId, String number, int port, String text,
3751 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003752 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003753 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003754 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003755 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003756 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3757 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003758 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003759
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003760 /**
fionaxu0152e512016-11-14 13:36:14 -08003761 * Sets the voice activation state of a given subId.
3762 */
3763 @Override
3764 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3766 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003767
3768 final long identity = Binder.clearCallingIdentity();
3769 try {
3770 final Phone phone = getPhone(subId);
3771 if (phone != null) {
3772 phone.setVoiceActivationState(activationState);
3773 } else {
3774 loge("setVoiceActivationState fails with invalid subId: " + subId);
3775 }
3776 } finally {
3777 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003778 }
3779 }
3780
3781 /**
3782 * Sets the data activation state of a given subId.
3783 */
3784 @Override
3785 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3787 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003788
3789 final long identity = Binder.clearCallingIdentity();
3790 try {
3791 final Phone phone = getPhone(subId);
3792 if (phone != null) {
3793 phone.setDataActivationState(activationState);
3794 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003795 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 }
3797 } finally {
3798 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003799 }
3800 }
3801
3802 /**
3803 * Returns the voice activation state of a given subId.
3804 */
3805 @Override
3806 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003807 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808
fionaxu0152e512016-11-14 13:36:14 -08003809 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 if (phone != null) {
3813 return phone.getVoiceActivationState();
3814 } else {
3815 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3816 }
3817 } finally {
3818 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003819 }
3820 }
3821
3822 /**
3823 * Returns the data activation state of a given subId.
3824 */
3825 @Override
3826 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003827 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828
fionaxu0152e512016-11-14 13:36:14 -08003829 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830 final long identity = Binder.clearCallingIdentity();
3831 try {
3832 if (phone != null) {
3833 return phone.getDataActivationState();
3834 } else {
3835 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3836 }
3837 } finally {
3838 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003839 }
3840 }
3841
3842 /**
Wink Saville36469e72014-06-11 15:17:00 -07003843 * Returns the unread count of voicemails for a subId
3844 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003845 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003846 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3847 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003848 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003849 mApp, subId, callingPackage, callingFeatureId,
3850 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003851 return 0;
3852 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853 final long identity = Binder.clearCallingIdentity();
3854 try {
3855 final Phone phone = getPhone(subId);
3856 if (phone != null) {
3857 return phone.getVoiceMessageCount();
3858 } else {
3859 return 0;
3860 }
3861 } finally {
3862 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003863 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003864 }
3865
3866 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003867 * returns true, if the device is in a state where both voice and data
3868 * are supported simultaneously. This can change based on location or network condition.
3869 */
3870 @Override
3871 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 final Phone phone = getPhone(subId);
3875 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3876 } finally {
3877 Binder.restoreCallingIdentity(identity);
3878 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003879 }
3880
3881 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003882 * Send the dialer code if called from the current default dialer or the caller has
3883 * carrier privilege.
3884 * @param inputCode The dialer code to send
3885 */
3886 @Override
3887 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003888 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003889 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003890 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3891 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003892 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003893 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003894 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896
3897 final long identity = Binder.clearCallingIdentity();
3898 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003899 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003900 } finally {
3901 Binder.restoreCallingIdentity(identity);
3902 }
fionaxu235cc5e2017-03-06 22:25:57 -08003903 }
3904
Pengquan Menga1bb6272018-09-06 09:59:22 -07003905 @Override
3906 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003907 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003908 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003909 mApp, subId, "getNetworkSelectionMode");
3910 final long identity = Binder.clearCallingIdentity();
3911 try {
3912 if (!isActiveSubscription(subId)) {
3913 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3914 }
3915 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3916 } finally {
3917 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003918 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003919 }
3920
Brad Ebinger35c841c2018-10-01 10:40:55 -07003921 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003922 public boolean isInEmergencySmsMode() {
3923 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3924 final long identity = Binder.clearCallingIdentity();
3925 try {
3926 for (Phone phone : PhoneFactory.getPhones()) {
3927 if (phone.isInEmergencySmsMode()) {
3928 return true;
3929 }
3930 }
3931 } finally {
3932 Binder.restoreCallingIdentity(identity);
3933 }
3934 return false;
3935 }
3936
shilu366312e2019-12-17 09:28:10 -08003937 /**
3938 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3939 * @param subId The subscription to use to check the configuration.
3940 * @param c The callback that will be used to send the result.
3941 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003942 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003943 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3944 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003945 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003946 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003947
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003948 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3949 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3950 "IMS not available on device.");
3951 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003952 final long token = Binder.clearCallingIdentity();
3953 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003954 int slotId = getSlotIndexOrException(subId);
3955 verifyImsMmTelConfiguredOrThrow(slotId);
3956 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003957 } catch (ImsException e) {
3958 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003959 } finally {
3960 Binder.restoreCallingIdentity(token);
3961 }
3962 }
3963
shilu366312e2019-12-17 09:28:10 -08003964 /**
3965 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3966 * @param subId The subscription to use to check the configuration.
3967 * @param c The callback that will be used to send the result.
3968 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003970 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003971 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003972 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003973 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3974 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3975 }
Meng Wangafbc5852019-09-19 17:37:13 -07003976 final long token = Binder.clearCallingIdentity();
3977 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003978 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3979 .removeRegistrationCallbackForSubscription(c, subId);
3980 } catch (ImsException e) {
3981 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3982 + "is inactive, ignoring unregister.");
3983 // If the subscription is no longer active, just return, since the callback
3984 // will already have been removed internally.
3985 } finally {
3986 Binder.restoreCallingIdentity(token);
3987 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003988 }
3989
Brad Ebingera34a6c22019-10-22 17:36:18 -07003990 /**
3991 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3992 */
3993 @Override
3994 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3995 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3996 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3997 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3998 "IMS not available on device.");
3999 }
4000 final long token = Binder.clearCallingIdentity();
4001 try {
4002 Phone phone = getPhone(subId);
4003 if (phone == null) {
4004 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4005 + subId + "'");
4006 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4007 }
4008 phone.getImsRegistrationState(regState -> {
4009 try {
4010 consumer.accept((regState == null)
4011 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4012 } catch (RemoteException e) {
4013 // Ignore if the remote process is no longer available to call back.
4014 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4015 }
4016 });
4017 } finally {
4018 Binder.restoreCallingIdentity(token);
4019 }
4020 }
4021
4022 /**
4023 * Get the transport type for the IMS service registration state.
4024 */
4025 @Override
4026 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004027 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004028 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004029 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4030 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4031 "IMS not available on device.");
4032 }
4033 final long token = Binder.clearCallingIdentity();
4034 try {
4035 Phone phone = getPhone(subId);
4036 if (phone == null) {
4037 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4038 + subId + "'");
4039 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4040 }
4041 phone.getImsRegistrationTech(regTech -> {
4042 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4043 int regTechConverted = (regTech == null)
4044 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4045 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4046 regTechConverted);
4047 try {
4048 consumer.accept(regTechConverted);
4049 } catch (RemoteException e) {
4050 // Ignore if the remote process is no longer available to call back.
4051 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4052 }
4053 });
4054 } finally {
4055 Binder.restoreCallingIdentity(token);
4056 }
4057 }
4058
shilu366312e2019-12-17 09:28:10 -08004059 /**
4060 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4061 * @param subId The subscription to use to check the configuration.
4062 * @param c The callback that will be used to send the result.
4063 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004064 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004065 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4066 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004067 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004068 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004069 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4070 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4071 "IMS not available on device.");
4072 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004073 final long token = Binder.clearCallingIdentity();
4074 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004075 int slotId = getSlotIndexOrException(subId);
4076 verifyImsMmTelConfiguredOrThrow(slotId);
4077 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004078 } catch (ImsException e) {
4079 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004080 } finally {
4081 Binder.restoreCallingIdentity(token);
4082 }
4083 }
4084
shilu366312e2019-12-17 09:28:10 -08004085 /**
4086 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4087 * @param subId The subscription to use to check the configuration.
4088 * @param c The callback that will be used to send the result.
4089 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004090 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004091 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004092 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004093 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004094 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4095 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4096 }
Meng Wangafbc5852019-09-19 17:37:13 -07004097
4098 final long token = Binder.clearCallingIdentity();
4099 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004100 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004101 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004102 } catch (ImsException e) {
4103 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4104 + "is inactive, ignoring unregister.");
4105 // If the subscription is no longer active, just return, since the callback
4106 // will already have been removed internally.
4107 } finally {
4108 Binder.restoreCallingIdentity(token);
4109 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004110 }
4111
4112 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004113 public boolean isCapable(int subId, int capability, int regTech) {
4114 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004115 final long token = Binder.clearCallingIdentity();
4116 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004117 int slotId = getSlotIndexOrException(subId);
4118 verifyImsMmTelConfiguredOrThrow(slotId);
4119 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004120 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004121 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4122 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004123 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004124 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4125 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 } finally {
4127 Binder.restoreCallingIdentity(token);
4128 }
4129 }
4130
4131 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004132 public boolean isAvailable(int subId, int capability, int regTech) {
4133 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 final long token = Binder.clearCallingIdentity();
4135 try {
4136 Phone phone = getPhone(subId);
4137 if (phone == null) return false;
4138 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004139 } catch (com.android.ims.ImsException e) {
4140 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4141 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 } finally {
4143 Binder.restoreCallingIdentity(token);
4144 }
4145 }
4146
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004147 /**
4148 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4149 * subscription.
4150 * @param subId The subscription to use to check the configuration.
4151 * @param callback The callback that will be used to send the result.
4152 * @param capability The MmTelFeature capability that will be used to send the result.
4153 * @param transportType The transport type of the MmTelFeature capability.
4154 */
4155 @Override
4156 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4157 int transportType) {
4158 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4159 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4160 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4161 "IMS not available on device.");
4162 }
4163 final long token = Binder.clearCallingIdentity();
4164 try {
4165 int slotId = getSlotIndex(subId);
4166 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4167 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4168 + subId + "'");
4169 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4170 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004171 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004172 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4173 transportType, aBoolean -> {
4174 try {
4175 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4176 } catch (RemoteException e) {
4177 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4178 + "running. Ignore");
4179 }
4180 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004181 } catch (ImsException e) {
4182 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004183 } finally {
4184 Binder.restoreCallingIdentity(token);
4185 }
4186 }
4187
shilu366312e2019-12-17 09:28:10 -08004188 /**
4189 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4190 * @param subId The subscription to use to check the configuration.
4191 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 @Override
4193 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004194 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004195 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004196
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 final long token = Binder.clearCallingIdentity();
4198 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004199 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004200 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004201 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004202 } catch (ImsException e) {
4203 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004204 } finally {
4205 Binder.restoreCallingIdentity(token);
4206 }
4207 }
4208
4209 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004210 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004212 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 final long identity = Binder.clearCallingIdentity();
4214 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004215 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004216 // This setting doesn't require an active ImsService connection, so do not verify. The
4217 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004218 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004219 } catch (ImsException e) {
4220 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 } finally {
4222 Binder.restoreCallingIdentity(identity);
4223 }
4224 }
4225
shilu366312e2019-12-17 09:28:10 -08004226 /**
4227 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4228 * @param subId The subscription to use to check the configuration.
4229 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004230 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004231 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004232 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004233 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 final long identity = Binder.clearCallingIdentity();
4235 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004236 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004237 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004238 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004239 } catch (ImsException e) {
4240 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004241 } finally {
4242 Binder.restoreCallingIdentity(identity);
4243 }
4244 }
4245
4246 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004247 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004249 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004250 final long identity = Binder.clearCallingIdentity();
4251 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004252 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004253 // This setting doesn't require an active ImsService connection, so do not verify. The
4254 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004255 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004256 } catch (ImsException e) {
4257 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004258 } finally {
4259 Binder.restoreCallingIdentity(identity);
4260 }
4261 }
4262
shilu366312e2019-12-17 09:28:10 -08004263 /**
4264 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4265 * @param subId The subscription to use to check the configuration.
4266 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004267 @Override
4268 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004269 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004270 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 final long identity = Binder.clearCallingIdentity();
4272 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004273 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004274 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004275 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004276 } catch (ImsException e) {
4277 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004278 } finally {
4279 Binder.restoreCallingIdentity(identity);
4280 }
4281 }
4282
4283 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004284 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004286 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004287 final long identity = Binder.clearCallingIdentity();
4288 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004289 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004290 // This setting doesn't require an active ImsService connection, so do not verify. The
4291 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004292 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004293 } catch (ImsException e) {
4294 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 } finally {
4296 Binder.restoreCallingIdentity(identity);
4297 }
4298 }
4299
shilu366312e2019-12-17 09:28:10 -08004300 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004301 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4302 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4303 * @param subId The subscription to use to check the configuration.
4304 */
4305 @Override
4306 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004307 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004308 mApp, subId, "isCrossSimCallingEnabledByUser");
4309 final long identity = Binder.clearCallingIdentity();
4310 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004311 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004312 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004313 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004314 } catch (ImsException e) {
4315 throw new ServiceSpecificException(e.getCode());
4316 } finally {
4317 Binder.restoreCallingIdentity(identity);
4318 }
4319 }
4320
4321 /**
4322 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4323 * Requires MODIFY_PHONE_STATE permission.
4324 * @param subId The subscription to use to check the configuration.
4325 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4326 * false otherwise
4327 */
4328 @Override
4329 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4331 "setCrossSimCallingEnabled");
4332 final long identity = Binder.clearCallingIdentity();
4333 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004334 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004335 // This setting doesn't require an active ImsService connection, so do not verify. The
4336 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004337 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004338 } catch (ImsException e) {
4339 throw new ServiceSpecificException(e.getCode());
4340 } finally {
4341 Binder.restoreCallingIdentity(identity);
4342 }
4343 }
4344
4345 /**
shilu366312e2019-12-17 09:28:10 -08004346 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4347 * @param subId The subscription to use to check the configuration.
4348 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004349 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004350
Brad Ebinger35c841c2018-10-01 10:40:55 -07004351 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004352 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004353 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 final long identity = Binder.clearCallingIdentity();
4355 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004356 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004357 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004358 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004359 } catch (ImsException e) {
4360 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004361 } finally {
4362 Binder.restoreCallingIdentity(identity);
4363 }
4364 }
4365
4366 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004367 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004369 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 final long identity = Binder.clearCallingIdentity();
4371 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004372 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004373 // This setting doesn't require an active ImsService connection, so do not verify. The
4374 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004375 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004376 } catch (ImsException e) {
4377 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 } finally {
4379 Binder.restoreCallingIdentity(identity);
4380 }
4381 }
4382
4383 @Override
4384 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4386 "setVoWiFiNonPersistent");
4387 final long identity = Binder.clearCallingIdentity();
4388 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004389 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004390 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004391 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004392 } catch (ImsException e) {
4393 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004394 } finally {
4395 Binder.restoreCallingIdentity(identity);
4396 }
4397 }
4398
shilu366312e2019-12-17 09:28:10 -08004399 /**
4400 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4401 * @param subId The subscription to use to check the configuration.
4402 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004403 @Override
4404 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004405 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004406 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004407 final long identity = Binder.clearCallingIdentity();
4408 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004409 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004410 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004411 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004412 } catch (ImsException e) {
4413 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004414 } finally {
4415 Binder.restoreCallingIdentity(identity);
4416 }
4417 }
4418
4419 @Override
4420 public void setVoWiFiModeSetting(int subId, int mode) {
4421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4422 "setVoWiFiModeSetting");
4423 final long identity = Binder.clearCallingIdentity();
4424 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004425 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004426 // This setting doesn't require an active ImsService connection, so do not verify. The
4427 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004428 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004429 } catch (ImsException e) {
4430 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004431 } finally {
4432 Binder.restoreCallingIdentity(identity);
4433 }
4434 }
4435
4436 @Override
4437 public int getVoWiFiRoamingModeSetting(int subId) {
4438 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4439 final long identity = Binder.clearCallingIdentity();
4440 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004441 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004442 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004443 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004444 } catch (ImsException e) {
4445 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004446 } finally {
4447 Binder.restoreCallingIdentity(identity);
4448 }
4449 }
4450
4451 @Override
4452 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4454 "setVoWiFiRoamingModeSetting");
4455 final long identity = Binder.clearCallingIdentity();
4456 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004457 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004458 // This setting doesn't require an active ImsService connection, so do not verify. The
4459 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004460 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004461 } catch (ImsException e) {
4462 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004463 } finally {
4464 Binder.restoreCallingIdentity(identity);
4465 }
4466 }
4467
4468 @Override
4469 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4471 "setRttCapabilityEnabled");
4472 final long identity = Binder.clearCallingIdentity();
4473 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004474 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004475 // This setting doesn't require an active ImsService connection, so do not verify. The
4476 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004477 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004478 } catch (ImsException e) {
4479 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004480 } finally {
4481 Binder.restoreCallingIdentity(identity);
4482 }
4483 }
4484
shilu366312e2019-12-17 09:28:10 -08004485 /**
4486 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4487 * @param subId The subscription to use to check the configuration.
4488 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004489 @Override
4490 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004491 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004492 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 final long identity = Binder.clearCallingIdentity();
4494 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004495 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004496 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004497 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004498 } catch (ImsException e) {
4499 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
4503 }
4504
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004505 @Override
4506 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4507 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4508 final long identity = Binder.clearCallingIdentity();
4509 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004510 if (!isImsAvailableOnDevice()) {
4511 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4512 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004513 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004514 int slotId = getSlotIndexOrException(subId);
4515 verifyImsMmTelConfiguredOrThrow(slotId);
4516 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004517 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004518 } catch (ImsException e) {
4519 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004520 } finally {
4521 Binder.restoreCallingIdentity(identity);
4522 }
4523 }
4524
4525 @Override
4526 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4527 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4528 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004529 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4530 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4531 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004532 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004533 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004534 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004535 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004536 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4537 + "is inactive, ignoring unregister.");
4538 // If the subscription is no longer active, just return, since the callback will already
4539 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004540 } finally {
4541 Binder.restoreCallingIdentity(identity);
4542 }
4543 }
4544
allenwtsu99c623b2020-01-03 18:24:23 +08004545
4546 private void checkModifyPhoneStatePermission(int subId, String message) {
4547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4548 message);
4549 }
4550
4551 private boolean isImsProvisioningRequired(int subId, int capability,
4552 boolean isMmtelCapability) {
4553 Phone phone = getPhone(subId);
4554 if (phone == null) {
4555 loge("phone instance null for subid " + subId);
4556 return false;
4557 }
4558 if (isMmtelCapability) {
4559 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4560 return false;
4561 }
4562 } else {
4563 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4564 return false;
4565 }
4566 }
4567 return true;
4568 }
4569
4570 @Override
4571 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4572 boolean isProvisioned) {
4573 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4574
4575 final long identity = Binder.clearCallingIdentity();
4576 try {
4577 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4578 if (!isImsProvisioningRequired(subId, capability, false)) {
4579 return;
4580 }
4581
4582 // this capability requires provisioning, route to the correct API.
4583 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4584 switch (capability) {
4585 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4586 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4587 ims.setEabProvisioned(isProvisioned);
4588 break;
4589 default: {
4590 throw new IllegalArgumentException("Tried to set provisioning for "
4591 + "rcs capability '" + capability + "', which does not require "
4592 + "provisioning.");
4593 }
4594 }
4595 } finally {
4596 Binder.restoreCallingIdentity(identity);
4597 }
4598
4599 }
4600
4601
4602 @Override
4603 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4604 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4605 final long identity = Binder.clearCallingIdentity();
4606 try {
4607 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4608 if (!isImsProvisioningRequired(subId, capability, false)) {
4609 return true;
4610 }
4611
4612 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4613 switch (capability) {
4614 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4615 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4616 return ims.isEabProvisionedOnDevice();
4617
4618 default: {
4619 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4620 + "capability '" + capability + "', which does not require "
4621 + "provisioning.");
4622 }
4623 }
4624
4625 } finally {
4626 Binder.restoreCallingIdentity(identity);
4627 }
4628 }
4629
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004630 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004631 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4632 boolean isProvisioned) {
4633 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004634 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4635 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4636 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004637 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4638 }
allenwtsu99c623b2020-01-03 18:24:23 +08004639 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004640 final long identity = Binder.clearCallingIdentity();
4641 try {
4642 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004643 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004644 return;
4645 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004646 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4647 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4648 loge("setImsProvisioningStatusForCapability: called for technology that does "
4649 + "not support provisioning - " + tech);
4650 return;
4651 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004652
4653 // this capability requires provisioning, route to the correct API.
4654 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4655 switch (capability) {
4656 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4657 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4658 ims.setVolteProvisioned(isProvisioned);
4659 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4660 ims.setWfcProvisioned(isProvisioned);
4661 }
4662 break;
4663 }
4664 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4665 // There is currently no difference in VT provisioning type.
4666 ims.setVtProvisioned(isProvisioned);
4667 break;
4668 }
4669 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4670 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4671 // change the capability of the feature instead if needed.
4672 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4673 == isProvisioned) {
4674 // No change in provisioning.
4675 return;
4676 }
4677 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4678 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004679 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004680 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004681 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4682 + ", Exception" + e.getMessage());
4683 }
4684 break;
4685 }
4686 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004687 throw new IllegalArgumentException("Tried to set provisioning for "
4688 + "MmTel capability '" + capability + "', which does not require "
4689 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004690 }
4691 }
4692
4693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
4696 }
4697
4698 @Override
4699 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4700 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004701 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4702 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4703 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004704 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4705 }
4706 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4707 final long identity = Binder.clearCallingIdentity();
4708 try {
4709 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004710 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004711 return true;
4712 }
4713
Brad Ebinger0d79c572021-04-17 15:20:49 -07004714 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4715 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4716 loge("getImsProvisioningStatusForCapability: called for technology that does "
4717 + "not support provisioning - " + tech);
4718 return true;
4719 }
4720
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004721 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4722 switch (capability) {
4723 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4724 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4725 return ims.isVolteProvisionedOnDevice();
4726 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4727 return ims.isWfcProvisionedOnDevice();
4728 }
4729 // This should never happen, since we are checking tech above to make sure it
4730 // is either LTE or IWLAN.
4731 throw new IllegalArgumentException("Invalid radio technology for voice "
4732 + "capability.");
4733 }
4734 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4735 // There is currently no difference in VT provisioning type.
4736 return ims.isVtProvisionedOnDevice();
4737 }
4738 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4739 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4740 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4741 }
4742 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004743 throw new IllegalArgumentException(
4744 "Tried to get provisioning for MmTel capability '" + capability
4745 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004746 }
4747 }
4748
4749 } finally {
4750 Binder.restoreCallingIdentity(identity);
4751 }
4752 }
4753
4754 @Override
4755 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4756 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4757 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4758 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4759 }
4760 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4761 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4762 return (provisionedBits & capability) > 0;
4763 }
4764
4765 @Override
4766 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4767 boolean isProvisioned) {
4768 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4769 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4770 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4771 }
4772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4773 "setProvisioningStatusForCapability");
4774 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4775 // If the current provisioning status for capability already matches isProvisioned,
4776 // do nothing.
4777 if (((provisionedBits & capability) > 0) == isProvisioned) {
4778 return;
4779 }
4780 if (isProvisioned) {
4781 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4782 } else {
4783 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4784 }
4785 }
4786
4787 /**
4788 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4789 * technology. The bitfield should mirror the bitfield defined by
4790 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4791 */
4792 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4793 String key = getMmTelProvisioningKey(subId, tech);
4794 // Default is no capabilities are provisioned.
4795 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4796 }
4797
4798 /**
4799 * Sets the MmTel capability provisioning bitfield (defined by
4800 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4801 * technology specified.
4802 *
4803 * Note: This is a synchronous command and should not be called on UI thread.
4804 */
4805 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4806 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4807 String key = getMmTelProvisioningKey(subId, tech);
4808 editor.putInt(key, newField);
4809 editor.commit();
4810 }
4811
4812 private static String getMmTelProvisioningKey(int subId, int tech) {
4813 // resulting key is provision_ims_mmtel_{subId}_{tech}
4814 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4815 }
4816
4817 /**
4818 * Query CarrierConfig to see if the specified capability requires provisioning for the
4819 * carrier associated with the subscription id.
4820 */
4821 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4822 int capability) {
4823 CarrierConfigManager configManager = new CarrierConfigManager(context);
4824 PersistableBundle c = configManager.getConfigForSubId(subId);
4825 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004826 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004827 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4828 false);
4829 boolean requireVoiceVtProvisioning = c.getBoolean(
4830 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4831
4832 // First check to make sure that the capability requires provisioning.
4833 switch (capability) {
4834 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4835 // intentional fallthrough
4836 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4837 if (requireVoiceVtProvisioning) {
4838 // Voice and Video requires provisioning
4839 return true;
4840 }
4841 break;
4842 }
4843 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4844 if (requireUtProvisioning) {
4845 // UT requires provisioning
4846 return true;
4847 }
4848 break;
4849 }
4850 }
4851 return false;
4852 }
4853
allenwtsu99c623b2020-01-03 18:24:23 +08004854 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4855 int capability) {
4856 CarrierConfigManager configManager = new CarrierConfigManager(context);
4857 PersistableBundle c = configManager.getConfigForSubId(subId);
4858
4859 boolean requireRcsProvisioning = c.getBoolean(
4860 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4861
4862 // First check to make sure that the capability requires provisioning.
4863 switch (capability) {
4864 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4865 // intentional fallthrough
4866 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4867 if (requireRcsProvisioning) {
4868 // OPTION or PRESENCE requires provisioning
4869 return true;
4870 }
4871 break;
4872 }
4873 }
4874 return false;
4875 }
4876
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004877 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004878 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004879 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4880 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4881 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004882 enforceReadPrivilegedPermission("getImsProvisioningInt");
4883 final long identity = Binder.clearCallingIdentity();
4884 try {
4885 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004886 int slotId = getSlotIndex(subId);
4887 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4888 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4889 + subId + "' for key:" + key);
4890 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4891 }
calvinpanb5a34062021-02-08 19:59:36 +08004892 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004893 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004894 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4895 + subId + "' for key:" + key);
4896 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004897 } finally {
4898 Binder.restoreCallingIdentity(identity);
4899 }
4900 }
4901
4902 @Override
4903 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004904 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4905 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4906 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004907 enforceReadPrivilegedPermission("getImsProvisioningString");
4908 final long identity = Binder.clearCallingIdentity();
4909 try {
4910 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004911 int slotId = getSlotIndex(subId);
4912 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4913 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4914 + subId + "' for key:" + key);
4915 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4916 }
calvinpanb5a34062021-02-08 19:59:36 +08004917 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004918 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004919 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4920 + subId + "' for key:" + key);
4921 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004922 } finally {
4923 Binder.restoreCallingIdentity(identity);
4924 }
4925 }
4926
4927 @Override
4928 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004929 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4930 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4931 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4933 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004934 final long identity = Binder.clearCallingIdentity();
4935 try {
4936 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004937 int slotId = getSlotIndex(subId);
4938 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4939 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4940 + subId + "' for key:" + key);
4941 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4942 }
calvinpanb5a34062021-02-08 19:59:36 +08004943 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4944 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004945 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004946 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004947 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004948 } finally {
4949 Binder.restoreCallingIdentity(identity);
4950 }
4951 }
4952
4953 @Override
4954 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004955 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4956 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4957 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4959 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004960 final long identity = Binder.clearCallingIdentity();
4961 try {
4962 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004963 int slotId = getSlotIndex(subId);
4964 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4965 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4966 + subId + "' for key:" + key);
4967 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4968 }
calvinpanb5a34062021-02-08 19:59:36 +08004969 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4970 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004971 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004972 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004973 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004974 } finally {
4975 Binder.restoreCallingIdentity(identity);
4976 }
4977 }
4978
Brad Ebinger919631e2021-06-02 17:46:35 -07004979 /**
4980 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4981 * for the given slot ID or no ImsResolver instance has been created.
4982 * @param slotId The slot ID that the IMS service is created for.
4983 * @throws ImsException If there is no ImsService configured for this slot.
4984 */
4985 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4986 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4987 ImsFeature.FEATURE_MMTEL)) {
4988 throw new ImsException("This subscription does not support MMTEL over IMS",
4989 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4990 }
4991 }
4992
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004993 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004994 int slotId = SubscriptionManager.getSlotIndex(subId);
4995 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004996 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4997 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004998 }
4999 return slotId;
5000 }
5001
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005002 private int getSlotIndex(int subId) {
5003 int slotId = SubscriptionManager.getSlotIndex(subId);
5004 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5005 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5006 }
5007 return slotId;
5008 }
5009
Wink Saville36469e72014-06-11 15:17:00 -07005010 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005011 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005012 */
5013 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005014 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5015 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005016 try {
5017 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5018 } catch (SecurityException se) {
5019 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5020 throw new SecurityException("Package " + callingPackage + " does not belong to "
5021 + Binder.getCallingUid());
5022 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005023 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005024 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005025 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005026 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005027 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005028 mApp, subId, callingPackage, callingFeatureId,
5029 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005030 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5031 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005033 final long identity = Binder.clearCallingIdentity();
5034 try {
5035 final Phone phone = getPhone(subId);
5036 if (phone != null) {
5037 return phone.getServiceState().getDataNetworkType();
5038 } else {
5039 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5040 }
5041 } finally {
5042 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005043 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005044 }
5045
5046 /**
5047 * Returns the data network type
5048 */
5049 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005050 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005051 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5052 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005053 }
5054
5055 /**
5056 * Returns the data network type for a subId
5057 */
5058 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005059 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5060 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005062 mApp, subId, callingPackage, callingFeatureId,
5063 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005064 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5065 }
5066
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067 final long identity = Binder.clearCallingIdentity();
5068 try {
5069 final Phone phone = getPhone(subId);
5070 if (phone != null) {
5071 return phone.getServiceState().getDataNetworkType();
5072 } else {
5073 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5074 }
5075 } finally {
5076 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005077 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005078 }
5079
5080 /**
Wink Saville36469e72014-06-11 15:17:00 -07005081 * Returns the Voice network type for a subId
5082 */
5083 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005084 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5085 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005086 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005087 mApp, subId, callingPackage, callingFeatureId,
5088 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005089 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5090 }
5091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005092 final long identity = Binder.clearCallingIdentity();
5093 try {
5094 final Phone phone = getPhone(subId);
5095 if (phone != null) {
5096 return phone.getServiceState().getVoiceNetworkType();
5097 } else {
5098 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5099 }
5100 } finally {
5101 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005102 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005103 }
5104
5105 /**
5106 * @return true if a ICC card is present
5107 */
5108 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005109 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005110 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5111 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005112 }
5113
5114 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005115 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005116 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005117 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005118 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119 final long identity = Binder.clearCallingIdentity();
5120 try {
5121 final Phone phone = PhoneFactory.getPhone(slotIndex);
5122 if (phone != null) {
5123 return phone.getIccCard().hasIccCard();
5124 } else {
5125 return false;
5126 }
5127 } finally {
5128 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005129 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005130 }
5131
5132 /**
5133 * Return if the current radio is LTE on CDMA. This
5134 * is a tri-state return value as for a period of time
5135 * the mode may be unknown.
5136 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005137 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005138 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005139 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005140 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005141 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005142 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5143 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5144 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005145 }
5146
Sanket Padawe356d7632015-06-22 14:03:32 -07005147 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005148 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5149 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005150 try {
5151 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5152 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005153 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5154 }
5155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156 final long identity = Binder.clearCallingIdentity();
5157 try {
5158 final Phone phone = getPhone(subId);
5159 if (phone == null) {
5160 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5161 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005162 return TelephonyProperties.lte_on_cdma_device()
5163 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164 }
5165 } finally {
5166 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005167 }
Wink Saville36469e72014-06-11 15:17:00 -07005168 }
5169
Wink Saville36469e72014-06-11 15:17:00 -07005170 /**
5171 * {@hide}
5172 * Returns Default subId, 0 in the case of single standby.
5173 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005174 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005175 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005176 }
5177
Shishir Agrawala9f32182016-04-12 12:00:16 -07005178 private int getSlotForDefaultSubscription() {
5179 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5180 }
5181
Wink Savilleb564aae2014-10-23 10:18:09 -07005182 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005183 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005184 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005185
Pengquan Menge92a50d2018-09-21 15:54:48 -07005186 private boolean isActiveSubscription(int subId) {
5187 return mSubscriptionController.isActiveSubId(subId);
5188 }
5189
Ihab Awadf2177b72013-11-25 13:33:23 -08005190 /**
5191 * @see android.telephony.TelephonyManager.WifiCallingChoices
5192 */
5193 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005194 final long identity = Binder.clearCallingIdentity();
5195 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005196 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005197 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5198 getWhenToMakeWifiCallsDefaultPreference());
5199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005202 }
5203
5204 /**
5205 * @see android.telephony.TelephonyManager.WifiCallingChoices
5206 */
5207 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 final long identity = Binder.clearCallingIdentity();
5209 try {
5210 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005211 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5213 } finally {
5214 Binder.restoreCallingIdentity(identity);
5215 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005216 }
5217
Sailesh Nepald1e68152013-12-12 19:08:02 -08005218 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005219 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005220 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005221 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005222
Jordan Liu4c733742019-02-28 12:03:40 -08005223 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5224 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5225 if (phoneId == -1) {
5226 throw new IllegalArgumentException("Given slot index: " + slotIndex
5227 + " does not correspond to an active phone");
5228 }
5229 return PhoneFactory.getPhone(phoneId);
5230 }
5231
Shishir Agrawal566b7612013-10-28 14:41:00 -07005232 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005233 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5234 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5236 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005238 if (DBG) {
5239 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5240 }
5241 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5242 p2);
5243 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005244
Jordan Liu4c733742019-02-28 12:03:40 -08005245
5246 @Override
5247 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5248 int slotIndex, String callingPackage, String aid, int p2) {
5249 enforceModifyPermission();
5250 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5251 if (DBG) {
5252 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5253 }
5254 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5255 callingPackage, aid, p2);
5256 }
5257
5258 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5259 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 final long identity = Binder.clearCallingIdentity();
5261 try {
5262 if (TextUtils.equals(ISDR_AID, aid)) {
5263 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005264 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5265 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005266 if (bestComponent == null
5267 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5268 loge("The calling package is not allowed to access ISD-R.");
5269 throw new SecurityException(
5270 "The calling package is not allowed to access ISD-R.");
5271 }
Derek Tan740e1672017-06-27 14:56:27 -07005272 }
Derek Tan740e1672017-06-27 14:56:27 -07005273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005275 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5276 null /* workSource */);
5277 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278 return response;
5279 } finally {
5280 Binder.restoreCallingIdentity(identity);
5281 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005282 }
5283
5284 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005285 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5287 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005288 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5289 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5290 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005291
Jordan Liu4c733742019-02-28 12:03:40 -08005292 @Override
5293 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5294 enforceModifyPermission();
5295 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5296 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5297 channel);
5298 }
5299
5300 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 final long identity = Binder.clearCallingIdentity();
5302 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005303 if (channel < 0) {
5304 return false;
5305 }
Jordan Liu4c733742019-02-28 12:03:40 -08005306 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5307 null /* workSource */);
5308 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 return success;
5310 } finally {
5311 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005312 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005313 }
5314
5315 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005316 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005317 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5319 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005320 if (DBG) {
5321 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5322 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5323 + p3 + " data=" + data);
5324 }
5325 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5326 command, p1, p2, p3, data);
5327 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005328
Jordan Liu4c733742019-02-28 12:03:40 -08005329 @Override
5330 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5331 int command, int p1, int p2, int p3, String data) {
5332 enforceModifyPermission();
5333 if (DBG) {
5334 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5335 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5336 + p3 + " data=" + data);
5337 }
5338 return iccTransmitApduLogicalChannelWithPermission(
5339 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5340 data);
5341 }
5342
5343 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5344 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345 final long identity = Binder.clearCallingIdentity();
5346 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005347 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 return "";
5349 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005352 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5353 null /* workSource */);
5354 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 // Append the returned status code to the end of the response payload.
5357 String s = Integer.toHexString(
5358 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5359 if (response.payload != null) {
5360 s = IccUtils.bytesToHexString(response.payload) + s;
5361 }
5362 return s;
5363 } finally {
5364 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005365 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005366 }
Jake Hambye994d462014-02-03 13:10:13 -08005367
Evan Charltonc66da362014-05-16 14:06:40 -07005368 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005369 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5370 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5372 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005374 if (DBG) {
5375 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5376 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5377 }
5378 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5379 cla, command, p1, p2, p3, data);
5380 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005381
Jordan Liu4c733742019-02-28 12:03:40 -08005382 @Override
5383 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5384 int command, int p1, int p2, int p3, String data) {
5385 enforceModifyPermission();
5386 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5387 if (DBG) {
5388 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5389 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5390 + " data=" + data);
5391 }
5392
5393 return iccTransmitApduBasicChannelWithPermission(
5394 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5395 p2, p3, data);
5396 }
5397
5398 // open APDU basic channel assuming the caller has sufficient permissions
5399 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5400 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401 final long identity = Binder.clearCallingIdentity();
5402 try {
5403 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5404 && TextUtils.equals(ISDR_AID, data)) {
5405 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005406 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5407 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 if (bestComponent == null
5409 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5410 loge("The calling package is not allowed to select ISD-R.");
5411 throw new SecurityException(
5412 "The calling package is not allowed to select ISD-R.");
5413 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005414 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005416 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005417 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5418 null /* workSource */);
5419 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005420
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 // Append the returned status code to the end of the response payload.
5422 String s = Integer.toHexString(
5423 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5424 if (response.payload != null) {
5425 s = IccUtils.bytesToHexString(response.payload) + s;
5426 }
5427 return s;
5428 } finally {
5429 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005430 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005431 }
5432
5433 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005434 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005435 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5437 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439 final long identity = Binder.clearCallingIdentity();
5440 try {
5441 if (DBG) {
5442 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5443 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5444 }
5445
5446 IccIoResult response =
5447 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5448 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5449 subId);
5450
5451 if (DBG) {
5452 log("Exchange SIM_IO [R]" + response);
5453 }
5454
5455 byte[] result = null;
5456 int length = 2;
5457 if (response.payload != null) {
5458 length = 2 + response.payload.length;
5459 result = new byte[length];
5460 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5461 } else {
5462 result = new byte[length];
5463 }
5464
5465 result[length - 1] = (byte) response.sw2;
5466 result[length - 2] = (byte) response.sw1;
5467 return result;
5468 } finally {
5469 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005470 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005471 }
5472
Nathan Haroldb3014052017-01-25 15:57:32 -08005473 /**
5474 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5475 * on a particular subscription
5476 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005477 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5478 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005479 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005480 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005481 return null;
5482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483
5484 final long identity = Binder.clearCallingIdentity();
5485 try {
5486 if (appType != TelephonyManager.APPTYPE_USIM
5487 && appType != TelephonyManager.APPTYPE_SIM) {
5488 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5489 return null;
5490 }
5491 Object response = sendRequest(
5492 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5493 if (response instanceof String[]) {
5494 return (String[]) response;
5495 }
yincheng zhao2737e882019-09-06 17:06:54 -07005496 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005497 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005498 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499 } finally {
5500 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005501 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005502 }
5503
yincheng zhao2737e882019-09-06 17:06:54 -07005504 /**
5505 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5506 * subscription.
5507 *
5508 * @param subId the id of the subscription.
5509 * @param appType the uicc app type, must be USIM or SIM.
5510 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5511 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005512 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005513 * @return number of fplmns that is successfully written to the SIM.
5514 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005515 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5516 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005517 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5518 mApp, subId, "setForbiddenPlmns");
5519
yincheng zhao2737e882019-09-06 17:06:54 -07005520 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5521 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5522 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5523 }
5524 if (fplmns == null) {
5525 throw new IllegalArgumentException("Fplmn List provided is null");
5526 }
5527 for (String fplmn : fplmns) {
5528 if (!CellIdentity.isValidPlmn(fplmn)) {
5529 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5530 }
5531 }
5532 final long identity = Binder.clearCallingIdentity();
5533 try {
5534 Object response = sendRequest(
5535 CMD_SET_FORBIDDEN_PLMNS,
5536 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5537 subId);
5538 return (int) response;
5539 } finally {
5540 Binder.restoreCallingIdentity(identity);
5541 }
5542 }
5543
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005544 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005545 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5547 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005549 final long identity = Binder.clearCallingIdentity();
5550 try {
5551 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5552 if (response.payload == null) {
5553 return "";
5554 }
Evan Charltonc66da362014-05-16 14:06:40 -07005555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556 // Append the returned status code to the end of the response payload.
5557 String s = Integer.toHexString(
5558 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5559 s = IccUtils.bytesToHexString(response.payload) + s;
5560 return s;
5561 } finally {
5562 Binder.restoreCallingIdentity(identity);
5563 }
Evan Charltonc66da362014-05-16 14:06:40 -07005564 }
5565
Jake Hambye994d462014-02-03 13:10:13 -08005566 /**
5567 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5568 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5569 *
5570 * @param itemID the ID of the item to read
5571 * @return the NV item as a String, or null on error.
5572 */
5573 @Override
5574 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005575 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5577 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578
5579 final long identity = Binder.clearCallingIdentity();
5580 try {
5581 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005582 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5584 return value;
5585 } finally {
5586 Binder.restoreCallingIdentity(identity);
5587 }
Jake Hambye994d462014-02-03 13:10:13 -08005588 }
5589
5590 /**
5591 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5592 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5593 *
5594 * @param itemID the ID of the item to read
5595 * @param itemValue the value to write, as a String
5596 * @return true on success; false on any failure
5597 */
5598 @Override
5599 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005600 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5602 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603
5604 final long identity = Binder.clearCallingIdentity();
5605 try {
5606 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5607 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005608 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5610 return success;
5611 } finally {
5612 Binder.restoreCallingIdentity(identity);
5613 }
Jake Hambye994d462014-02-03 13:10:13 -08005614 }
5615
5616 /**
5617 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5618 * Used for device configuration by some CDMA operators.
5619 *
5620 * @param preferredRoamingList byte array containing the new PRL
5621 * @return true on success; false on any failure
5622 */
5623 @Override
5624 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5626 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627
5628 final long identity = Binder.clearCallingIdentity();
5629 try {
5630 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5631 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5632 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5633 return success;
5634 } finally {
5635 Binder.restoreCallingIdentity(identity);
5636 }
Jake Hambye994d462014-02-03 13:10:13 -08005637 }
5638
5639 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005640 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005641 * Used for device configuration by some CDMA operators.
5642 *
chen xu6dac5ab2018-10-26 17:39:23 -07005643 * @param slotIndex - device slot.
5644 *
Jake Hambye994d462014-02-03 13:10:13 -08005645 * @return true on success; false on any failure
5646 */
5647 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005648 public boolean resetModemConfig(int slotIndex) {
5649 Phone phone = PhoneFactory.getPhone(slotIndex);
5650 if (phone != null) {
5651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5652 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653
chen xu6dac5ab2018-10-26 17:39:23 -07005654 final long identity = Binder.clearCallingIdentity();
5655 try {
5656 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5657 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5658 return success;
5659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662 }
chen xu6dac5ab2018-10-26 17:39:23 -07005663 return false;
5664 }
5665
5666 /**
5667 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5668 *
5669 * @param slotIndex - device slot.
5670 *
5671 * @return true on success; false on any failure
5672 */
5673 @Override
5674 public boolean rebootModem(int slotIndex) {
5675 Phone phone = PhoneFactory.getPhone(slotIndex);
5676 if (phone != null) {
5677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5678 mApp, phone.getSubId(), "rebootModem");
5679
5680 final long identity = Binder.clearCallingIdentity();
5681 try {
5682 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5683 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5684 return success;
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
5688 }
5689 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005690 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005691
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005692 public String[] getPcscfAddress(String apnType, String callingPackage,
5693 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005694 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5696 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005697 return new String[0];
5698 }
5699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 final long identity = Binder.clearCallingIdentity();
5701 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005702 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 } finally {
5704 Binder.restoreCallingIdentity(identity);
5705 }
Wink Saville36469e72014-06-11 15:17:00 -07005706 }
5707
Brad Ebinger51f743a2017-01-23 13:50:20 -08005708 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005709 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5710 * {@link #disableIms(int)}.
5711 * @param slotIndex device slot.
5712 */
5713 public void resetIms(int slotIndex) {
5714 enforceModifyPermission();
5715
5716 final long identity = Binder.clearCallingIdentity();
5717 try {
5718 if (mImsResolver == null) {
5719 // may happen if the does not support IMS.
5720 return;
5721 }
5722 mImsResolver.disableIms(slotIndex);
5723 mImsResolver.enableIms(slotIndex);
5724 } finally {
5725 Binder.restoreCallingIdentity(identity);
5726 }
5727 }
5728
5729 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005730 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5731 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005732 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005733 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005734 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735
5736 final long identity = Binder.clearCallingIdentity();
5737 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005738 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005739 // may happen if the device does not support IMS.
5740 return;
5741 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005742 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743 } finally {
5744 Binder.restoreCallingIdentity(identity);
5745 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005746 }
5747
5748 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005749 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5750 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005751 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005752 public void disableIms(int slotId) {
5753 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754
5755 final long identity = Binder.clearCallingIdentity();
5756 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005757 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005758 // may happen if the device does not support IMS.
5759 return;
5760 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005761 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 } finally {
5763 Binder.restoreCallingIdentity(identity);
5764 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005765 }
5766
5767 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005768 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5769 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005770 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005771 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005772 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005773 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774
5775 final long identity = Binder.clearCallingIdentity();
5776 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005777 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005778 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5779 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005780 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005781 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005785 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005786 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005787 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5788 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005789 @Override
5790 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005791 enforceModifyPermission();
5792
5793 final long identity = Binder.clearCallingIdentity();
5794 try {
5795 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005796 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005797 } finally {
5798 Binder.restoreCallingIdentity(identity);
5799 }
5800 }
5801
5802 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005803 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005804 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005805 */
5806 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5807 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808
5809 final long identity = Binder.clearCallingIdentity();
5810 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005811 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005812 // may happen if the device does not support IMS.
5813 return null;
5814 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005815 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816 } finally {
5817 Binder.restoreCallingIdentity(identity);
5818 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005819 }
5820
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005821 /**
5822 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005823 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005824 */
5825 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5826 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827
5828 final long identity = Binder.clearCallingIdentity();
5829 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005830 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005831 // may happen if the device does not support IMS.
5832 return null;
5833 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005834 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005835 } finally {
5836 Binder.restoreCallingIdentity(identity);
5837 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005838 }
5839
Brad Ebinger884c07b2018-02-15 16:17:40 -08005840 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005841 * Sets the ImsService Package Name that Telephony will bind to.
5842 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005843 * @param slotIndex the slot ID that the ImsService should bind for.
5844 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005845 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005846 * @param featureTypes An integer array of feature types associated with a packageName.
5847 * @param packageName The name of the package that the current configuration will be replaced
5848 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005849 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005850 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005851 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5852 int[] featureTypes, String packageName) {
5853 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5854 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5856 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005857 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005858
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859 final long identity = Binder.clearCallingIdentity();
5860 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005861 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005862 // may happen if the device does not support IMS.
5863 return false;
5864 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005865 Map<Integer, String> featureConfig = new HashMap<>();
5866 for (int featureType : featureTypes) {
5867 featureConfig.put(featureType, packageName);
5868 }
5869 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5870 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005871 } finally {
5872 Binder.restoreCallingIdentity(identity);
5873 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005874 }
5875
5876 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005877 * Clears any carrier ImsService overrides for the slot index specified that were previously
5878 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5879 *
5880 * This should only be used for testing.
5881 *
5882 * @param slotIndex the slot ID that the ImsService should bind for.
5883 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5884 */
5885 @Override
5886 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5887 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5888 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5889 "clearCarrierImsServiceOverride");
5890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5891 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5892 "clearCarrierImsServiceOverride");
5893
5894 final long identity = Binder.clearCallingIdentity();
5895 try {
5896 if (mImsResolver == null) {
5897 // may happen if the device does not support IMS.
5898 return false;
5899 }
5900 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5901 } finally {
5902 Binder.restoreCallingIdentity(identity);
5903 }
5904 }
5905
5906 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005907 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005908 *
5909 * @param slotId The slot that the ImsService is associated with.
5910 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5911 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005912 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005913 * @return the package name of the ImsService configuration.
5914 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005915 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5916 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005917 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005918 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005919 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005920 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5921 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005923 final long identity = Binder.clearCallingIdentity();
5924 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005925 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005926 // may happen if the device does not support IMS.
5927 return "";
5928 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005929 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005930 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5931 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932 } finally {
5933 Binder.restoreCallingIdentity(identity);
5934 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005935 }
5936
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005937 /**
5938 * Get the MmTelFeature state associated with the requested subscription id.
5939 * @param subId The subscription that the MmTelFeature is associated with.
5940 * @param callback A callback with an integer containing the
5941 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5942 */
5943 @Override
5944 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5945 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5946 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5947 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5948 "IMS not available on device.");
5949 }
5950 final long token = Binder.clearCallingIdentity();
5951 try {
5952 int slotId = getSlotIndex(subId);
5953 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5954 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5955 + subId + "'");
5956 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5957 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005958 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005959 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5960 try {
5961 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5962 } catch (RemoteException e) {
5963 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5964 + "Ignore");
5965 }
5966 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005967 } catch (ImsException e) {
5968 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005969 } finally {
5970 Binder.restoreCallingIdentity(token);
5971 }
5972 }
5973
Daniel Brightbb5840b2021-01-12 15:48:18 -08005974 /**
5975 * Sets the ims registration state on all valid {@link Phone}s.
5976 */
5977 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005978 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979
5980 final long identity = Binder.clearCallingIdentity();
5981 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005982 // NOTE: Before S, this method only set the default phone.
5983 for (final Phone phone : PhoneFactory.getPhones()) {
5984 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5985 phone.setImsRegistrationState(registered);
5986 }
5987 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 } finally {
5989 Binder.restoreCallingIdentity(identity);
5990 }
Wink Saville36469e72014-06-11 15:17:00 -07005991 }
5992
5993 /**
Stuart Scott54788802015-03-30 13:18:01 -07005994 * Set the network selection mode to automatic.
5995 *
5996 */
5997 @Override
5998 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6000 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001
6002 final long identity = Binder.clearCallingIdentity();
6003 try {
shilufc958392020-01-20 11:36:01 -08006004 if (!isActiveSubscription(subId)) {
6005 return;
6006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006008 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6009 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010 } finally {
6011 Binder.restoreCallingIdentity(identity);
6012 }
Stuart Scott54788802015-03-30 13:18:01 -07006013 }
6014
Jack Yud10cdd42020-09-28 20:28:01 -07006015 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006016 * Ask the radio to connect to the input network and change selection mode to manual.
6017 *
6018 * @param subId the id of the subscription.
6019 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6020 * the operator to attach to.
6021 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6022 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6023 * normal network selection next time.
6024 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006025 */
6026 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006027 public boolean setNetworkSelectionModeManual(
6028 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6030 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006031
6032 if (!isActiveSubscription(subId)) {
6033 return false;
6034 }
6035
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 final long identity = Binder.clearCallingIdentity();
6037 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006038 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006040 if (DBG) {
6041 log("setNetworkSelectionModeManual: subId: " + subId
6042 + " operator: " + operatorInfo);
6043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6045 } finally {
6046 Binder.restoreCallingIdentity(identity);
6047 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006048 }
shilu84f6e8b2019-12-19 13:58:01 -08006049 /**
6050 * Get the manual network selection
6051 *
6052 * @param subId the id of the subscription.
6053 *
6054 * @return the previously saved user selected PLMN
6055 */
6056 @Override
6057 public String getManualNetworkSelectionPlmn(int subId) {
6058 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006059 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006060 mApp, subId, "getManualNetworkSelectionPlmn");
6061
6062 final long identity = Binder.clearCallingIdentity();
6063 try {
6064 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006065 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006066 }
6067
6068 final Phone phone = getPhone(subId);
6069 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006070 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006071 }
6072 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6073 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6074 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6075 } finally {
6076 Binder.restoreCallingIdentity(identity);
6077 }
6078 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006079
6080 /**
6081 * Scans for available networks.
6082 */
6083 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006084 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6085 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6087 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006088 LocationAccessPolicy.LocationPermissionResult locationResult =
6089 LocationAccessPolicy.checkLocationPermission(mApp,
6090 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6091 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006092 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006093 .setCallingPid(Binder.getCallingPid())
6094 .setCallingUid(Binder.getCallingUid())
6095 .setMethod("getCellNetworkScanResults")
6096 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006097 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6098 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006099 .build());
6100 switch (locationResult) {
6101 case DENIED_HARD:
6102 throw new SecurityException("Not allowed to access scan results -- location");
6103 case DENIED_SOFT:
6104 return null;
6105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106
Pengquan Menga1bb6272018-09-06 09:59:22 -07006107 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108 try {
6109 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006110 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 } finally {
6113 Binder.restoreCallingIdentity(identity);
6114 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006115 }
6116
6117 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006118 * Get the call forwarding info, given the call forwarding reason.
6119 */
6120 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006121 public void getCallForwarding(int subId, int callForwardingReason,
6122 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006123 enforceReadPrivilegedPermission("getCallForwarding");
6124 long identity = Binder.clearCallingIdentity();
6125 try {
6126 if (DBG) {
6127 log("getCallForwarding: subId " + subId
6128 + " callForwardingReason" + callForwardingReason);
6129 }
Hall Liu27d24262020-09-18 19:04:59 -07006130
6131 Phone phone = getPhone(subId);
6132 if (phone == null) {
6133 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006134 callback.onError(
6135 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006136 } catch (RemoteException e) {
6137 // ignore
6138 }
6139 return;
6140 }
6141
6142 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6143 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6144 @Override
6145 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6146 try {
6147 callback.onCallForwardingInfoAvailable(info);
6148 } catch (RemoteException e) {
6149 // ignore
6150 }
6151 }
6152
6153 @Override
6154 public void onError(int error) {
6155 try {
6156 callback.onError(error);
6157 } catch (RemoteException e) {
6158 // ignore
6159 }
6160 }
6161 });
6162 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006163 } finally {
6164 Binder.restoreCallingIdentity(identity);
6165 }
6166 }
6167
6168 /**
6169 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6170 * reason, the number to forward, and the timeout before the forwarding is attempted.
6171 */
6172 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006173 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6174 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006175 enforceModifyPermission();
6176 long identity = Binder.clearCallingIdentity();
6177 try {
6178 if (DBG) {
6179 log("setCallForwarding: subId " + subId
6180 + " callForwardingInfo" + callForwardingInfo);
6181 }
Hall Liu27d24262020-09-18 19:04:59 -07006182
6183 Phone phone = getPhone(subId);
6184 if (phone == null) {
6185 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006186 callback.accept(
6187 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006188 } catch (RemoteException e) {
6189 // ignore
6190 }
6191 return;
6192 }
6193
6194 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6195 FunctionalUtils.ignoreRemoteException(callback::accept));
6196
6197 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006198 } finally {
6199 Binder.restoreCallingIdentity(identity);
6200 }
6201 }
6202
6203 /**
Hall Liu27d24262020-09-18 19:04:59 -07006204 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006205 */
6206 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006207 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006208 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006209 long identity = Binder.clearCallingIdentity();
6210 try {
Hall Liu27d24262020-09-18 19:04:59 -07006211 Phone phone = getPhone(subId);
6212 if (phone == null) {
6213 try {
6214 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6215 } catch (RemoteException e) {
6216 // ignore
6217 }
6218 return;
6219 }
SongFerngWang0e767992021-03-31 22:08:45 +08006220 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6221 PersistableBundle c = configManager.getConfigForSubId(subId);
6222 boolean requireUssd = c.getBoolean(
6223 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006224
Shuo Qian4a594052020-01-23 11:59:30 -08006225 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006226 if (requireUssd) {
6227 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6228 getSubscriptionCarrierId(subId));
6229 String newUssdCommand = "";
6230 try {
6231 newUssdCommand = carrierXmlParser.getFeature(
6232 CarrierXmlParser.FEATURE_CALL_WAITING)
6233 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6234 } catch (NullPointerException e) {
6235 loge("Failed to generate USSD number" + e);
6236 }
6237 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6238 mMainThreadHandler, callback, carrierXmlParser,
6239 CarrierXmlParser.SsEntry.SSAction.QUERY);
6240 final String ussdCommand = newUssdCommand;
6241 Executors.newSingleThreadExecutor().execute(() -> {
6242 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6243 });
6244 } else {
6245 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6246 callback::accept);
6247 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6248 }
Shuo Qian4a594052020-01-23 11:59:30 -08006249 } finally {
6250 Binder.restoreCallingIdentity(identity);
6251 }
6252 }
6253
6254 /**
Hall Liu27d24262020-09-18 19:04:59 -07006255 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006256 */
6257 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006258 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006259 enforceModifyPermission();
6260 long identity = Binder.clearCallingIdentity();
6261 try {
Hall Liu27d24262020-09-18 19:04:59 -07006262 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6263
6264 Phone phone = getPhone(subId);
6265 if (phone == null) {
6266 try {
6267 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6268 } catch (RemoteException e) {
6269 // ignore
6270 }
6271 return;
6272 }
6273
SongFerngWang0e767992021-03-31 22:08:45 +08006274 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6275 PersistableBundle c = configManager.getConfigForSubId(subId);
6276 boolean requireUssd = c.getBoolean(
6277 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006278
SongFerngWang0e767992021-03-31 22:08:45 +08006279 if (DBG) log("getCallWaitingStatus: subId " + subId);
6280 if (requireUssd) {
6281 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6282 getSubscriptionCarrierId(subId));
6283 CarrierXmlParser.SsEntry.SSAction ssAction =
6284 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6285 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6286 String newUssdCommand = "";
6287 try {
6288 newUssdCommand = carrierXmlParser.getFeature(
6289 CarrierXmlParser.FEATURE_CALL_WAITING)
6290 .makeCommand(ssAction, null);
6291 } catch (NullPointerException e) {
6292 loge("Failed to generate USSD number" + e);
6293 }
6294 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6295 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6296 final String ussdCommand = newUssdCommand;
6297 Executors.newSingleThreadExecutor().execute(() -> {
6298 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6299 });
6300 } else {
6301 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6302 FunctionalUtils.ignoreRemoteException(callback::accept));
6303
6304 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6305 }
Shuo Qian4a594052020-01-23 11:59:30 -08006306 } finally {
6307 Binder.restoreCallingIdentity(identity);
6308 }
6309 }
6310
6311 /**
yinxub1bed742017-04-17 11:45:04 -07006312 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006313 *
yinxub1bed742017-04-17 11:45:04 -07006314 * @param subId id of the subscription
6315 * @param request contains the radio access networks with bands/channels to scan
6316 * @param messenger callback messenger for scan results or errors
6317 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006318 * @return the id of the requested scan which can be used to stop the scan.
6319 */
6320 @Override
6321 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006322 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6324 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006325 LocationAccessPolicy.LocationPermissionResult locationResult =
6326 LocationAccessPolicy.checkLocationPermission(mApp,
6327 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6328 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006329 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006330 .setCallingPid(Binder.getCallingPid())
6331 .setCallingUid(Binder.getCallingUid())
6332 .setMethod("requestNetworkScan")
6333 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006334 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6335 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006336 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006337 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006338 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6339 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006340 if (e != null) {
6341 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6342 throw e;
6343 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006344 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006345 return TelephonyScanManager.INVALID_SCAN_ID;
6346 }
6347 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006348 }
Hall Liu912dfd32019-04-25 14:02:26 -07006349 int callingUid = Binder.getCallingUid();
6350 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006351 final long identity = Binder.clearCallingIdentity();
6352 try {
6353 return mNetworkScanRequestTracker.startNetworkScan(
6354 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006355 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006356 } finally {
6357 Binder.restoreCallingIdentity(identity);
6358 }
yinxu504e1392017-04-12 16:03:22 -07006359 }
6360
Hall Liub2ac8ef2019-02-28 15:56:23 -08006361 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006362 NetworkScanRequest request, int subId, String callingPackage) {
6363 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006364 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6365 boolean hasNetworkScanPermission =
6366 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6367 == PERMISSION_GRANTED;
6368
6369 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6370 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6371 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006372 }
6373
6374 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6375 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006376 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6377 return new SecurityException("Specific channels must not be"
6378 + " scanned without location access.");
6379 }
6380 }
6381 }
6382
Hall Liub2ac8ef2019-02-28 15:56:23 -08006383 return null;
6384 }
6385
yinxu504e1392017-04-12 16:03:22 -07006386 /**
6387 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006388 *
6389 * @param subId id of the subscription
6390 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006391 */
6392 @Override
6393 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6395 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006396
Hall Liu912dfd32019-04-25 14:02:26 -07006397 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006398 final long identity = Binder.clearCallingIdentity();
6399 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006400 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 } finally {
6402 Binder.restoreCallingIdentity(identity);
6403 }
yinxu504e1392017-04-12 16:03:22 -07006404 }
6405
6406 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006407 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006408 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006409 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006410 */
6411 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006412 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006413 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006414 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006415 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006416
6417 final long identity = Binder.clearCallingIdentity();
6418 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006419 if (DBG) log("getAllowedNetworkTypesBitmask");
6420 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6421 int networkTypesBitmask = (result != null ? result[0] : -1);
6422 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6423 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424 } finally {
6425 Binder.restoreCallingIdentity(identity);
6426 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006427 }
6428
6429 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006430 * Get the allowed network types for certain reason.
6431 *
6432 * @param subId the id of the subscription.
6433 * @param reason the reason the allowed network type change is taking place
6434 * @return the allowed network types.
6435 */
6436 @Override
6437 public long getAllowedNetworkTypesForReason(int subId,
6438 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006439 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006440 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006441 final long identity = Binder.clearCallingIdentity();
6442 try {
6443 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6444 } finally {
6445 Binder.restoreCallingIdentity(identity);
6446 }
6447 }
6448
6449 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006450 * Enable/Disable E-UTRA-NR Dual Connectivity
6451 * @param subId subscription id of the sim card
6452 * @param nrDualConnectivityState expected NR dual connectivity state
6453 * This can be passed following states
6454 * <ol>
6455 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6456 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6457 * <li>Disable NR dual connectivity and force secondary cell to be released
6458 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6459 * </ol>
6460 * @return operation result.
6461 */
6462 @Override
6463 public int setNrDualConnectivityState(int subId,
6464 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6466 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006467 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006468 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6469 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6470 }
6471
Sooraj Sasindran37444802020-08-11 10:40:43 -07006472 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6473 final long identity = Binder.clearCallingIdentity();
6474 try {
6475 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6476 nrDualConnectivityState, subId,
6477 workSource);
6478 if (DBG) log("enableNRDualConnectivity result: " + result);
6479 return result;
6480 } finally {
6481 Binder.restoreCallingIdentity(identity);
6482 }
6483 }
6484
6485 /**
6486 * Is E-UTRA-NR Dual Connectivity enabled
6487 * @return true if dual connectivity is enabled else false
6488 */
6489 @Override
6490 public boolean isNrDualConnectivityEnabled(int subId) {
6491 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006492 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006493 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006494 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006495 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6496 return false;
6497 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006498 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6499 final long identity = Binder.clearCallingIdentity();
6500 try {
6501 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6502 null, subId, workSource);
6503 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6504 return isEnabled;
6505 } finally {
6506 Binder.restoreCallingIdentity(identity);
6507 }
6508 }
6509
6510 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006511 * Set the allowed network types of the device and
6512 * provide the reason triggering the allowed network change.
6513 *
6514 * @param subId the id of the subscription.
6515 * @param reason the reason the allowed network type change is taking place
6516 * @param allowedNetworkTypes the allowed network types.
6517 * @return true on success; false on any failure.
6518 */
6519 @Override
6520 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006521 @TelephonyManager.AllowedNetworkTypesReason int reason,
6522 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6524 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006525 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006526 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6527 return false;
6528 }
6529 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6530 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006531 return false;
6532 }
6533
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006534 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6535 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6536
6537
6538 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6539 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6540 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006541 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006542
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006543 final long identity = Binder.clearCallingIdentity();
6544 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006545 Boolean success = (Boolean) sendRequest(
6546 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6547 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6548
6549 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6550 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006551 } finally {
6552 Binder.restoreCallingIdentity(identity);
6553 }
6554 }
6555
6556 /**
Miaoa84611c2019-03-15 09:21:10 +08006557 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006558 *
Miaoa84611c2019-03-15 09:21:10 +08006559 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006560 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006561 * @hide
6562 */
6563 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006564 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006565 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006566 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006567 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 try {
Miaoa84611c2019-03-15 09:21:10 +08006569 if (phone != null) {
6570 return phone.hasMatchedTetherApnSetting();
6571 } else {
6572 return false;
6573 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574 } finally {
6575 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006576 }
Junda Liu475951f2014-11-07 16:45:03 -08006577 }
6578
6579 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006580 * Enable or disable always reporting signal strength changes from radio.
6581 *
6582 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6583 */
6584 @Override
6585 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6586 enforceModifyPermission();
6587 enforceSystemCaller();
6588
6589 final long identity = Binder.clearCallingIdentity();
6590 final Phone phone = getPhone(subId);
6591 try {
6592 if (phone != null) {
6593 if (DBG) {
6594 log("setAlwaysReportSignalStrength: subId=" + subId
6595 + " isEnable=" + isEnable);
6596 }
6597 phone.setAlwaysReportSignalStrength(isEnable);
6598 } else {
6599 loge("setAlwaysReportSignalStrength: no phone found for subId="
6600 + subId);
6601 }
6602 } finally {
6603 Binder.restoreCallingIdentity(identity);
6604 }
6605 }
6606
6607 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006608 * Get the user enabled state of Mobile Data.
6609 *
6610 * TODO: remove and use isUserDataEnabled.
6611 * This can't be removed now because some vendor codes
6612 * calls through ITelephony directly while they should
6613 * use TelephonyManager.
6614 *
6615 * @return true on enabled
6616 */
6617 @Override
6618 public boolean getDataEnabled(int subId) {
6619 return isUserDataEnabled(subId);
6620 }
6621
6622 /**
6623 * Get whether mobile data is enabled per user setting.
6624 *
6625 * There are other factors deciding whether mobile data is actually enabled, but they are
6626 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006627 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006628 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006629 *
6630 * @return {@code true} if data is enabled else {@code false}
6631 */
6632 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006633 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006634 try {
6635 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6636 null);
6637 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6639 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006640 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006641
6642 final long identity = Binder.clearCallingIdentity();
6643 try {
6644 int phoneId = mSubscriptionController.getPhoneId(subId);
6645 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6646 Phone phone = PhoneFactory.getPhone(phoneId);
6647 if (phone != null) {
6648 boolean retVal = phone.isUserDataEnabled();
6649 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6650 return retVal;
6651 } else {
6652 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6653 return false;
6654 }
6655 } finally {
6656 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006657 }
6658 }
6659
6660 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006661 * Checks if the device is capable of mobile data by considering whether whether the
6662 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6663 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006664 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006665 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006666 */
6667 @Override
6668 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006669 try {
6670 try {
6671 mApp.enforceCallingOrSelfPermission(
6672 android.Manifest.permission.ACCESS_NETWORK_STATE,
6673 null);
6674 } catch (Exception e) {
6675 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6676 "isDataEnabled");
6677 }
6678 } catch (Exception e) {
6679 enforceReadPrivilegedPermission("isDataEnabled");
6680 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006681
6682 final long identity = Binder.clearCallingIdentity();
6683 try {
6684 int phoneId = mSubscriptionController.getPhoneId(subId);
6685 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6686 Phone phone = PhoneFactory.getPhone(phoneId);
6687 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006688 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006689 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6690 return retVal;
6691 } else {
6692 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6693 return false;
6694 }
6695 } finally {
6696 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006697 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006698 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006699
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006700 /**
6701 * Check if data is enabled for a specific reason
6702 * @param subId Subscription index
6703 * @param reason the reason the data enable change is taking place
6704 * @return {@code true} if the overall data is enabled; {@code false} if not.
6705 */
6706 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006707 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006708 @TelephonyManager.DataEnabledReason int reason) {
6709 try {
6710 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6711 null);
6712 } catch (Exception e) {
6713 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006714 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006715 }
6716
6717
6718 final long identity = Binder.clearCallingIdentity();
6719 try {
6720 int phoneId = mSubscriptionController.getPhoneId(subId);
6721 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006722 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006723 + " reason=" + reason);
6724 }
6725 Phone phone = PhoneFactory.getPhone(phoneId);
6726 if (phone != null) {
6727 boolean retVal;
6728 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6729 retVal = phone.isUserDataEnabled();
6730 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006731 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006732 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006733 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006734 return retVal;
6735 } else {
6736 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006737 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006738 + subId + " retVal=false");
6739 }
6740 return false;
6741 }
6742 } finally {
6743 Binder.restoreCallingIdentity(identity);
6744 }
6745 }
6746
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006747 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006748 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006749 if (uid == Process.PHONE_UID) {
6750 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6751 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006752 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6753 }
6754
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006755 //load access rules from carrier configs, and check those as well: b/139133814
6756 SubscriptionController subController = SubscriptionController.getInstance();
6757 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6758 || subController == null) return privilegeFromSim;
6759
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006760 PackageManager pkgMgr = phone.getContext().getPackageManager();
6761 String[] packages = pkgMgr.getPackagesForUid(uid);
6762
6763 final long identity = Binder.clearCallingIdentity();
6764 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006765 int subId = phone.getSubId();
6766 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6767 // A test override is in place for the privileges for this subId, so don't try to
6768 // read the subscription privileges.
6769 return privilegeFromSim;
6770 }
6771 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006772 SubscriptionManager subManager = (SubscriptionManager)
6773 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6774 for (String pkg : packages) {
6775 if (subManager.canManageSubscription(subInfo, pkg)) {
6776 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6777 }
6778 }
6779 return privilegeFromSim;
6780 } finally {
6781 Binder.restoreCallingIdentity(identity);
6782 }
6783 }
6784
6785 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6786 String pkgName) {
6787 //load access rules from carrier configs, and check those as well: b/139133814
6788 SubscriptionController subController = SubscriptionController.getInstance();
6789 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6790 || subController == null) return privilegeFromSim;
6791
6792 final long identity = Binder.clearCallingIdentity();
6793 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006794 int subId = phone.getSubId();
6795 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6796 // A test override is in place for the privileges for this subId, so don't try to
6797 // read the subscription privileges.
6798 return privilegeFromSim;
6799 }
6800 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006801 SubscriptionManager subManager = (SubscriptionManager)
6802 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6803 return subManager.canManageSubscription(subInfo, pkgName)
6804 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6805 } finally {
6806 Binder.restoreCallingIdentity(identity);
6807 }
6808 }
6809
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006810 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006811 public int getCarrierPrivilegeStatus(int subId) {
6812 final Phone phone = getPhone(subId);
6813 if (phone == null) {
6814 loge("getCarrierPrivilegeStatus: Invalid subId");
6815 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6816 }
6817 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006818 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006819 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006820 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6821 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006822
6823 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6824 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006825 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006826 }
Junda Liu29340342014-07-10 15:23:27 -07006827
6828 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006829 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006830 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006831 final Phone phone = getPhone(subId);
6832 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006833 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006834 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6835 }
6836 UiccProfile profile =
6837 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6838 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006839 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006840 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6841 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006842 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006843 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006844 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006845 }
6846
6847 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006848 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006849 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006850 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006851 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006852 }
6853
6854 int phoneId = SubscriptionManager.getPhoneId(subId);
6855 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006856 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006857 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006858 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6859 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006860 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6861 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6862 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006863 }
6864
6865 @Override
6866 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006867 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006868 if (TextUtils.isEmpty(pkgName))
6869 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006870 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6871 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6872 UiccCard card = UiccController.getInstance().getUiccCard(i);
6873 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006874 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006875 continue;
6876 }
6877
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006878 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6879 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6880 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006881 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6882 break;
6883 }
6884 }
6885
6886 return result;
Junda Liu29340342014-07-10 15:23:27 -07006887 }
Derek Tan89e89d42014-07-08 17:00:10 -07006888
6889 @Override
Junda Liue64de782015-04-16 17:19:16 -07006890 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006891 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006892 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6893 loge("phoneId " + phoneId + " is not valid.");
6894 return null;
6895 }
6896 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006897 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006898 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006899 return null ;
6900 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006901 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006902 }
6903
Amith Yamasani6e118872016-02-19 12:53:51 -08006904 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006905 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006906 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006907 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006908 List<String> privilegedPackages = new ArrayList<>();
6909 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006910 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6911 // has UICC in that slot.
6912 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006913 if (card.hasCarrierPrivilegeRules()) {
6914 if (packages == null) {
6915 // Only check packages in user 0 for now
6916 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006917 PackageManager.MATCH_DISABLED_COMPONENTS
6918 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006919 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006920 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006921 }
6922 for (int p = packages.size() - 1; p >= 0; p--) {
6923 PackageInfo pkgInfo = packages.get(p);
6924 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran9a1f2d42021-09-28 21:37:29 +00006925 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6926 card.getCarrierPrivilegeStatus(pkgInfo),
6927 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006928 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006929 privilegedPackages.add(pkgInfo.packageName);
6930 }
6931 }
6932 }
6933 }
6934 return privilegedPackages;
6935 }
6936
chen xuf7e9fe82019-05-09 19:31:02 -07006937 @Override
6938 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006939 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6940
6941 final long identity = Binder.clearCallingIdentity();
6942
chen xuf7e9fe82019-05-09 19:31:02 -07006943 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006944 try {
6945 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6946 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6947 }
6948 } finally {
6949 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006950 }
6951 return privilegedPackages;
6952 }
6953
Wink Savilleb564aae2014-10-23 10:18:09 -07006954 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006955 final Phone phone = getPhone(subId);
6956 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006957 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006958 return null;
6959 }
6960 String iccId = card.getIccId();
6961 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006962 return null;
6963 }
6964 return iccId;
6965 }
6966
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006967 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006968 public void setCallComposerStatus(int subId, int status) {
6969 enforceModifyPermission();
6970
6971 final long identity = Binder.clearCallingIdentity();
6972 try {
6973 Phone phone = getPhone(subId);
6974 if (phone != null) {
6975 Phone defaultPhone = phone.getImsPhone();
6976 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6977 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6978 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006979 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6980 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006981 }
6982 }
Shuo Qian284ae752020-12-22 19:10:14 -08006983 } catch (ImsException e) {
6984 throw new ServiceSpecificException(e.getCode());
6985 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006986 Binder.restoreCallingIdentity(identity);
6987 }
6988 }
6989
6990 @Override
6991 public int getCallComposerStatus(int subId) {
6992 enforceReadPrivilegedPermission("getCallComposerStatus");
6993
6994 final long identity = Binder.clearCallingIdentity();
6995 try {
6996 Phone phone = getPhone(subId);
6997 if (phone != null) {
6998 Phone defaultPhone = phone.getImsPhone();
6999 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7000 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7001 return imsPhone.getCallComposerStatus();
7002 }
7003 }
7004 } finally {
7005 Binder.restoreCallingIdentity(identity);
7006 }
7007 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7008 }
7009
7010 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007011 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7012 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007013 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007014 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007016 final long identity = Binder.clearCallingIdentity();
7017 try {
7018 final String iccId = getIccId(subId);
7019 final Phone phone = getPhone(subId);
7020 if (phone == null) {
7021 return false;
7022 }
7023 final String subscriberId = phone.getSubscriberId();
7024
7025 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007026 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007027 + subscriberId + " to " + number);
7028 }
7029
7030 if (TextUtils.isEmpty(iccId)) {
7031 return false;
7032 }
7033
7034 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7035
7036 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7037 if (alphaTag == null) {
7038 editor.remove(alphaTagPrefKey);
7039 } else {
7040 editor.putString(alphaTagPrefKey, alphaTag);
7041 }
7042
7043 // Record both the line number and IMSI for this ICCID, since we need to
7044 // track all merged IMSIs based on line number
7045 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7046 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7047 if (number == null) {
7048 editor.remove(numberPrefKey);
7049 editor.remove(subscriberPrefKey);
7050 } else {
7051 editor.putString(numberPrefKey, number);
7052 editor.putString(subscriberPrefKey, subscriberId);
7053 }
7054
7055 editor.commit();
7056 return true;
7057 } finally {
7058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007059 }
Derek Tan7226c842014-07-02 17:42:23 -07007060 }
7061
7062 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007063 public String getLine1NumberForDisplay(int subId, String callingPackage,
7064 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007065 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007067 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007068 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007069 return null;
7070 }
Derek Tan97ebb422014-09-05 16:55:38 -07007071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 final long identity = Binder.clearCallingIdentity();
7073 try {
7074 String iccId = getIccId(subId);
7075 if (iccId != null) {
7076 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7077 if (DBG_MERGE) {
7078 log("getLine1NumberForDisplay returning "
7079 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7080 }
7081 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007082 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7084 return null;
7085 } finally {
7086 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007087 }
Derek Tan7226c842014-07-02 17:42:23 -07007088 }
7089
7090 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007091 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7092 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007093 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007094 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007095 return null;
7096 }
Derek Tan97ebb422014-09-05 16:55:38 -07007097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007098 final long identity = Binder.clearCallingIdentity();
7099 try {
7100 String iccId = getIccId(subId);
7101 if (iccId != null) {
7102 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7103 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7104 }
7105 return null;
7106 } finally {
7107 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007108 }
Derek Tan7226c842014-07-02 17:42:23 -07007109 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007110
7111 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007112 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7113 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007114 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7115 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007116 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007117 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007118 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007119 return null;
7120 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007121
Jordan Liub49b04b2019-05-06 14:45:15 -07007122 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7123 // the process, where TelephonyManager was instantiated.
7124 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007125 final long identity = Binder.clearCallingIdentity();
7126 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007127 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 final TelephonyManager tele = TelephonyManager.from(context);
7129 final SubscriptionManager sub = SubscriptionManager.from(context);
7130
7131 // Figure out what subscribers are currently active
7132 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133
Jordan Liub49b04b2019-05-06 14:45:15 -07007134 // Only consider subs which match the current subId
7135 // This logic can be simplified. See b/131189269 for progress.
7136 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007137 activeSubscriberIds.add(tele.getSubscriberId(subId));
7138 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139
7140 // First pass, find a number override for an active subscriber
7141 String mergeNumber = null;
7142 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7143 for (String key : prefs.keySet()) {
7144 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7145 final String subscriberId = (String) prefs.get(key);
7146 if (activeSubscriberIds.contains(subscriberId)) {
7147 final String iccId = key.substring(
7148 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7149 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7150 mergeNumber = (String) prefs.get(numberKey);
7151 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007152 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007153 + " for active subscriber " + subscriberId);
7154 }
7155 if (!TextUtils.isEmpty(mergeNumber)) {
7156 break;
7157 }
7158 }
7159 }
7160 }
7161
7162 // Shortcut when no active merged subscribers
7163 if (TextUtils.isEmpty(mergeNumber)) {
7164 return null;
7165 }
7166
7167 // Second pass, find all subscribers under that line override
7168 final ArraySet<String> result = new ArraySet<>();
7169 for (String key : prefs.keySet()) {
7170 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7171 final String number = (String) prefs.get(key);
7172 if (mergeNumber.equals(number)) {
7173 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7174 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7175 final String subscriberId = (String) prefs.get(subscriberKey);
7176 if (!TextUtils.isEmpty(subscriberId)) {
7177 result.add(subscriberId);
7178 }
7179 }
7180 }
7181 }
7182
7183 final String[] resultArray = result.toArray(new String[result.size()]);
7184 Arrays.sort(resultArray);
7185 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007186 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7188 }
7189 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007190 } finally {
7191 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007192 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007193 }
7194
7195 @Override
zoey chen38003472019-12-13 17:16:31 +08007196 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7197 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007198
7199 final long identity = Binder.clearCallingIdentity();
7200 try {
7201 final TelephonyManager telephonyManager = mApp.getSystemService(
7202 TelephonyManager.class);
7203 String subscriberId = telephonyManager.getSubscriberId(subId);
7204 if (subscriberId == null) {
7205 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007206 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007207 + subId);
7208 }
7209 return null;
7210 }
7211
7212 final SubscriptionInfo info = SubscriptionController.getInstance()
7213 .getSubscriptionInfo(subId);
7214 final ParcelUuid groupUuid = info.getGroupUuid();
7215 // If it doesn't belong to any group, return just subscriberId of itself.
7216 if (groupUuid == null) {
7217 return new String[]{subscriberId};
7218 }
7219
7220 // Get all subscriberIds from the group.
7221 final List<String> mergedSubscriberIds = new ArrayList<>();
7222 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007223 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007224 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007225 for (SubscriptionInfo subInfo : groupInfos) {
7226 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7227 if (subscriberId != null) {
7228 mergedSubscriberIds.add(subscriberId);
7229 }
7230 }
7231
7232 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7233 } finally {
7234 Binder.restoreCallingIdentity(identity);
7235
7236 }
7237 }
7238
7239 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007240 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007241 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007242 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243
7244 final long identity = Binder.clearCallingIdentity();
7245 try {
7246 final Phone phone = getPhone(subId);
7247 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7248 } finally {
7249 Binder.restoreCallingIdentity(identity);
7250 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007251 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007252
7253 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007254 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007255 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7256 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007257 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7258 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259
7260 final long identity = Binder.clearCallingIdentity();
7261 try {
7262 final Phone phone = getPhone(subId);
7263 if (phone == null) {
7264 return false;
7265 }
7266 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7267 cdmaNonRoamingList);
7268 } finally {
7269 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007270 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007271 }
7272
7273 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007274 @Deprecated
7275 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7276 enforceModifyPermission();
7277
7278 int returnValue = 0;
7279 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007280 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007281 if(result.exception == null) {
7282 if (result.result != null) {
7283 byte[] responseData = (byte[])(result.result);
7284 if(responseData.length > oemResp.length) {
7285 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7286 responseData.length + "bytes. Buffer Size is " +
7287 oemResp.length + "bytes.");
7288 }
7289 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7290 returnValue = responseData.length;
7291 }
7292 } else {
7293 CommandException ex = (CommandException) result.exception;
7294 returnValue = ex.getCommandError().ordinal();
7295 if(returnValue > 0) returnValue *= -1;
7296 }
7297 } catch (RuntimeException e) {
7298 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7299 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7300 if(returnValue > 0) returnValue *= -1;
7301 }
7302
7303 return returnValue;
7304 }
7305
7306 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007307 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007308 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007309 try {
7310 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007311 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007312 mApp, phone.getSubId(), "getRadioAccessFamily");
7313 } catch (SecurityException e) {
7314 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7315 throw e;
7316 }
chen xub97461a2018-10-26 14:17:57 -07007317 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007318 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007319 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007321 final long identity = Binder.clearCallingIdentity();
7322 try {
chen xub97461a2018-10-26 14:17:57 -07007323 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007324 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007325 mApp, phone.getSubId(), "getRadioAccessFamily");
7326 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 } finally {
7328 Binder.restoreCallingIdentity(identity);
7329 }
chen xub97461a2018-10-26 14:17:57 -07007330 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007331 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007332
7333 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007334 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007335 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007336 try {
7337 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7338 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007339 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007340 }
7341 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007342 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007343 }
7344 RoleManager rm = mApp.getSystemService(RoleManager.class);
7345 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7346 if (!dialerRoleHolders.contains(callingPackage)) {
7347 throw new SecurityException("App must be the dialer role holder to"
7348 + " upload a call composer pic");
7349 }
7350
7351 Executors.newSingleThreadExecutor().execute(() -> {
7352 ByteArrayOutputStream output = new ByteArrayOutputStream(
7353 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7354 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7355 boolean readUntilEnd = false;
7356 int totalBytesRead = 0;
7357 byte[] buffer = new byte[16 * 1024];
7358 while (true) {
7359 int numRead;
7360 try {
7361 numRead = input.read(buffer);
7362 } catch (IOException e) {
7363 try {
7364 fd.checkError();
7365 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7366 null);
7367 } catch (IOException e1) {
7368 // This means that the other side closed explicitly with an error. If this
7369 // happens, log and ignore.
7370 loge("Remote end of call composer picture pipe closed: " + e1);
7371 }
7372 break;
7373 }
7374 if (numRead == -1) {
7375 readUntilEnd = true;
7376 break;
7377 }
7378 totalBytesRead += numRead;
7379 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7380 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7381 try {
7382 input.close();
7383 } catch (IOException e) {
7384 // ignore
7385 }
7386 break;
7387 }
7388 output.write(buffer, 0, numRead);
7389 }
7390 // Generally, the remote end will close the file descriptors. The only case where we
7391 // close is above, where the picture size is too big.
7392
7393 try {
7394 fd.checkError();
7395 } catch (IOException e) {
7396 loge("Remote end for call composer closed with an error: " + e);
7397 return;
7398 }
7399
Hall Liuaa4211e2021-01-20 15:43:39 -08007400 if (!readUntilEnd) {
7401 loge("Did not finish reading entire image; aborting");
7402 return;
7403 }
Hall Liu82694d52020-12-11 18:22:04 -08007404
Hall Liuaa4211e2021-01-20 15:43:39 -08007405 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7406 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7407 new CallComposerPictureTransfer.Factory() {},
7408 imageData,
7409 (result) -> {
7410 if (result.first != null) {
7411 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7412 Bundle outputResult = new Bundle();
7413 outputResult.putParcelable(
7414 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7415 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7416 outputResult);
7417 } else {
7418 callback.send(result.second, null);
7419 }
7420 }
7421 );
Hall Liu82694d52020-12-11 18:22:04 -08007422 });
7423 }
7424
7425 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007426 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007427 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007428 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429
7430 final long identity = Binder.clearCallingIdentity();
7431 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007432 ImsManager.getInstance(defaultPhone.getContext(),
7433 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434 } finally {
7435 Binder.restoreCallingIdentity(identity);
7436 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007437 }
7438
7439 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007440 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007441 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7443 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007444 return false;
7445 }
Svet Ganovb320e182015-04-16 12:30:10 -07007446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 final long identity = Binder.clearCallingIdentity();
7448 try {
7449 // Check the user preference and the system-level IMS setting. Even if the user has
7450 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7451 // In the long run, we may instead need to check if there exists a connection service
7452 // which can support video calling.
7453 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007454 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007455 return imsManager.isVtEnabledByPlatform()
7456 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7457 && imsManager.isVtEnabledByUser();
7458 } finally {
7459 Binder.restoreCallingIdentity(identity);
7460 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007461 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007462
Andrew Leea1239f22015-03-02 17:44:07 -08007463 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007464 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7465 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007467 mApp, subId, callingPackage, callingFeatureId,
7468 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007469 return false;
7470 }
7471
7472 final long identity = Binder.clearCallingIdentity();
7473 try {
7474 CarrierConfigManager configManager =
7475 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007476 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7478 } finally {
7479 Binder.restoreCallingIdentity(identity);
7480 }
Andrew Leea1239f22015-03-02 17:44:07 -08007481 }
7482
7483 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007484 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007486 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 return false;
7488 }
7489
7490 final long identity = Binder.clearCallingIdentity();
7491 try {
7492 CarrierConfigManager configManager =
7493 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007494 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7496 } finally {
7497 Binder.restoreCallingIdentity(identity);
7498 }
Andrew Leea1239f22015-03-02 17:44:07 -08007499 }
7500
Andrew Lee9431b832015-03-09 18:46:45 -07007501 @Override
7502 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007503 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007504 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007505 }
7506
7507 @Override
7508 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 final long identity = Binder.clearCallingIdentity();
7510 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007511 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 } finally {
7513 Binder.restoreCallingIdentity(identity);
7514 }
Andrew Lee9431b832015-03-09 18:46:45 -07007515 }
7516
Hall Liuf6668912018-10-31 17:05:23 -07007517 /**
7518 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7519 * support for the feature and device firmware support.
7520 *
7521 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7522 */
7523 @Override
7524 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007526 final Phone phone = getPhone(subscriptionId);
7527 if (phone == null) {
7528 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7529 return false;
7530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007532 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7534 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007535 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 return isCarrierSupported && isDeviceSupported;
7537 } finally {
7538 Binder.restoreCallingIdentity(identity);
7539 }
Hall Liu98187582018-01-22 19:15:32 -08007540 }
7541
Hall Liuf6668912018-10-31 17:05:23 -07007542 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007543 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7544 * RTT setting, will return true if the device and carrier both support RTT.
7545 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007546 */
7547 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 final long identity = Binder.clearCallingIdentity();
7549 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007550 boolean isRttSupported = isRttSupported(subscriptionId);
7551 boolean isUserRttSettingOn = Settings.Secure.getInt(
7552 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7553 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7554 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7555 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556 } finally {
7557 Binder.restoreCallingIdentity(identity);
7558 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007559 }
7560
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007561 @Deprecated
7562 @Override
7563 public String getDeviceId(String callingPackage) {
7564 return getDeviceIdWithFeature(callingPackage, null);
7565 }
7566
Sanket Padawe7310cc72015-01-14 09:53:20 -08007567 /**
7568 * Returns the unique device ID of phone, for example, the IMEI for
7569 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7570 *
7571 * <p>Requires Permission:
7572 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7573 */
7574 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007575 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007576 try {
7577 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7578 } catch (SecurityException se) {
7579 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7580 throw new SecurityException("Package " + callingPackage + " does not belong to "
7581 + Binder.getCallingUid());
7582 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007583 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007584 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007585 return null;
7586 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007587 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007588 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007589 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007590 return null;
7591 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007592
7593 final long identity = Binder.clearCallingIdentity();
7594 try {
7595 return phone.getDeviceId();
7596 } finally {
7597 Binder.restoreCallingIdentity(identity);
7598 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007599 }
7600
Ping Sunc67b7c22016-03-02 19:16:45 +08007601 /**
7602 * {@hide}
7603 * Returns the IMS Registration Status on a particular subid
7604 *
7605 * @param subId
7606 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007607 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007608 Phone phone = getPhone(subId);
7609 if (phone != null) {
7610 return phone.isImsRegistered();
7611 } else {
7612 return false;
7613 }
7614 }
7615
Santos Cordon7a1885b2015-02-03 11:15:19 -08007616 @Override
7617 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007618 final long identity = Binder.clearCallingIdentity();
7619 try {
7620 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7621 } finally {
7622 Binder.restoreCallingIdentity(identity);
7623 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007624 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007625
Tyler Gunnf70ed162019-04-03 15:28:53 -07007626 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007627 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007628 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007630 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007631 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7632 }
7633 final long identity = Binder.clearCallingIdentity();
7634 try {
7635 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7636 } finally {
7637 Binder.restoreCallingIdentity(identity);
7638 }
7639 }
7640
7641 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007642 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007643 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007644 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007645 mApp,
7646 subscriptionId,
7647 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007648 final long identity = Binder.clearCallingIdentity();
7649 try {
7650 Phone phone = getPhone(subscriptionId);
7651 if (phone == null) {
7652 return null;
7653 }
7654 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7655 } finally {
7656 Binder.restoreCallingIdentity(identity);
7657 }
7658 }
7659
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007660 /**
7661 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007662 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007663 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007664 final long identity = Binder.clearCallingIdentity();
7665 try {
7666 Phone phone = getPhone(subId);
7667 if (phone != null) {
7668 return phone.isWifiCallingEnabled();
7669 } else {
7670 return false;
7671 }
7672 } finally {
7673 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007674 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007675 }
7676
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007677 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007678 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007679 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007680 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007681 final long identity = Binder.clearCallingIdentity();
7682 try {
7683 Phone phone = getPhone(subId);
7684 if (phone != null) {
7685 return phone.isVideoEnabled();
7686 } else {
7687 return false;
7688 }
7689 } finally {
7690 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007691 }
7692 }
7693
7694 /**
7695 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7696 * defined in {@link ImsRegistrationImplBase}.
7697 */
7698 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 final long identity = Binder.clearCallingIdentity();
7700 try {
7701 Phone phone = getPhone(subId);
7702 if (phone != null) {
7703 return phone.getImsRegistrationTech();
7704 } else {
7705 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7706 }
7707 } finally {
7708 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007709 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007710 }
7711
Stuart Scott8eef64f2015-04-08 15:13:54 -07007712 @Override
7713 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007714 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007715 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7716 return;
7717 }
Kai Shif70f46f2021-03-03 13:59:46 -08007718 Phone defaultPhone = getDefaultPhone();
7719 if (defaultPhone != null) {
7720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7721 mApp, getDefaultPhone().getSubId(), "factoryReset");
7722 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007723 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007724
Svet Ganovcc087f82015-05-12 20:35:54 -07007725 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007726 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7727 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007728 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007729 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007730 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007731 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007732 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007733 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007734 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007735 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007736 // There has been issues when Sms raw table somehow stores orphan
7737 // fragments. They lead to garbled message when new fragments come
7738 // in and combined with those stale ones. In case this happens again,
7739 // user can reset all network settings which will clean up this table.
7740 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007741 // Clean up IMS settings as well here.
7742 int slotId = getSlotIndex(subId);
7743 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7744 ImsManager.getInstance(mApp, slotId).factoryReset();
7745 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007746
Kai Shif70f46f2021-03-03 13:59:46 -08007747 if (defaultPhone == null) {
7748 return;
7749 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007750 // Erase modem config if erase modem on network setting is enabled.
7751 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7752 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7753 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007754 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007755 }
Kai Shif70f46f2021-03-03 13:59:46 -08007756
7757 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007758 } finally {
7759 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007760 }
7761 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007762
SongFerngWangfd89b102021-05-27 22:44:54 +08007763 @VisibleForTesting
7764 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7765 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7766 return;
7767 }
7768 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7769 RILConstants.PREFERRED_NETWORK_MODE);
7770 SubscriptionManager.setSubscriptionProperty(subId,
7771 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7772 "user=" + defaultNetworkType);
7773 phone.loadAllowedNetworksFromSubscriptionDatabase();
7774 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7775 defaultNetworkType, null);
7776 }
7777
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007778 private void cleanUpSmsRawTable(Context context) {
7779 ContentResolver resolver = context.getContentResolver();
7780 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7781 resolver.delete(uri, null, null);
7782 }
7783
Narayan Kamath1c496c22015-04-16 14:40:19 +01007784 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007785 public String getSimLocaleForSubscriber(int subId) {
7786 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7787 final Phone phone = getPhone(subId);
7788 if (phone == null) {
7789 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007790 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007791 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007792 final long identity = Binder.clearCallingIdentity();
7793 try {
chen xu5d3637b2019-01-21 23:31:38 -08007794 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007795 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007796 if (info == null) {
7797 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7798 return null;
7799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800 // Try and fetch the locale from the carrier properties or from the SIM language
7801 // preferences (EF-PL and EF-LI)...
7802 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007804 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7805 if (localeFromDefaultSim != null) {
7806 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7807 if (DBG) log("Using locale from subId: " + subId + " locale: "
7808 + localeFromDefaultSim);
7809 return localeFromDefaultSim.toLanguageTag();
7810 } else {
7811 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812 }
7813 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007815 // The SIM language preferences only store a language (e.g. fr = French), not an
7816 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7817 // the SIM and carrier preferences does not include a country we add the country
7818 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007819 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007820 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007821 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822 return mccLocale.toLanguageTag();
7823 }
7824
7825 if (DBG) log("No locale found - returning null");
7826 return null;
7827 } finally {
7828 Binder.restoreCallingIdentity(identity);
7829 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007830 }
7831
7832 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007833 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007834 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007835 }
7836
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007837 /**
7838 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7839 */
7840 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007841 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007842 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007843 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007844
Chenjie Yu1ba97252018-01-11 18:16:20 -08007845 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007846 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007847
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007848 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007849 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7850 * representing the state of the modem.
7851 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007852 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7853 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007854 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007855 */
7856 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007857 public void requestModemActivityInfo(ResultReceiver result) {
7858 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007859 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007860
7861 final long identity = Binder.clearCallingIdentity();
7862 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007863 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007864 } finally {
7865 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007866 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007867 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007868
Siddharth Rayb8114062018-06-17 15:02:38 -07007869 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7870 // less than total activity duration.
7871 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7872 if (info == null) {
7873 return false;
7874 }
7875 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007876 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7877 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7878
Siddharth Rayb8114062018-06-17 15:02:38 -07007879 return (info.isValid()
7880 && (info.getSleepTimeMillis() <= activityDurationMs)
7881 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007882 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007883 && (totalTxTimeMs <= activityDurationMs));
7884 }
7885
Jack Yu85bd38a2015-11-09 11:34:32 -08007886 /**
7887 * {@hide}
7888 * Returns the service state information on specified subscription.
7889 */
7890 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007891 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7892 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007893 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007894 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007895 return null;
7896 }
7897
Hall Liuf19c44f2018-11-27 14:38:17 -08007898 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7899 LocationAccessPolicy.checkLocationPermission(mApp,
7900 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7901 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007902 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007903 .setCallingPid(Binder.getCallingPid())
7904 .setCallingUid(Binder.getCallingUid())
7905 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007906 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007907 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007908 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7909 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007910 .build());
7911
7912 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7913 LocationAccessPolicy.checkLocationPermission(mApp,
7914 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7915 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007916 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007917 .setCallingPid(Binder.getCallingPid())
7918 .setCallingUid(Binder.getCallingUid())
7919 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007920 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007921 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007922 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7923 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007924 .build());
7925 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7926 boolean hasFinePermission =
7927 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7928 boolean hasCoarsePermission =
7929 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7930
Jack Yu479f40e2020-10-27 21:29:25 -07007931 final Phone phone = getPhone(subId);
7932 if (phone == null) {
7933 return null;
7934 }
7935
Jordan Liu0f2bc442020-11-18 16:47:37 -08007936 final long identity = Binder.clearCallingIdentity();
7937
Jack Yu479f40e2020-10-27 21:29:25 -07007938 boolean isCallingPackageDataService = phone.getDataServicePackages()
7939 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007940 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007941 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7942 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7943 Rlog.d(LOG_TAG,
7944 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7945 return null;
7946 }
7947
Hall Liuf19c44f2018-11-27 14:38:17 -08007948 ServiceState ss = phone.getServiceState();
7949
7950 // Scrub out the location info in ServiceState depending on what level of access
7951 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007952 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007953 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7954 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 } finally {
7956 Binder.restoreCallingIdentity(identity);
7957 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007958 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007959
7960 /**
7961 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7962 *
7963 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7964 * voicemail ringtone.
7965 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7966 * PhoneAccount.
7967 */
7968 @Override
7969 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007970 final long identity = Binder.clearCallingIdentity();
7971 try {
7972 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7973 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007974 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007975 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007977 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7978 } finally {
7979 Binder.restoreCallingIdentity(identity);
7980 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007981 }
7982
7983 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007984 * Sets the per-account voicemail ringtone.
7985 *
7986 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7987 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7988 *
7989 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7990 * voicemail ringtone.
7991 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7992 * PhoneAccount.
7993 */
7994 @Override
7995 public void setVoicemailRingtoneUri(String callingPackage,
7996 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007997 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007998 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007999 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8000 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8002 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8003 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005
8006 final long identity = Binder.clearCallingIdentity();
8007 try {
8008 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8009 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008010 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008011 }
8012 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8013 } finally {
8014 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008015 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008016 }
8017
8018 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008019 * Returns whether vibration is set for voicemail notification in Phone settings.
8020 *
8021 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8022 * voicemail vibration setting.
8023 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8024 */
8025 @Override
8026 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008027 final long identity = Binder.clearCallingIdentity();
8028 try {
8029 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8030 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008031 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008032 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008033
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008034 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8035 } finally {
8036 Binder.restoreCallingIdentity(identity);
8037 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008038 }
8039
Youhan Wange64578a2016-05-02 15:32:42 -07008040 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008041 * Sets the per-account voicemail vibration.
8042 *
8043 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8044 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8045 *
8046 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8047 * voicemail vibration setting.
8048 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8049 * specific PhoneAccount.
8050 */
8051 @Override
8052 public void setVoicemailVibrationEnabled(String callingPackage,
8053 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008054 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008055 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008056 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8057 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8059 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8060 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008061 }
8062
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008063 final long identity = Binder.clearCallingIdentity();
8064 try {
8065 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8066 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008067 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008068 }
8069 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8070 } finally {
8071 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008072 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008073 }
8074
8075 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008076 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8077 *
8078 * @throws SecurityException if the caller does not have the required permission
8079 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008080 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008081 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008082 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008083 }
8084
8085 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008086 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8087 * permission.
8088 *
8089 * @throws SecurityException if the caller does not have the required permission
8090 */
8091 private void enforceSendSmsPermission() {
8092 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8093 }
8094
8095 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008096 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008097 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008098 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008099 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008100 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008101 final long identity = Binder.clearCallingIdentity();
8102 try {
8103 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008104 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008105 if (componentName == null) {
8106 throw new SecurityException(
8107 "Caller not current active visual voicemail package[null]");
8108 }
8109 String vvmPackage = componentName.getPackageName();
8110 if (!callingPackage.equals(vvmPackage)) {
8111 throw new SecurityException("Caller not current active visual voicemail package["
8112 + vvmPackage + "]");
8113 }
8114 } finally {
8115 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008116 }
8117 }
8118
8119 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008120 * Return the application ID for the app type.
8121 *
8122 * @param subId the subscription ID that this request applies to.
8123 * @param appType the uicc app type.
8124 * @return Application ID for specificied app type, or null if no uicc.
8125 */
8126 @Override
8127 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008128 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008129 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008130
8131 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008132 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133 if (phone == null) {
8134 return null;
8135 }
8136 String aid = null;
8137 try {
8138 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8139 .getApplicationByType(appType).getAid();
8140 } catch (Exception e) {
8141 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8142 }
8143 return aid;
8144 } finally {
8145 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008146 }
Youhan Wange64578a2016-05-02 15:32:42 -07008147 }
8148
Youhan Wang4001d252016-05-11 10:29:41 -07008149 /**
8150 * Return the Electronic Serial Number.
8151 *
8152 * @param subId the subscription ID that this request applies to.
8153 * @return ESN or null if error.
8154 */
8155 @Override
8156 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008157 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008158 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008159
8160 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008161 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162 if (phone == null) {
8163 return null;
8164 }
8165 String esn = null;
8166 try {
8167 esn = phone.getEsn();
8168 } catch (Exception e) {
8169 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8170 }
8171 return esn;
8172 } finally {
8173 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008174 }
Youhan Wang4001d252016-05-11 10:29:41 -07008175 }
8176
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008177 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008178 * Return the Preferred Roaming List Version.
8179 *
8180 * @param subId the subscription ID that this request applies to.
8181 * @return PRLVersion or null if error.
8182 */
8183 @Override
8184 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008185 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008186 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008187
8188 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008189 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008190 if (phone == null) {
8191 return null;
8192 }
8193 String cdmaPrlVersion = null;
8194 try {
8195 cdmaPrlVersion = phone.getCdmaPrlVersion();
8196 } catch (Exception e) {
8197 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8198 }
8199 return cdmaPrlVersion;
8200 } finally {
8201 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008202 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008203 }
8204
8205 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008206 * Get snapshot of Telephony histograms
8207 * @return List of Telephony histograms
8208 * @hide
8209 */
8210 @Override
8211 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8213 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214
8215 final long identity = Binder.clearCallingIdentity();
8216 try {
8217 return RIL.getTelephonyRILTimingHistograms();
8218 } finally {
8219 Binder.restoreCallingIdentity(identity);
8220 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008221 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008222
8223 /**
8224 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008225 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8226 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008227 * Require system privileges. In the future we may add this to carrier APIs.
8228 *
Michele Berionne482f8202018-11-27 18:57:59 -08008229 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008230 */
8231 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008232 @TelephonyManager.SetCarrierRestrictionResult
8233 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008234 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008235 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008236
Michele Berionne482f8202018-11-27 18:57:59 -08008237 if (carrierRestrictionRules == null) {
8238 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008239 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 final long identity = Binder.clearCallingIdentity();
8242 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008243 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008244 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008245 } finally {
8246 Binder.restoreCallingIdentity(identity);
8247 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008248 }
8249
8250 /**
8251 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008252 * Get the allowed carrier list and the excluded carrier list, including the priority between
8253 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008254 * Require system privileges. In the future we may add this to carrier APIs.
8255 *
Michele Berionne482f8202018-11-27 18:57:59 -08008256 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008257 */
8258 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008259 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008260 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008261 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008262
8263 final long identity = Binder.clearCallingIdentity();
8264 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008265 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8266 if (response instanceof CarrierRestrictionRules) {
8267 return (CarrierRestrictionRules) response;
8268 }
8269 // Response is an Exception of some kind,
8270 // which is signalled to the user as a NULL retval
8271 return null;
8272 } catch (Exception e) {
8273 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8274 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275 } finally {
8276 Binder.restoreCallingIdentity(identity);
8277 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008278 }
8279
fionaxu59545b42016-05-25 15:53:37 -07008280 /**
fionaxu59545b42016-05-25 15:53:37 -07008281 * Action set from carrier signalling broadcast receivers to enable/disable radio
8282 * @param subId the subscription ID that this action applies to.
8283 * @param enabled control enable or disable radio.
8284 * {@hide}
8285 */
8286 @Override
8287 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8288 enforceModifyPermission();
8289 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008290
8291 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008292 if (phone == null) {
8293 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8294 return;
8295 }
8296 try {
8297 phone.carrierActionSetRadioEnabled(enabled);
8298 } catch (Exception e) {
8299 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300 } finally {
8301 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008302 }
8303 }
8304
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008305 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008306 * Enable or disable Voice over NR (VoNR)
8307 * @param subId the subscription ID that this action applies to.
8308 * @param enabled enable or disable VoNR.
8309 * @return operation result.
8310 */
8311 @Override
8312 public int setVoNrEnabled(int subId, boolean enabled) {
8313 enforceModifyPermission();
8314 final Phone phone = getPhone(subId);
8315
8316 final long identity = Binder.clearCallingIdentity();
8317 if (phone == null) {
8318 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8319 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8320 }
8321
8322 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8323 try {
8324 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8325 workSource);
8326 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008327
8328 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8329 if (DBG) {
8330 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8331 }
8332 SubscriptionManager.setSubscriptionProperty(
8333 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8334 (enabled ? "1" : "0"));
8335 }
8336
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008337 return result;
8338 } finally {
8339 Binder.restoreCallingIdentity(identity);
8340 }
8341 }
8342
8343 /**
8344 * Is voice over NR enabled
8345 * @return true if VoNR is enabled else false
8346 */
8347 @Override
8348 public boolean isVoNrEnabled(int subId) {
8349 enforceReadPrivilegedPermission("isVoNrEnabled");
8350 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8351 final long identity = Binder.clearCallingIdentity();
8352 try {
8353 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8354 null, subId, workSource);
8355 if (DBG) log("isVoNrEnabled: " + isEnabled);
8356 return isEnabled;
8357 } finally {
8358 Binder.restoreCallingIdentity(identity);
8359 }
8360 }
8361
8362 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008363 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8364 * network status based on which carrier apps could apply actions accordingly,
8365 * enable/disable default url handler for example.
8366 *
8367 * @param subId the subscription ID that this action applies to.
8368 * @param report control start/stop reporting the default network status.
8369 * {@hide}
8370 */
8371 @Override
8372 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8373 enforceModifyPermission();
8374 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008375
8376 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008377 if (phone == null) {
8378 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8379 return;
8380 }
8381 try {
8382 phone.carrierActionReportDefaultNetworkStatus(report);
8383 } catch (Exception e) {
8384 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008385 } finally {
8386 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008387 }
8388 }
8389
8390 /**
fionaxud9622282017-07-17 17:51:30 -07008391 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8392 * @param subId the subscription ID that this action applies to.
8393 * {@hide}
8394 */
8395 @Override
8396 public void carrierActionResetAll(int subId) {
8397 enforceModifyPermission();
8398 final Phone phone = getPhone(subId);
8399 if (phone == null) {
8400 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8401 return;
8402 }
8403 try {
8404 phone.carrierActionResetAll();
8405 } catch (Exception e) {
8406 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8407 }
8408 }
8409
8410 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008411 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8412 * bug report is being generated.
8413 */
8414 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008415 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008416 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8417 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008418 writer.println("Permission Denial: can't dump Phone from pid="
8419 + Binder.getCallingPid()
8420 + ", uid=" + Binder.getCallingUid()
8421 + "without permission "
8422 + android.Manifest.permission.DUMP);
8423 return;
8424 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008425 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008426 }
Jack Yueb89b242016-06-22 13:27:47 -07008427
Brad Ebingerdac2f002018-04-03 15:17:52 -07008428 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008429 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8430 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8431 @NonNull String[] args) {
8432 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8433 this, in.getFileDescriptor(), out.getFileDescriptor(),
8434 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008435 }
8436
Jack Yueb89b242016-06-22 13:27:47 -07008437 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008438 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008439 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008440 * @param reason the reason the data enable change is taking place
8441 * @param enabled True if enabling the data, otherwise disabling.
8442 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008443 */
8444 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008445 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008446 boolean enabled) {
8447 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8448 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8449 try {
8450 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008451 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008452 } catch (SecurityException se) {
8453 enforceModifyPermission();
8454 }
8455 } else {
8456 enforceModifyPermission();
8457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008458
8459 final long identity = Binder.clearCallingIdentity();
8460 try {
8461 Phone phone = getPhone(subId);
8462 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008463 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8464 phone.carrierActionSetMeteredApnsEnabled(enabled);
8465 } else {
8466 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8467 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008468 }
8469 } finally {
8470 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008471 }
8472 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008473
8474 /**
8475 * Get Client request stats
8476 * @return List of Client Request Stats
8477 * @hide
8478 */
8479 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008480 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8481 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008482 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008483 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008484 return null;
8485 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008486 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008488 final long identity = Binder.clearCallingIdentity();
8489 try {
8490 if (phone != null) {
8491 return phone.getClientRequestStats();
8492 }
8493
8494 return null;
8495 } finally {
8496 Binder.restoreCallingIdentity(identity);
8497 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008498 }
8499
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008500 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008501 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008502 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008503 }
Jack Yueb4124c2017-02-16 15:32:43 -08008504
8505 /**
Grace Chen70990072017-03-24 17:21:30 -07008506 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008507 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008508 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008509 * @param state State of SIM (power down, power up, pass through)
8510 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8511 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8512 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008513 *
8514 **/
8515 @Override
Grace Chen70990072017-03-24 17:21:30 -07008516 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008517 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008518 Phone phone = PhoneFactory.getPhone(slotIndex);
8519
vagdeviaf9a5b92018-08-15 16:01:53 -07008520 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008522 final long identity = Binder.clearCallingIdentity();
8523 try {
8524 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008525 phone.setSimPowerState(state, null, workSource);
8526 }
8527 } finally {
8528 Binder.restoreCallingIdentity(identity);
8529 }
8530 }
8531
8532 /**
8533 * Set SIM card power state.
8534 *
8535 * @param slotIndex SIM slot id.
8536 * @param state State of SIM (power down, power up, pass through)
8537 * @param callback callback to trigger after success or failure
8538 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8539 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8540 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8541 *
8542 **/
8543 @Override
8544 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8545 IIntegerConsumer callback) {
8546 enforceModifyPermission();
8547 Phone phone = PhoneFactory.getPhone(slotIndex);
8548
8549 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8550
8551 final long identity = Binder.clearCallingIdentity();
8552 try {
8553 if (phone != null) {
8554 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8555 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008556 }
8557 } finally {
8558 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008559 }
8560 }
Shuo Qiandd210312017-04-12 22:11:33 +00008561
Tyler Gunn65d45c22017-06-05 11:22:26 -07008562 private boolean isUssdApiAllowed(int subId) {
8563 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008564 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008565 if (configManager == null) {
8566 return false;
8567 }
8568 PersistableBundle pb = configManager.getConfigForSubId(subId);
8569 if (pb == null) {
8570 return false;
8571 }
8572 return pb.getBoolean(
8573 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8574 }
8575
Shuo Qiandd210312017-04-12 22:11:33 +00008576 /**
8577 * Check if phone is in emergency callback mode
8578 * @return true if phone is in emergency callback mode
8579 * @param subId sub id
8580 */
goneil9c5f4872017-12-05 14:07:56 -08008581 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008582 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008583 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008584 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008585
8586 final long identity = Binder.clearCallingIdentity();
8587 try {
8588 if (phone != null) {
8589 return phone.isInEcm();
8590 } else {
8591 return false;
8592 }
8593 } finally {
8594 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008595 }
8596 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008597
8598 /**
8599 * Get the current signal strength information for the given subscription.
8600 * Because this information is not updated when the device is in a low power state
8601 * it should not be relied-upon to be current.
8602 * @param subId Subscription index
8603 * @return the most recent cached signal strength info from the modem
8604 */
8605 @Override
8606 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008607 final long identity = Binder.clearCallingIdentity();
8608 try {
8609 Phone p = getPhone(subId);
8610 if (p == null) {
8611 return null;
8612 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008614 return p.getSignalStrength();
8615 } finally {
8616 Binder.restoreCallingIdentity(identity);
8617 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008618 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008619
Pengquan Meng77b7f132018-08-22 14:49:57 -07008620 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008621 * Get the current modem radio state for the given slot.
8622 * @param slotIndex slot index.
8623 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008624 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008625 * @return the current radio power state from the modem
8626 */
8627 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008628 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008629 Phone phone = PhoneFactory.getPhone(slotIndex);
8630 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8632 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008633 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8634 }
8635
8636 final long identity = Binder.clearCallingIdentity();
8637 try {
8638 return phone.getRadioPowerState();
8639 } finally {
8640 Binder.restoreCallingIdentity(identity);
8641 }
8642 }
8643 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8644 }
8645
8646 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008647 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8648 *
8649 * <p>Requires one of the following permissions:
8650 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8651 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8652 * privileges.
8653 *
8654 * @param subId subscription id
8655 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8656 * {@code false}.
8657 */
8658 @Override
8659 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008660 try {
8661 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8662 null);
8663 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008664 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008665 mApp, subId, "isDataRoamingEnabled");
8666 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008667
Pengquan Menga1bb6272018-09-06 09:59:22 -07008668 boolean isEnabled = false;
8669 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008670 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008671 Phone phone = getPhone(subId);
8672 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008673 } finally {
8674 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008675 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008676 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008677 }
8678
8679
8680 /**
8681 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8682 *
8683 * <p> Requires permission:
8684 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8685 * privileges.
8686 *
8687 * @param subId subscription id
8688 * @param isEnabled {@code true} means enable, {@code false} means disable.
8689 */
8690 @Override
8691 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8693 mApp, subId, "setDataRoamingEnabled");
8694
Pengquan Menga1bb6272018-09-06 09:59:22 -07008695 final long identity = Binder.clearCallingIdentity();
8696 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008697 Phone phone = getPhone(subId);
8698 if (phone != null) {
8699 phone.setDataRoamingEnabled(isEnabled);
8700 }
8701 } finally {
8702 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008703 }
8704 }
8705
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008706 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008707 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008708 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008709 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008710 mApp, subId, "isManualNetworkSelectionAllowed");
8711
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008712 boolean isAllowed = true;
8713 final long identity = Binder.clearCallingIdentity();
8714 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008715 Phone phone = getPhone(subId);
8716 if (phone != null) {
8717 isAllowed = phone.isCspPlmnEnabled();
8718 }
8719 } finally {
8720 Binder.restoreCallingIdentity(identity);
8721 }
8722 return isAllowed;
8723 }
8724
8725 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008726 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008727 // Verify that tha callingPackage belongs to the calling UID
8728 mApp.getSystemService(AppOpsManager.class)
8729 .checkPackage(Binder.getCallingUid(), callingPackage);
8730
Jordan Liu1e142fc2019-04-22 15:10:43 -07008731 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008732 try {
8733 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008734 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008735 } catch (SecurityException e) {
8736 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8737 // has carrier privileges on an active UICC
8738 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8739 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008740 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008741 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008742 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008743
8744 final long identity = Binder.clearCallingIdentity();
8745 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008746 UiccController uiccController = UiccController.getInstance();
8747 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008748 if (hasReadPermission) {
8749 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008750 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008751
8752 // Remove private info if the caller doesn't have access
8753 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8754 for (UiccCardInfo cardInfo : cardInfos) {
8755 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8756 // is available
8757 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8758 if (card == null || card.getUiccProfile() == null) {
8759 // assume no access if the card or profile is unavailable
8760 filteredInfos.add(cardInfo.getUnprivileged());
8761 continue;
8762 }
8763 UiccProfile profile = card.getUiccProfile();
8764 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8765 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8766 filteredInfos.add(cardInfo);
8767 } else {
8768 filteredInfos.add(cardInfo.getUnprivileged());
8769 }
8770 }
8771 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008772 } finally {
8773 Binder.restoreCallingIdentity(identity);
8774 }
8775 }
8776
8777 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008778 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008779 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008781 final long identity = Binder.clearCallingIdentity();
8782 try {
8783 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8784 if (slots == null) {
8785 Rlog.i(LOG_TAG, "slots is null.");
8786 return null;
8787 }
8788
8789 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8790 for (int i = 0; i < slots.length; i++) {
8791 UiccSlot slot = slots[i];
8792 if (slot == null) {
8793 continue;
8794 }
8795
Jordan Liu7be7e652019-05-06 18:55:02 +00008796 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008797 UiccCard card = slot.getUiccCard();
8798 if (card != null) {
8799 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008800 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008801 cardId = slot.getEid();
8802 if (TextUtils.isEmpty(cardId)) {
8803 cardId = slot.getIccId();
8804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008805 }
8806
Jordan Liu857451f2019-05-09 16:35:35 -07008807 if (cardId != null) {
8808 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8809 // if cardId is an EID, it's all digits so this is fine
8810 cardId = IccUtils.stripTrailingFs(cardId);
8811 }
8812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008813 int cardState = 0;
8814 switch (slot.getCardState()) {
8815 case CARDSTATE_ABSENT:
8816 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8817 break;
8818 case CARDSTATE_PRESENT:
8819 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8820 break;
8821 case CARDSTATE_ERROR:
8822 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8823 break;
8824 case CARDSTATE_RESTRICTED:
8825 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8826 break;
8827 default:
8828 break;
8829
8830 }
8831
8832 infos[i] = new UiccSlotInfo(
8833 slot.isActive(),
8834 slot.isEuicc(),
8835 cardId,
8836 cardState,
8837 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008838 slot.isExtendedApduSupported(),
8839 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008840 }
8841 return infos;
8842 } finally {
8843 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008844 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008845 }
8846
8847 @Override
8848 public boolean switchSlots(int[] physicalSlots) {
8849 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008850
8851 final long identity = Binder.clearCallingIdentity();
8852 try {
8853 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8854 } finally {
8855 Binder.restoreCallingIdentity(identity);
8856 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008857 }
Jack Yu4c988042018-02-27 15:30:01 -08008858
8859 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008860 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008861 final long identity = Binder.clearCallingIdentity();
8862 try {
8863 return UiccController.getInstance().getCardIdForDefaultEuicc();
8864 } finally {
8865 Binder.restoreCallingIdentity(identity);
8866 }
8867 }
8868
Pengquan Meng85728fb2018-03-12 16:31:21 -07008869 /**
goneil47ffb6e2018-04-06 15:40:58 -07008870 * A test API to reload the UICC profile.
8871 *
8872 * <p>Requires that the calling app has permission
8873 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8874 * @hide
8875 */
8876 @Override
8877 public void refreshUiccProfile(int subId) {
8878 enforceModifyPermission();
8879
8880 final long identity = Binder.clearCallingIdentity();
8881 try {
8882 Phone phone = getPhone(subId);
8883 if (phone == null) {
8884 return;
8885 }
8886 UiccCard uiccCard = phone.getUiccCard();
8887 if (uiccCard == null) {
8888 return;
8889 }
8890 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8891 if (uiccProfile == null) {
8892 return;
8893 }
8894 uiccProfile.refresh();
8895 } finally {
8896 Binder.restoreCallingIdentity(identity);
8897 }
8898 }
8899
8900 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008901 * Returns false if the mobile data is disabled by default, otherwise return true.
8902 */
8903 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008904 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008905 }
8906
8907 /**
8908 * Returns true if the data roaming is enabled by default, i.e the system property
8909 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8910 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8911 */
8912 private boolean getDefaultDataRoamingEnabled(int subId) {
8913 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008914 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008915 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008916 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8917 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8918 return isDataRoamingEnabled;
8919 }
8920
8921 /**
8922 * Returns the default network type for the given {@code subId}, if the default network type is
8923 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8924 */
8925 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008926 List<Integer> list = TelephonyProperties.default_network();
8927 int phoneId = mSubscriptionController.getPhoneId(subId);
8928 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8929 return list.get(phoneId);
8930 }
8931 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008932 }
fionaxua13278b2018-03-21 00:08:13 -07008933
8934 @Override
8935 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008936 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008937 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008938
8939 final long identity = Binder.clearCallingIdentity();
8940 try {
8941 final Phone phone = getPhone(subId);
8942 if (phone == null) {
8943 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8944 return;
8945 }
chen xueaba88a2019-03-15 13:15:10 -07008946 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8947 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008948 if (carrierPrivilegeRules == null) {
8949 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8950 } else {
8951 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008953 } finally {
8954 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008955 }
fionaxua13278b2018-03-21 00:08:13 -07008956 }
8957
8958 @Override
8959 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008960 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008961
8962 final long identity = Binder.clearCallingIdentity();
8963 try {
8964 final Phone phone = getPhone(subId);
8965 if (phone == null) {
8966 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8967 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8968 }
8969 return phone.getCarrierIdListVersion();
8970 } finally {
8971 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008972 }
fionaxua13278b2018-03-21 00:08:13 -07008973 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008974
8975 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008976 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8977 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008979 mApp, subId, callingPackage, callingFeatureId,
8980 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008981 return -1;
8982 }
8983
8984 final long identity = Binder.clearCallingIdentity();
8985 try {
8986 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8987 } finally {
8988 Binder.restoreCallingIdentity(identity);
8989 }
8990 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008991
8992 @Override
8993 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008994 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008995 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008996 mApp, subId, "getCdmaRoamingMode");
8997
8998 final long identity = Binder.clearCallingIdentity();
8999 try {
9000 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9001 } finally {
9002 Binder.restoreCallingIdentity(identity);
9003 }
9004 }
9005
9006 @Override
9007 public boolean setCdmaRoamingMode(int subId, int mode) {
9008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9009 mApp, subId, "setCdmaRoamingMode");
9010
9011 final long identity = Binder.clearCallingIdentity();
9012 try {
9013 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9014 } finally {
9015 Binder.restoreCallingIdentity(identity);
9016 }
9017 }
9018
9019 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009020 public int getCdmaSubscriptionMode(int subId) {
9021 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009022 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009023 mApp, subId, "getCdmaSubscriptionMode");
9024
9025 final long identity = Binder.clearCallingIdentity();
9026 try {
9027 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9028 } finally {
9029 Binder.restoreCallingIdentity(identity);
9030 }
9031 }
9032
9033 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009034 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9036 mApp, subId, "setCdmaSubscriptionMode");
9037
9038 final long identity = Binder.clearCallingIdentity();
9039 try {
9040 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9041 } finally {
9042 Binder.restoreCallingIdentity(identity);
9043 }
9044 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009045
sqianc5eccab2018-10-19 18:46:41 -07009046 @Override
sqian8c685422019-02-22 15:55:18 -08009047 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009048 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009050 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9051 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009052 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9053 }
9054 final long identity = Binder.clearCallingIdentity();
9055 try {
sqian854d44b2018-12-12 16:48:18 -08009056 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9057 for (Phone phone: PhoneFactory.getPhones()) {
9058 if (phone.getEmergencyNumberTracker() != null
9059 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9060 emergencyNumberListInternal.put(
9061 phone.getSubId(),
9062 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9063 }
sqian11b7a0e2018-12-05 18:48:28 -08009064 }
sqian854d44b2018-12-12 16:48:18 -08009065 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009066 } finally {
9067 Binder.restoreCallingIdentity(identity);
9068 }
sqianc5eccab2018-10-19 18:46:41 -07009069 }
9070
9071 @Override
sqian8c685422019-02-22 15:55:18 -08009072 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009073 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009074 if (!exactMatch) {
9075 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009076 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009077 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009078 }
9079 final long identity = Binder.clearCallingIdentity();
9080 try {
sqian854d44b2018-12-12 16:48:18 -08009081 for (Phone phone: PhoneFactory.getPhones()) {
9082 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009083 && phone.getEmergencyNumberTracker()
9084 .isEmergencyNumber(number, exactMatch)) {
9085 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009086 }
sqian11b7a0e2018-12-05 18:48:28 -08009087 }
9088 return false;
9089 } finally {
9090 Binder.restoreCallingIdentity(identity);
9091 }
9092 }
9093
sqianf4ca7ed2019-01-15 18:32:07 -08009094 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009095 * Start emergency callback mode for GsmCdmaPhone for testing.
9096 */
9097 @Override
9098 public void startEmergencyCallbackMode() {
9099 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9100 "startEmergencyCallbackMode");
9101 enforceModifyPermission();
9102 final long identity = Binder.clearCallingIdentity();
9103 try {
9104 for (Phone phone : PhoneFactory.getPhones()) {
9105 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9106 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9107 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9108 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9109 gsmCdmaPhone.obtainMessage(
9110 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9111 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9112 }
9113 }
9114 } finally {
9115 Binder.restoreCallingIdentity(identity);
9116 }
9117 }
9118
9119 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009120 * Update emergency number list for test mode.
9121 */
9122 @Override
9123 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9124 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9125 "updateEmergencyNumberListTestMode");
9126
9127 final long identity = Binder.clearCallingIdentity();
9128 try {
9129 for (Phone phone: PhoneFactory.getPhones()) {
9130 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9131 if (tracker != null) {
9132 tracker.executeEmergencyNumberTestModeCommand(action, num);
9133 }
9134 }
9135 } finally {
9136 Binder.restoreCallingIdentity(identity);
9137 }
9138 }
9139
9140 /**
9141 * Get the full emergency number list for test mode.
9142 */
9143 @Override
9144 public List<String> getEmergencyNumberListTestMode() {
9145 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9146 "getEmergencyNumberListTestMode");
9147
9148 final long identity = Binder.clearCallingIdentity();
9149 try {
9150 Set<String> emergencyNumbers = new HashSet<>();
9151 for (Phone phone: PhoneFactory.getPhones()) {
9152 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9153 if (tracker != null) {
9154 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9155 emergencyNumbers.add(num.getNumber());
9156 }
9157 }
9158 }
9159 return new ArrayList<>(emergencyNumbers);
9160 } finally {
9161 Binder.restoreCallingIdentity(identity);
9162 }
9163 }
9164
chen xud6b45bd2018-10-30 22:27:10 -07009165 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009166 public int getEmergencyNumberDbVersion(int subId) {
9167 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9168
9169 final long identity = Binder.clearCallingIdentity();
9170 try {
9171 final Phone phone = getPhone(subId);
9172 if (phone == null) {
9173 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9174 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9175 }
9176 return phone.getEmergencyNumberDbVersion();
9177 } finally {
9178 Binder.restoreCallingIdentity(identity);
9179 }
9180 }
9181
9182 @Override
9183 public void notifyOtaEmergencyNumberDbInstalled() {
9184 enforceModifyPermission();
9185
9186 final long identity = Binder.clearCallingIdentity();
9187 try {
9188 for (Phone phone: PhoneFactory.getPhones()) {
9189 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9190 if (tracker != null) {
9191 tracker.updateOtaEmergencyNumberDatabase();
9192 }
9193 }
9194 } finally {
9195 Binder.restoreCallingIdentity(identity);
9196 }
9197 }
9198
9199 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009200 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009201 enforceActiveEmergencySessionPermission();
9202
9203 final long identity = Binder.clearCallingIdentity();
9204 try {
9205 for (Phone phone: PhoneFactory.getPhones()) {
9206 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9207 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009208 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9209 }
9210 }
9211 } finally {
9212 Binder.restoreCallingIdentity(identity);
9213 }
9214 }
9215
9216 @Override
9217 public void resetOtaEmergencyNumberDbFilePath() {
9218 enforceActiveEmergencySessionPermission();
9219
9220 final long identity = Binder.clearCallingIdentity();
9221 try {
9222 for (Phone phone: PhoneFactory.getPhones()) {
9223 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9224 if (tracker != null) {
9225 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009226 }
9227 }
9228 } finally {
9229 Binder.restoreCallingIdentity(identity);
9230 }
9231 }
9232
9233 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009234 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9235 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9236 Phone phone = getPhone(subId);
9237 if (phone == null) {
9238 return null;
9239 }
9240 final long identity = Binder.clearCallingIdentity();
9241 try {
9242 UiccProfile profile = UiccController.getInstance()
9243 .getUiccProfileForPhone(phone.getPhoneId());
9244 if (profile != null) {
9245 return profile.getCertsFromCarrierPrivilegeAccessRules();
9246 }
9247 } finally {
9248 Binder.restoreCallingIdentity(identity);
9249 }
9250 return null;
9251 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009252
9253 /**
9254 * Enable or disable a modem stack.
9255 */
9256 @Override
9257 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9258 enforceModifyPermission();
9259
9260 final long identity = Binder.clearCallingIdentity();
9261 try {
9262 Phone phone = PhoneFactory.getPhone(slotIndex);
9263 if (phone == null) {
9264 return false;
9265 } else {
9266 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9267 }
9268 } finally {
9269 Binder.restoreCallingIdentity(identity);
9270 }
9271 }
Michelecea4cf22018-12-21 15:00:11 -08009272
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009273 /**
9274 * Whether a modem stack is enabled or not.
9275 */
9276 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009277 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9278 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009279 Phone phone = PhoneFactory.getPhone(slotIndex);
9280 if (phone == null) return false;
9281
9282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009283 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9284 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009285 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9286 }
9287
9288 final long identity = Binder.clearCallingIdentity();
9289 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009290 try {
9291 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9292 } catch (NoSuchElementException ex) {
9293 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9294 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009295 } finally {
9296 Binder.restoreCallingIdentity(identity);
9297 }
9298 }
9299
Michelecea4cf22018-12-21 15:00:11 -08009300 @Override
Michele0ea7d782019-03-19 14:58:42 -07009301 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009302 enforceModifyPermission();
9303
9304 final long identity = Binder.clearCallingIdentity();
9305 try {
9306 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009307 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009308 .commit();
9309 } finally {
9310 Binder.restoreCallingIdentity(identity);
9311 }
9312 }
9313
9314 @Override
Michele0ea7d782019-03-19 14:58:42 -07009315 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009316 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009318 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9319 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009320 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009321 }
Michelecea4cf22018-12-21 15:00:11 -08009322
9323 final long identity = Binder.clearCallingIdentity();
9324 try {
Michele0ea7d782019-03-19 14:58:42 -07009325 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009326 } finally {
9327 Binder.restoreCallingIdentity(identity);
9328 }
9329 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009330
Michele0ea7d782019-03-19 14:58:42 -07009331 @TelephonyManager.IsMultiSimSupportedResult
9332 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009333 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9334 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9335 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009336 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9337 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009338 }
9339 // Check if the hardware supports multisim functionality. If usage of multisim is not
9340 // supported by the modem, indicate that it is restricted.
9341 PhoneCapability staticCapability =
9342 mPhoneConfigurationManager.getStaticPhoneCapability();
9343 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009344 loge("isMultiSimSupportedInternal: no static configuration available");
9345 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009346 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009347 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009348 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9349 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009350 }
9351 // Check if support of multiple SIMs is restricted by carrier
9352 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009353 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009354 }
9355
Michele0ea7d782019-03-19 14:58:42 -07009356 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009357 }
9358
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009359 /**
9360 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009361 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9362 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9363 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009364 * @param numOfSims number of active sims we want to switch to
9365 */
9366 @Override
9367 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009368 if (numOfSims == 1) {
9369 enforceModifyPermission();
9370 } else {
9371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9372 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9373 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009374 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009375
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009376 try {
Michele30b57b22019-03-01 12:01:14 -08009377 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009378 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009379 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9380 return;
9381 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009382 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9383 } finally {
9384 Binder.restoreCallingIdentity(identity);
9385 }
9386 }
9387
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009388 @Override
9389 public boolean isApplicationOnUicc(int subId, int appType) {
9390 enforceReadPrivilegedPermission("isApplicationOnUicc");
9391 Phone phone = getPhone(subId);
9392 if (phone == null) {
9393 return false;
9394 }
9395 final long identity = Binder.clearCallingIdentity();
9396 try {
9397 UiccCard uiccCard = phone.getUiccCard();
9398 if (uiccCard == null) {
9399 return false;
9400 }
9401 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9402 if (uiccProfile == null) {
9403 return false;
9404 }
9405 if (TelephonyManager.APPTYPE_SIM <= appType
9406 && appType <= TelephonyManager.APPTYPE_ISIM) {
9407 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9408 }
9409 return false;
9410 } finally {
9411 Binder.restoreCallingIdentity(identity);
9412 }
9413 }
9414
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009415 /**
chen xub4baa772019-04-03 10:23:41 -07009416 * Get whether making changes to modem configurations will trigger reboot.
9417 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009418 */
9419 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009420 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9421 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009422 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009423 mApp, subId, callingPackage, callingFeatureId,
9424 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009425 return false;
9426 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009427 final long identity = Binder.clearCallingIdentity();
9428 try {
9429 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9430 } finally {
9431 Binder.restoreCallingIdentity(identity);
9432 }
9433 }
9434
Nathan Harold29f5f052019-02-15 13:41:57 -08009435 private void updateModemStateMetrics() {
9436 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9437 // TODO: check the state for each modem if the api is ready.
9438 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9439 }
9440
Pengquan Meng3889a572019-01-23 11:16:29 -08009441 @Override
9442 public int[] getSlotsMapping() {
9443 enforceReadPrivilegedPermission("getSlotsMapping");
9444
9445 final long identity = Binder.clearCallingIdentity();
9446 try {
9447 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9448 // All logical slots should have a mapping to a physical slot.
9449 int[] logicalSlotsMapping = new int[phoneCount];
9450 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9451 for (int i = 0; i < slotInfos.length; i++) {
9452 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9453 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9454 }
9455 }
9456 return logicalSlotsMapping;
9457 } finally {
9458 Binder.restoreCallingIdentity(identity);
9459 }
9460 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009461
9462 /**
9463 * Get the IRadio HAL Version
9464 */
9465 @Override
9466 public int getRadioHalVersion() {
9467 Phone phone = getDefaultPhone();
9468 if (phone == null) return -1;
9469 HalVersion hv = phone.getHalVersion();
9470 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9471 return hv.major * 100 + hv.minor;
9472 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009473
9474 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009475 * Get the current calling package name.
9476 * @return the current calling package name
9477 */
9478 @Override
9479 public String getCurrentPackageName() {
9480 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9481 }
9482
9483 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009484 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9485 * corresponding network requests on a subId.
9486 *
9487 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009488 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009489 * 2) APN is un-metered for this subscription, or
9490 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009491 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009492 *
9493 * @return whether data is allowed for a apn type.
9494 *
9495 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009496 */
9497 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009498 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009499 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9500 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009501
9502 // Now that all security checks passes, perform the operation as ourselves.
9503 final long identity = Binder.clearCallingIdentity();
9504 try {
9505 Phone phone = getPhone(subId);
9506 if (phone == null) return false;
9507
Jack Yu41407ee2019-05-13 16:54:09 -07009508 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009509 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9510 } finally {
9511 Binder.restoreCallingIdentity(identity);
9512 }
9513 }
9514
9515 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009516 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009517 enforceReadPrivilegedPermission("isApnMetered");
9518
9519 // Now that all security checks passes, perform the operation as ourselves.
9520 final long identity = Binder.clearCallingIdentity();
9521 try {
9522 Phone phone = getPhone(subId);
9523 if (phone == null) return true; // By default return true.
9524
Jack Yu41407ee2019-05-13 16:54:09 -07009525 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009526 } finally {
9527 Binder.restoreCallingIdentity(identity);
9528 }
9529 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009530
9531 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009532 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9533 int subscriptionId, IBooleanConsumer resultCallback) {
9534 enforceModifyPermission();
9535 long token = Binder.clearCallingIdentity();
9536 try {
9537 Phone phone = getPhone(subscriptionId);
9538 if (phone == null) {
9539 try {
9540 if (resultCallback != null) {
9541 resultCallback.accept(false);
9542 }
9543 } catch (RemoteException e) {
9544 // ignore
9545 }
9546 return;
9547 }
9548 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9549 Pair.create(specifiers, (x) -> {
9550 try {
9551 if (resultCallback != null) {
9552 resultCallback.accept(x);
9553 }
9554 } catch (RemoteException e) {
9555 // ignore
9556 }
9557 });
9558 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9559 } finally {
9560 Binder.restoreCallingIdentity(token);
9561 }
9562 }
9563
9564 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009565 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9566 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009567 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009568 mApp, subId, "getSystemSelectionChannels");
9569 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9570 final long identity = Binder.clearCallingIdentity();
9571 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009572 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9573 if (result instanceof IllegalStateException) {
9574 throw (IllegalStateException) result;
9575 }
9576 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009577 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9578 return specifiers;
9579 } finally {
9580 Binder.restoreCallingIdentity(identity);
9581 }
9582 }
9583
9584 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009585 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009586 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009587 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9588 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9589 if (iccRecords == null) {
9590 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9591 return false;
9592 }
9593 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9594 }
9595
9596 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009597 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9598 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009599 if (callingPackage == null) {
9600 callingPackage = getCurrentPackageName();
9601 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009602 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9603 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009604 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9605 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009606 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9607 }
9608 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9609 Intent intent = new Intent();
9610 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9611 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9612 // Bring up choose default SMS subscription dialog right now
9613 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9614 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9615 mApp.startActivity(intent);
9616 }
chen xud5ca2d52019-05-28 15:20:57 -07009617
9618 @Override
9619 public String getMmsUAProfUrl(int subId) {
9620 //TODO investigate if this API should require proper permission check in R b/133791609
9621 final long identity = Binder.clearCallingIdentity();
9622 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009623 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9624 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9625 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9626 return carrierUAProfUrl;
9627 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009628 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9629 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009630 } finally {
9631 Binder.restoreCallingIdentity(identity);
9632 }
9633 }
9634
9635 @Override
9636 public String getMmsUserAgent(int subId) {
9637 //TODO investigate if this API should require proper permission check in R b/133791609
9638 final long identity = Binder.clearCallingIdentity();
9639 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009640 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9641 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9642 if (!TextUtils.isEmpty(carrierUserAgent)) {
9643 return carrierUserAgent;
9644 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009645 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9646 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009647 } finally {
9648 Binder.restoreCallingIdentity(identity);
9649 }
9650 }
Jack Yub07d4972019-05-28 16:12:25 -07009651
9652 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009653 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9654 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009655
Jack Yub07d4972019-05-28 16:12:25 -07009656 final long identity = Binder.clearCallingIdentity();
9657 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009658 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009659 if (phone == null) return false;
9660
Hall Liua62f5da2020-09-25 10:42:19 -07009661 switch (policy) {
9662 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9663 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9664 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9665 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9666 default:
9667 throw new IllegalArgumentException(policy + " is not a valid policy");
9668 }
Jack Yub07d4972019-05-28 16:12:25 -07009669 } finally {
9670 Binder.restoreCallingIdentity(identity);
9671 }
9672 }
9673
9674 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009675 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009676 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009677 enforceModifyPermission();
9678
changbettyd5c246e2019-12-24 15:40:37 +08009679 final long identity = Binder.clearCallingIdentity();
9680 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009681 Phone phone = getPhone(subscriptionId);
9682 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009683
Hall Liua62f5da2020-09-25 10:42:19 -07009684 switch (policy) {
9685 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9686 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9687 break;
9688 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9689 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9690 break;
9691 default:
9692 throw new IllegalArgumentException(policy + " is not a valid policy");
9693 }
changbettyd5c246e2019-12-24 15:40:37 +08009694 } finally {
9695 Binder.restoreCallingIdentity(identity);
9696 }
9697 }
9698
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009699 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009700 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009701 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9702 * otherwise.
9703 */
9704 @Override
9705 public void setCepEnabled(boolean isCepEnabled) {
9706 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9707
9708 final long identity = Binder.clearCallingIdentity();
9709 try {
9710 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9711 for (Phone phone : PhoneFactory.getPhones()) {
9712 Phone defaultPhone = phone.getImsPhone();
9713 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9714 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9715 ImsPhoneCallTracker imsPhoneCallTracker =
9716 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9717 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9718 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9719 + imsPhone.getMsisdn());
9720 }
9721 }
9722 } finally {
9723 Binder.restoreCallingIdentity(identity);
9724 }
9725 }
allenwtsu46dcc572020-01-08 18:24:03 +08009726
9727 /**
9728 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9729 *
9730 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9731 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9732 * before being read.
9733 */
9734 @Override
9735 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9736 isCompressed) {
9737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9738 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009739 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9740 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9741 }
9742 if (!isImsAvailableOnDevice()) {
9743 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9744 "IMS not available on device.");
9745 }
9746
9747 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009748 try {
Hui Wang761a6682020-10-31 05:12:53 +00009749 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9750 } finally {
9751 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009752 }
9753 }
zoey chene02881a2019-12-30 16:11:23 +08009754
9755 @Override
9756 public boolean isIccLockEnabled(int subId) {
9757 enforceReadPrivilegedPermission("isIccLockEnabled");
9758
9759 // Now that all security checks passes, perform the operation as ourselves.
9760 final long identity = Binder.clearCallingIdentity();
9761 try {
9762 Phone phone = getPhone(subId);
9763 if (phone != null && phone.getIccCard() != null) {
9764 return phone.getIccCard().getIccLockEnabled();
9765 } else {
9766 return false;
9767 }
9768 } finally {
9769 Binder.restoreCallingIdentity(identity);
9770 }
9771 }
9772
9773 /**
9774 * Set the ICC pin lock enabled or disabled.
9775 *
9776 * @return an integer representing the status of IccLock enabled or disabled in the following
9777 * three cases:
9778 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9779 * successfully.
9780 * - Positive number and zero for remaining password attempts.
9781 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9782 *
9783 */
9784 @Override
9785 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9786 enforceModifyPermission();
9787
9788 Phone phone = getPhone(subId);
9789 if (phone == null) {
9790 return 0;
9791 }
9792 // Now that all security checks passes, perform the operation as ourselves.
9793 final long identity = Binder.clearCallingIdentity();
9794 try {
9795 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9796 new Pair<Boolean, String>(enabled, password), phone, null);
9797 return attemptsRemaining;
9798
9799 } catch (Exception e) {
9800 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9801 } finally {
9802 Binder.restoreCallingIdentity(identity);
9803 }
9804 return 0;
9805 }
9806
9807 /**
9808 * Change the ICC password used in ICC pin lock.
9809 *
9810 * @return an integer representing the status of IccLock changed in the following three cases:
9811 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9812 * - Positive number and zero for remaining password attempts.
9813 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9814 *
9815 */
9816 @Override
9817 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9818 enforceModifyPermission();
9819
9820 Phone phone = getPhone(subId);
9821 if (phone == null) {
9822 return 0;
9823 }
9824 // Now that all security checks passes, perform the operation as ourselves.
9825 final long identity = Binder.clearCallingIdentity();
9826 try {
9827 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9828 new Pair<String, String>(oldPassword, newPassword), phone, null);
9829 return attemptsRemaining;
9830
9831 } catch (Exception e) {
9832 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9833 } finally {
9834 Binder.restoreCallingIdentity(identity);
9835 }
9836 return 0;
9837 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009838
9839 /**
9840 * Request for receiving user activity notification
9841 */
9842 @Override
9843 public void requestUserActivityNotification() {
9844 if (!mNotifyUserActivity.get()
9845 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9846 mNotifyUserActivity.set(true);
9847 }
9848 }
9849
9850 /**
9851 * Called when userActivity is signalled in the power manager.
9852 * This is safe to call from any thread, with any window manager locks held or not.
9853 */
9854 @Override
9855 public void userActivity() {
9856 // ***************************************
9857 // * Inherited from PhoneWindowManager *
9858 // ***************************************
9859 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9860 // WITH ITS LOCKS HELD.
9861 //
9862 // This code must be VERY careful about the locks
9863 // it acquires.
9864 // In fact, the current code acquires way too many,
9865 // and probably has lurking deadlocks.
9866
9867 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9868 throw new SecurityException("Only the OS may call notifyUserActivity()");
9869 }
9870
9871 if (mNotifyUserActivity.getAndSet(false)) {
9872 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9873 USER_ACTIVITY_NOTIFICATION_DELAY);
9874 }
9875 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009876
9877 @Override
9878 public boolean canConnectTo5GInDsdsMode() {
9879 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9880 }
Jack Yud10cdd42020-09-28 20:28:01 -07009881
9882 @Override
9883 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9884 String callingFeatureId) {
9885 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9886 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9887 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9888 }
9889
9890 Phone phone = getPhone(subId);
9891 if (phone == null) {
9892 throw new RuntimeException("phone is not available");
9893 }
9894 // Now that all security checks passes, perform the operation as ourselves.
9895 final long identity = Binder.clearCallingIdentity();
9896 try {
9897 return phone.getEquivalentHomePlmns();
9898 } finally {
9899 Binder.restoreCallingIdentity(identity);
9900 }
9901 }
Daniel Bright59e67312020-11-13 11:49:37 -08009902
9903 @Override
9904 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009905 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9906 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009907 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009908 if (radioInterfaceCapabilities == null) {
9909 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009910 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009911 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009912 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009913
Hui Wang641e81c2020-10-12 12:14:23 -07009914 @Override
9915 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9916 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009917 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9918 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9919 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9920 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9921 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009922 if (DBG) {
9923 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9924 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9925 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9926 }
9927
9928 if (!SubscriptionManager.isValidSubscriptionId(subId)
9929 || appType < TelephonyManager.APPTYPE_UNKNOWN
9930 || appType > TelephonyManager.APPTYPE_ISIM
9931 || nafUrl == null || securityProtocol == null || callback == null) {
9932 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9933 if (callback != null) {
9934 try {
9935 callback.onAuthenticationFailure(
9936 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9937 } catch (RemoteException exception) {
9938 log("Fail to notify onAuthenticationFailure due to " + exception);
9939 }
9940 return;
9941 }
9942 }
9943
9944 final long token = Binder.clearCallingIdentity();
9945 try {
9946 getGbaManager(subId).bootstrapAuthenticationRequest(
9947 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9948 forceBootStrapping, callback));
9949 } finally {
9950 Binder.restoreCallingIdentity(token);
9951 }
9952 }
9953
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009954 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009955 * Attempts to set the radio power state for all phones for thermal reason.
9956 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009957 * requested radio power state will actually be set. See {@link
9958 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9959 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009960 * @param enable {@code true} if trying to turn radio on.
9961 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9962 * false}.
9963 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009964 private boolean setRadioPowerForThermal(boolean enable) {
9965 boolean isPhoneAvailable = false;
9966 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9967 Phone phone = PhoneFactory.getPhone(i);
9968 if (phone != null) {
9969 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9970 isPhoneAvailable = true;
9971 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009972 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009973
9974 // return true if successfully informed the phone object about the thermal radio power
9975 // request.
9976 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009977 }
9978
9979 private int handleDataThrottlingRequest(int subId,
9980 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009981 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9982 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9983 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9984 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9985 throw new IllegalArgumentException("modem does not support data throttling");
9986 }
9987
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009988 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9989 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009990 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009991 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9992 }
9993
9994 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9995
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009996 if (isDataThrottlingSupported) {
9997 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009998 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009999 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10000 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10001 } else if (thermalMitigationResult
10002 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010003 log("Modem likely does not support data throttling on secondary carrier. Data " +
10004 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10005 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010006 }
10007 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010008 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010009
10010 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010011 }
10012
Jack Nudelman644b91a2021-03-12 14:09:48 -080010013 private static List<String> getThermalMitigationAllowlist(Context context) {
10014 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10015 for (String pckg : context.getResources()
10016 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10017 sThermalMitigationAllowlistedPackages.add(pckg);
10018 }
10019 }
10020
10021 return sThermalMitigationAllowlistedPackages;
10022 }
10023
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010024 private boolean isAnyPhoneInEmergencyState() {
10025 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10026 if (tm.isInEmergencyCall()) {
10027 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10028 return true;
10029 }
10030 for (Phone phone : PhoneFactory.getPhones()) {
10031 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10032 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10033 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10034 + phone.isInEcm());
10035 return true;
10036 }
10037 }
10038
10039 return false;
10040 }
10041
Jack Nudelman644b91a2021-03-12 14:09:48 -080010042 /**
10043 * Used by shell commands to add an authorized package name for thermal mitigation.
10044 * @param packageName name of package to be allowlisted
10045 * @param context
10046 */
10047 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10048 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10049 sThermalMitigationAllowlistedPackages.add(packageName);
10050 }
10051
10052 /**
10053 * Used by shell commands to remove an authorized package name for thermal mitigation.
10054 * @param packageName name of package to remove from allowlist
10055 * @param context
10056 */
10057 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10058 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10059 sThermalMitigationAllowlistedPackages.remove(packageName);
10060 }
10061
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010062 /**
10063 * Thermal mitigation request to control functionalities at modem.
10064 *
10065 * @param subId the id of the subscription.
10066 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010067 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010068 *
10069 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10070 */
10071 @Override
10072 @ThermalMitigationResult
10073 public int sendThermalMitigationRequest(
10074 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010075 ThermalMitigationRequest thermalMitigationRequest,
10076 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010077 enforceModifyPermission();
10078
Jack Nudelman644b91a2021-03-12 14:09:48 -080010079 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10080 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10081 .contains(callingPackage)) {
10082 throw new SecurityException("Calling package must be configured in the device config. "
10083 + "calling package: " + callingPackage);
10084 }
10085
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010086 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10087 final long identity = Binder.clearCallingIdentity();
10088
10089 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10090 try {
10091 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10092 switch (thermalMitigationAction) {
10093 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10094 thermalMitigationResult =
10095 handleDataThrottlingRequest(subId,
10096 thermalMitigationRequest.getDataThrottlingRequest());
10097 break;
10098 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10099 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10100 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10101 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10102 }
10103
10104 // Ensure that radio is on. If not able to power on due to phone being
10105 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010106 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010107 thermalMitigationResult =
10108 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10109 break;
10110 }
10111
10112 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10113 false);
10114 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10115 break;
10116 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10117 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10118 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10119 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10120 }
10121
10122 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10123 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010124 Phone phone = getPhone(subId);
10125 if (phone == null) {
10126 thermalMitigationResult =
10127 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10128 break;
10129 }
10130
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010131 TelephonyConnectionService service =
10132 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010133 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010134 Log.e(LOG_TAG, "An emergency call is pending");
10135 thermalMitigationResult =
10136 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10137 break;
10138 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010139 thermalMitigationResult =
10140 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10141 break;
10142 }
10143 } else {
10144 thermalMitigationResult =
10145 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10146 break;
10147 }
10148
10149 // Turn radio off. If not able to power off due to phone being unavailable,
10150 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010151 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010152 thermalMitigationResult =
10153 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10154 break;
10155 }
10156 thermalMitigationResult =
10157 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10158 break;
10159 default:
10160 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10161 + "not exist. Requested action: " + thermalMitigationAction);
10162 }
10163 } catch (IllegalArgumentException e) {
10164 throw e;
10165 } catch (Exception e) {
10166 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10167 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10168 } finally {
10169 Binder.restoreCallingIdentity(identity);
10170 }
10171
10172 if (DBG) {
10173 log("thermalMitigationRequest returning with thermalMitigationResult: "
10174 + thermalMitigationResult);
10175 }
10176
10177 return thermalMitigationResult;
10178 }
Hui Wang641e81c2020-10-12 12:14:23 -070010179
10180 /**
10181 * Set the GbaService Package Name that Telephony will bind to.
10182 *
10183 * @param subId The sim that the GbaService is associated with.
10184 * @param packageName The name of the package to be replaced with.
10185 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10186 */
10187 @Override
10188 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10189 enforceModifyPermission();
10190
10191 final long identity = Binder.clearCallingIdentity();
10192 try {
10193 return getGbaManager(subId).overrideServicePackage(packageName);
10194 } finally {
10195 Binder.restoreCallingIdentity(identity);
10196 }
10197 }
10198
10199 /**
10200 * Return the package name of the currently bound GbaService.
10201 *
10202 * @param subId The sim that the GbaService is associated with.
10203 * @return the package name of the GbaService configuration, null if GBA is not supported.
10204 */
10205 @Override
10206 public String getBoundGbaService(int subId) {
10207 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10208
10209 final long identity = Binder.clearCallingIdentity();
10210 try {
10211 return getGbaManager(subId).getServicePackage();
10212 } finally {
10213 Binder.restoreCallingIdentity(identity);
10214 }
10215 }
10216
10217 /**
10218 * Set the release time for telephony to unbind GbaService.
10219 *
10220 * @param subId The sim that the GbaService is associated with.
10221 * @param interval The release time to unbind GbaService by millisecond.
10222 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10223 */
10224 @Override
10225 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10226 enforceModifyPermission();
10227
10228 final long identity = Binder.clearCallingIdentity();
10229 try {
10230 return getGbaManager(subId).overrideReleaseTime(interval);
10231 } finally {
10232 Binder.restoreCallingIdentity(identity);
10233 }
10234 }
10235
10236 /**
10237 * Return the release time for telephony to unbind GbaService.
10238 *
10239 * @param subId The sim that the GbaService is associated with.
10240 * @return The release time to unbind GbaService by millisecond.
10241 */
10242 @Override
10243 public int getGbaReleaseTime(int subId) {
10244 enforceReadPrivilegedPermission("getGbaReleaseTime");
10245
10246 final long identity = Binder.clearCallingIdentity();
10247 try {
10248 return getGbaManager(subId).getReleaseTime();
10249 } finally {
10250 Binder.restoreCallingIdentity(identity);
10251 }
10252 }
10253
10254 private GbaManager getGbaManager(int subId) {
10255 GbaManager instance = GbaManager.getInstance(subId);
10256 if (instance == null) {
10257 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10258 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10259 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10260 }
10261 return instance;
10262 }
Hui Wang761a6682020-10-31 05:12:53 +000010263
10264 /**
10265 * indicate whether the device and the carrier can support
10266 * RCS VoLTE single registration.
10267 */
10268 @Override
10269 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010270 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10271 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10272 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10273 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010274
10275 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10276 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10277 }
10278
10279 final long identity = Binder.clearCallingIdentity();
10280 try {
10281 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10282 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010283 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10284 if (isCapable != null) {
10285 return isCapable;
10286 }
Hui Wang761a6682020-10-31 05:12:53 +000010287 }
Hui Wang67af90e2021-06-04 16:57:15 -070010288 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10289 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010290 } finally {
10291 Binder.restoreCallingIdentity(identity);
10292 }
10293 }
10294
10295 /**
10296 * Register RCS provisioning callback.
10297 */
10298 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010299 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010300 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010301 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010302 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010303 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10304 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010305
10306 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10307 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10308 }
10309 if (!isImsAvailableOnDevice()) {
10310 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10311 "IMS not available on device.");
10312 }
10313
10314 final long identity = Binder.clearCallingIdentity();
10315 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010316 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010317 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010318 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10319 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010320 }
Hui Wang761a6682020-10-31 05:12:53 +000010321 } finally {
10322 Binder.restoreCallingIdentity(identity);
10323 }
10324 }
10325
10326 /**
10327 * Unregister RCS provisioning callback.
10328 */
10329 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010330 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010331 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010332 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010333 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010334 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10335 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010336
10337 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10338 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10339 }
10340 if (!isImsAvailableOnDevice()) {
10341 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10342 "IMS not available on device.");
10343 }
10344
10345 final long identity = Binder.clearCallingIdentity();
10346 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010347 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010348 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010349 } finally {
10350 Binder.restoreCallingIdentity(identity);
10351 }
10352 }
10353
10354 /**
10355 * trigger RCS reconfiguration.
10356 */
10357 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010358 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10359 "triggerRcsReconfiguration",
10360 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010361
10362 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10363 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10364 }
10365 if (!isImsAvailableOnDevice()) {
10366 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10367 "IMS not available on device.");
10368 }
10369
10370 final long identity = Binder.clearCallingIdentity();
10371 try {
10372 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10373 } finally {
10374 Binder.restoreCallingIdentity(identity);
10375 }
10376 }
10377
10378 /**
10379 * Provide the client configuration parameters of the RCS application.
10380 */
10381 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010382 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10383 "setRcsClientConfiguration",
10384 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010385
10386 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10387 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10388 }
10389 if (!isImsAvailableOnDevice()) {
10390 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10391 "IMS not available on device.");
10392 }
10393
10394 final long identity = Binder.clearCallingIdentity();
10395
10396 try {
10397 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10398 if (configBinder == null) {
10399 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010400 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10401 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010402 } else {
10403 configBinder.setRcsClientConfiguration(rcc);
10404 }
joonhunshinfa314642021-09-17 06:33:39 +000010405
10406 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10407 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010408 } catch (RemoteException e) {
10409 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010410 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10411 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010412 } finally {
10413 Binder.restoreCallingIdentity(identity);
10414 }
10415 }
10416
10417 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010418 * Enables or disables the test mode for RCS VoLTE single registration.
10419 */
10420 @Override
10421 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10422 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10423 "setRcsSingleRegistrationTestModeEnabled");
10424
10425 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10426 }
10427
10428 /**
10429 * Gets the test mode for RCS VoLTE single registration.
10430 */
10431 @Override
10432 public boolean getRcsSingleRegistrationTestModeEnabled() {
10433 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10434 "getRcsSingleRegistrationTestModeEnabled");
10435
10436 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10437 }
10438
10439 /**
Hui Wang761a6682020-10-31 05:12:53 +000010440 * Overrides the config of RCS VoLTE single registration enabled for the device.
10441 */
10442 @Override
10443 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10444 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10445 "setDeviceSingleRegistrationEnabledOverride");
10446 enforceModifyPermission();
10447
10448 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10449 : Boolean.parseBoolean(enabledStr);
10450 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010451 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010452 }
10453
10454 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010455 * Sends a device to device communication message. Only usable via shell.
10456 * @param message message to send.
10457 * @param value message value.
10458 */
10459 @Override
10460 public void sendDeviceToDeviceMessage(int message, int value) {
10461 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010462 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010463 enforceModifyPermission();
10464
10465 final long identity = Binder.clearCallingIdentity();
10466 try {
10467 TelephonyConnectionService service =
10468 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10469 if (service == null) {
10470 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10471 return;
10472 }
10473 service.sendTestDeviceToDeviceMessage(message, value);
10474 } finally {
10475 Binder.restoreCallingIdentity(identity);
10476 }
10477 }
10478
Tyler Gunnbabbda02021-02-10 11:05:02 -080010479 /**
10480 * Sets the specified device to device transport active.
10481 * @param transport The transport to set active.
10482 */
10483 @Override
10484 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10485 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10486 "setActiveDeviceToDeviceTransport");
10487 enforceModifyPermission();
10488
10489 final long identity = Binder.clearCallingIdentity();
10490 try {
10491 TelephonyConnectionService service =
10492 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10493 if (service == null) {
10494 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10495 return;
10496 }
10497 service.setActiveDeviceToDeviceTransport(transport);
10498 } finally {
10499 Binder.restoreCallingIdentity(identity);
10500 }
10501 }
Tyler Gunn92479152021-01-20 16:30:10 -080010502
Tyler Gunnd4575212021-05-03 14:46:49 -070010503 @Override
10504 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10505 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10506 "setDeviceToDeviceForceEnabled");
10507
10508 final long identity = Binder.clearCallingIdentity();
10509 try {
10510 Arrays.stream(PhoneFactory.getPhones()).forEach(
10511 p -> {
10512 Phone thePhone = p.getImsPhone();
10513 if (thePhone != null && thePhone instanceof ImsPhone) {
10514 ImsPhone imsPhone = (ImsPhone) thePhone;
10515 CallTracker tracker = imsPhone.getCallTracker();
10516 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10517 ImsPhoneCallTracker imsPhoneCallTracker =
10518 (ImsPhoneCallTracker) tracker;
10519 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10520 }
10521 }
10522 }
10523 );
10524 } finally {
10525 Binder.restoreCallingIdentity(identity);
10526 }
10527 }
10528
Tyler Gunn92479152021-01-20 16:30:10 -080010529 /**
Hui Wang761a6682020-10-31 05:12:53 +000010530 * Gets the config of RCS VoLTE single registration enabled for the device.
10531 */
10532 @Override
10533 public boolean getDeviceSingleRegistrationEnabled() {
10534 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10535 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10536 }
10537
10538 /**
10539 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10540 */
10541 @Override
10542 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10543 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10544 "setCarrierSingleRegistrationEnabledOverride");
10545 enforceModifyPermission();
10546
10547 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10548 : Boolean.parseBoolean(enabledStr);
10549 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10550 subId, enabled);
10551 }
10552
10553 /**
10554 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10555 */
10556 @Override
10557 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10558 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10559 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10560 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010561
10562 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010563 * Overrides the ims feature validation result
10564 */
10565 @Override
10566 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10567 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10568 "setImsFeatureValidationOverride");
10569
10570 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10571 : Boolean.parseBoolean(enabledStr);
10572 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10573 subId, enabled);
10574 }
10575
10576 /**
10577 * Gets the ims feature validation override value
10578 */
10579 @Override
10580 public boolean getImsFeatureValidationOverride(int subId) {
10581 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10582 "getImsFeatureValidationOverride");
10583 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10584 }
10585
10586 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010587 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10588 * their mobile plan.
10589 */
10590 @Override
10591 public String getMobileProvisioningUrl() {
10592 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10593 final long identity = Binder.clearCallingIdentity();
10594 try {
10595 return getDefaultPhone().getMobileProvisioningUrl();
10596 } finally {
10597 Binder.restoreCallingIdentity(identity);
10598 }
10599 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010600
James.cf Linbcdf8b32021-01-14 16:44:13 +080010601 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010602 * Get the EAB contact from the EAB database.
10603 */
10604 @Override
10605 public String getContactFromEab(String contact) {
10606 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10607 enforceModifyPermission();
10608 final long identity = Binder.clearCallingIdentity();
10609 try {
10610 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10611 } finally {
10612 Binder.restoreCallingIdentity(identity);
10613 }
10614 }
10615
10616 /**
Calvin Pana1434322021-07-01 19:27:01 +080010617 * Get the EAB capability from the EAB database.
10618 */
10619 @Override
10620 public String getCapabilityFromEab(String contact) {
10621 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10622 enforceModifyPermission();
10623 final long identity = Binder.clearCallingIdentity();
10624 try {
10625 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10626 } finally {
10627 Binder.restoreCallingIdentity(identity);
10628 }
10629 }
10630
10631 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010632 * Remove the EAB contacts from the EAB database.
10633 */
10634 @Override
10635 public int removeContactFromEab(int subId, String contacts) {
10636 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10637 enforceModifyPermission();
10638 final long identity = Binder.clearCallingIdentity();
10639 try {
10640 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10641 } finally {
10642 Binder.restoreCallingIdentity(identity);
10643 }
10644 }
10645
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010646 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010647 public boolean getDeviceUceEnabled() {
10648 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10649 final long identity = Binder.clearCallingIdentity();
10650 try {
10651 return mApp.getDeviceUceEnabled();
10652 } finally {
10653 Binder.restoreCallingIdentity(identity);
10654 }
10655 }
10656
10657 @Override
10658 public void setDeviceUceEnabled(boolean isEnabled) {
10659 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10660 final long identity = Binder.clearCallingIdentity();
10661 try {
10662 mApp.setDeviceUceEnabled(isEnabled);
10663 } finally {
10664 Binder.restoreCallingIdentity(identity);
10665 }
10666 }
10667
Brad Ebinger14d467f2021-02-12 06:18:28 +000010668 /**
10669 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10670 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10671 */
10672 // Used for SHELL command only right now.
10673 @Override
10674 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10675 List<String> featureTags) {
10676 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10677 "addUceRegistrationOverrideShell");
10678 final long identity = Binder.clearCallingIdentity();
10679 try {
10680 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10681 new ArraySet<>(featureTags));
10682 } catch (ImsException e) {
10683 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10684 } finally {
10685 Binder.restoreCallingIdentity(identity);
10686 }
10687 }
10688
10689 /**
10690 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10691 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10692 */
10693 // Used for SHELL command only right now.
10694 @Override
10695 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10696 List<String> featureTags) {
10697 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10698 "removeUceRegistrationOverrideShell");
10699 final long identity = Binder.clearCallingIdentity();
10700 try {
10701 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10702 new ArraySet<>(featureTags));
10703 } catch (ImsException e) {
10704 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10705 } finally {
10706 Binder.restoreCallingIdentity(identity);
10707 }
10708 }
10709
10710 /**
10711 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10712 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10713 */
10714 // Used for SHELL command only right now.
10715 @Override
10716 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10717 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10718 "clearUceRegistrationOverrideShell");
10719 final long identity = Binder.clearCallingIdentity();
10720 try {
10721 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10722 } catch (ImsException e) {
10723 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10724 } finally {
10725 Binder.restoreCallingIdentity(identity);
10726 }
10727 }
10728
10729 /**
10730 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10731 */
10732 // Used for SHELL command only right now.
10733 @Override
10734 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10735 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10736 "getLatestRcsContactUceCapabilityShell");
10737 final long identity = Binder.clearCallingIdentity();
10738 try {
10739 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10740 } catch (ImsException e) {
10741 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10742 } finally {
10743 Binder.restoreCallingIdentity(identity);
10744 }
10745 }
10746
10747 /**
10748 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10749 * device does not have an active PUBLISH.
10750 */
10751 // Used for SHELL command only right now.
10752 @Override
10753 public String getLastUcePidfXmlShell(int subId) {
10754 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10755 final long identity = Binder.clearCallingIdentity();
10756 try {
10757 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10758 } catch (ImsException e) {
10759 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10760 } finally {
10761 Binder.restoreCallingIdentity(identity);
10762 }
10763 }
10764
James.cf Line8713a42021-04-29 16:04:26 +080010765 /**
10766 * Remove UCE requests cannot be sent to the network status.
10767 */
10768 // Used for SHELL command only right now.
10769 @Override
10770 public boolean removeUceRequestDisallowedStatus(int subId) {
10771 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10772 final long identity = Binder.clearCallingIdentity();
10773 try {
10774 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10775 } catch (ImsException e) {
10776 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10777 } finally {
10778 Binder.restoreCallingIdentity(identity);
10779 }
10780 }
10781
James.cf Lin0fc71b02021-05-25 01:37:38 +080010782 /**
10783 * Remove UCE requests cannot be sent to the network status.
10784 */
10785 // Used for SHELL command only.
10786 @Override
10787 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10788 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10789 final long identity = Binder.clearCallingIdentity();
10790 try {
10791 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10792 } catch (ImsException e) {
10793 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10794 } finally {
10795 Binder.restoreCallingIdentity(identity);
10796 }
10797 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010798
James.cf Lin4b784aa2021-01-31 03:25:15 +080010799 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010800 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10801 String callingPackage) {
10802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10803 mApp, subId, "setSignalStrengthUpdateRequest");
10804
10805 final int callingUid = Binder.getCallingUid();
10806 // Verify that tha callingPackage belongs to the calling UID
10807 mApp.getSystemService(AppOpsManager.class)
10808 .checkPackage(callingUid, callingPackage);
10809
10810 validateSignalStrengthUpdateRequest(request, callingUid);
10811
10812 final long identity = Binder.clearCallingIdentity();
10813 try {
10814 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10815 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10816
10817 if (result instanceof IllegalStateException) {
10818 throw (IllegalStateException) result;
10819 }
10820 } finally {
10821 Binder.restoreCallingIdentity(identity);
10822 }
10823 }
10824
10825 @Override
10826 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10827 String callingPackage) {
10828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10829 mApp, subId, "clearSignalStrengthUpdateRequest");
10830
10831 final int callingUid = Binder.getCallingUid();
10832 // Verify that tha callingPackage belongs to the calling UID
10833 mApp.getSystemService(AppOpsManager.class)
10834 .checkPackage(callingUid, callingPackage);
10835
10836 final long identity = Binder.clearCallingIdentity();
10837 try {
10838 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10839 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10840
10841 if (result instanceof IllegalStateException) {
10842 throw (IllegalStateException) result;
10843 }
10844 } finally {
10845 Binder.restoreCallingIdentity(identity);
10846 }
10847 }
10848
10849 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10850 int callingUid) {
10851 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10852 // phone/system process do not have further restriction on request
10853 return;
10854 }
10855
10856 // Applications has restrictions on how to use the request:
10857 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10858 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10859 // This is not system caller which has been checked above
10860 throw new IllegalArgumentException(
10861 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10862 }
10863
10864 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10865 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10866 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10867 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10868 || info.isEnabled()) {
10869 throw new IllegalArgumentException(
10870 "Only system can set hide fields in SignalThresholdInfo");
10871 }
10872
10873 // Thresholds length for each RAN need in range. This has been validated in
10874 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10875 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10876 final int[] thresholds = info.getThresholds();
10877 Objects.requireNonNull(thresholds);
10878 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10879 || thresholds.length
10880 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10881 throw new IllegalArgumentException(
10882 "thresholds length is out of range: " + thresholds.length);
10883 }
10884 }
10885 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010886
10887 /**
10888 * Gets the current phone capability.
10889 *
10890 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10891 * @return the PhoneCapability which describes the data connection capability of modem.
10892 * It's used to evaluate possible phone config change, for example from single
10893 * SIM device to multi-SIM device.
10894 */
10895 @Override
10896 public PhoneCapability getPhoneCapability() {
10897 enforceReadPrivilegedPermission("getPhoneCapability");
10898 final long identity = Binder.clearCallingIdentity();
10899 try {
10900 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10901 } finally {
10902 Binder.restoreCallingIdentity(identity);
10903 }
10904 }
Michele Berionne5e411512020-11-13 02:36:59 +000010905
10906 /**
10907 * Prepare TelephonyManager for an unattended reboot. The reboot is
10908 * required to be done shortly after the API is invoked.
10909 */
10910 @Override
10911 @TelephonyManager.PrepareUnattendedRebootResult
10912 public int prepareForUnattendedReboot() {
Rafael Higuera Silva7badcc42021-09-20 15:32:01 +000010913 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000010914 enforceRebootPermission();
10915
10916 final long identity = Binder.clearCallingIdentity();
10917 try {
Rafael Higuera Silva7badcc42021-09-20 15:32:01 +000010918 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000010919 } finally {
10920 Binder.restoreCallingIdentity(identity);
10921 }
10922 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010923
10924 /**
10925 * Request to get the current slicing configuration including URSP rules and
10926 * NSSAIs (configured, allowed and rejected).
10927 *
10928 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10929 */
10930 @Override
10931 public void getSlicingConfig(ResultReceiver callback) {
10932 enforceReadPrivilegedPermission("getSlicingConfig");
10933
10934 final long identity = Binder.clearCallingIdentity();
10935 try {
10936 Phone phone = getDefaultPhone();
10937 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10938 } finally {
10939 Binder.restoreCallingIdentity(identity);
10940 }
10941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010942}