blob: fcdbd480dd46fb07d8d8af1cbdfcc90a34bac237 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000034import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080035import android.app.role.RoleManager;
Chen Xu540470b2021-12-14 17:15:47 -080036import android.compat.Compatibility;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080045import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070046import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.net.Uri;
48import android.os.AsyncResult;
49import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080050import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.Bundle;
52import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070053import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.Looper;
55import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080057import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070058import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070059import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080060import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080061import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070062import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070063import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080064import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070066import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070067import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070068import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070069import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080070import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070071import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090072import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080073import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080074import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070075import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080076import android.telephony.AccessNetworkConstants;
77import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070078import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080079import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080080import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070081import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080082import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070083import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080084import android.telephony.CellIdentityCdma;
85import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070087import android.telephony.CellInfoGsm;
88import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070089import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080090import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070091import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070092import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070093import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080094import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070095import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080096import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070097import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080098import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080099import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700100import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800101import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800103import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800104import android.telephony.SignalStrengthUpdateRequest;
105import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800106import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800107import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800108import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700109import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700110import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800111import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800112import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800113import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000114import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000115import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000116import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700117import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700118import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800119import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800120import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800121import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700122import android.telephony.gba.GbaAuthRequest;
123import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700124import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800125import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000126import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000127import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700128import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700129import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800130import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700131import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800132import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700133import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000134import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700135import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800136import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800137import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800138import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800139import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800141import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700142import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800144import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800145
Andrew Lee312e8172014-10-23 17:01:36 -0700146import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800147import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800148import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800149import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800150import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700151import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700152import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700153import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800154import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700155import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700156import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800157import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700159import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800160import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800161import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800162import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700163import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000164import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800166import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800169import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700170import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700171import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700172import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700174import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800175import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700176import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700177import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700178import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700179import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800180import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800181import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700182import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700183import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700184import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800185import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800186import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800187import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700188import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800189import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700190import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800191import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700192import com.android.internal.telephony.imsphone.ImsPhone;
193import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000194import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800195import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700196import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700197import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800198import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700199import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800200import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700201import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800202import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000204import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800205import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000206import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800207import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700208import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700209import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800210import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800211import com.android.phone.callcomposer.CallComposerPictureManager;
212import com.android.phone.callcomposer.CallComposerPictureTransfer;
213import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700214import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700215import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800216import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700217import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700218import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800219import com.android.services.telephony.TelecomAccountRegistry;
220import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800221import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800222
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700224import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.io.IOException;
226import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700227import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800229import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000230import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800231import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800232import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800233import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100234import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800235import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700236import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800237import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800238import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800239import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800240import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800241import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242
243/**
244 * Implementation of the ITelephony interface.
245 */
Santos Cordon117fee72014-05-16 17:56:12 -0700246public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247 private static final String LOG_TAG = "PhoneInterfaceManager";
248 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
249 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800250 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251
252 // Message codes used with mMainThreadHandler
253 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700254 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
255 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700256 private static final int CMD_OPEN_CHANNEL = 9;
257 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
258 private static final int CMD_CLOSE_CHANNEL = 11;
259 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800260 private static final int CMD_NV_READ_ITEM = 13;
261 private static final int EVENT_NV_READ_ITEM_DONE = 14;
262 private static final int CMD_NV_WRITE_ITEM = 15;
263 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
264 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
265 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700266 private static final int CMD_RESET_MODEM_CONFIG = 19;
267 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800268 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
269 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800270 private static final int CMD_SEND_ENVELOPE = 25;
271 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000272 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
273 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700274 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
275 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
276 private static final int CMD_EXCHANGE_SIM_IO = 31;
277 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800278 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
279 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700280 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
281 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700282 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
283 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700284 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
285 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
286 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
287 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700288 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
289 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
290 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
291 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700292 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800293 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
294 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000295 private static final int CMD_SWITCH_SLOTS = 50;
296 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700297 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
298 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
299 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
300 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
301 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
302 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
303 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
304 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700305 private static final int CMD_GET_ALL_CELL_INFO = 60;
306 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
307 private static final int CMD_GET_CELL_LOCATION = 62;
308 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700309 private static final int CMD_MODEM_REBOOT = 64;
310 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700311 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
312 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800313 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
314 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700315 private static final int CMD_GET_MODEM_STATUS = 70;
316 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700317 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
318 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700319 private static final int CMD_ERASE_MODEM_CONFIG = 74;
320 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800321 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
322 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
323 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
324 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800325 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
326 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800327 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800328 private static final int CMD_GET_CALL_FORWARDING = 83;
329 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
330 private static final int CMD_SET_CALL_FORWARDING = 85;
331 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
332 private static final int CMD_GET_CALL_WAITING = 87;
333 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
334 private static final int CMD_SET_CALL_WAITING = 89;
335 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700336 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
337 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
338 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
339 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700340 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
341 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800342 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
343 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800344 private static final int CMD_SET_DATA_THROTTLING = 99;
345 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800346 private static final int CMD_SET_SIM_POWER = 101;
347 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800348 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
349 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
350 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
351 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800352 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
353 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000354 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800355 private static final int CMD_GET_SLICING_CONFIG = 110;
356 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800357 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700358 private static final int CMD_ENABLE_VONR = 113;
359 private static final int EVENT_ENABLE_VONR_DONE = 114;
360 private static final int CMD_IS_VONR_ENABLED = 115;
361 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800363 // Parameters of select command.
364 private static final int SELECT_COMMAND = 0xA4;
365 private static final int SELECT_P1 = 0x04;
366 private static final int SELECT_P2 = 0;
367 private static final int SELECT_P3 = 0x10;
368
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 /** The singleton instance. */
370 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800371 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
Wink Saville3ab207e2014-11-20 13:07:20 -0800373 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800375 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700376 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700378 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800379 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800380 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800381 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700382 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800383 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
Peter Wangdafb9ac2020-01-15 14:13:38 -0800385 /** User Activity */
386 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800387 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
388
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700389 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
390
Derek Tan97ebb422014-09-05 16:55:38 -0700391 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
392 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800393 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800394 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700395
Michelecea4cf22018-12-21 15:00:11 -0800396 // String to store multi SIM allowed
397 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
398
Derek Tan740e1672017-06-27 14:56:27 -0700399 // The AID of ISD-R.
400 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
401
yinxub1bed742017-04-17 11:45:04 -0700402 private NetworkScanRequestTracker mNetworkScanRequestTracker;
403
David Kelly5e06a7f2018-03-12 14:10:59 +0000404 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
405 private static final int MANUFACTURER_CODE_LENGTH = 8;
406
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800407 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800408 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800409
Derek Tan89e89d42014-07-08 17:00:10 -0700410 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700411 * Experiment flag to enable erase modem config on reset network, default value is false
412 */
413 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
414 "reset_network_erase_modem_config_enabled";
415
Rambo Wang0f050d82021-02-12 11:43:36 -0800416 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800417
sandeepjsb6c87872021-09-27 15:34:44 +0000418 /**
419 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
420 * one ICCID active at the same time.
421 * Apps should use below API signatures if targeting SDK is T and beyond.
422 *
423 * @hide
424 */
425 @ChangeId
426 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
427 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800428
Naina Nallurid63128d2019-09-17 14:10:30 -0700429 /**
Chen Xu540470b2021-12-14 17:15:47 -0800430 * Apps targeting on Android T and beyond will get exception whenever icc close channel
431 * operation fails.
432 */
433 @ChangeId
434 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
435 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
436
437 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 * A request object to use for transmitting data to an ICC.
439 */
440 private static final class IccAPDUArgument {
441 public int channel, cla, command, p1, p2, p3;
442 public String data;
443
444 public IccAPDUArgument(int channel, int cla, int command,
445 int p1, int p2, int p3, String data) {
446 this.channel = channel;
447 this.cla = cla;
448 this.command = command;
449 this.p1 = p1;
450 this.p2 = p2;
451 this.p3 = p3;
452 this.data = data;
453 }
454 }
455
456 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700457 * A request object to use for transmitting data to an ICC.
458 */
459 private static final class ManualNetworkSelectionArgument {
460 public OperatorInfo operatorInfo;
461 public boolean persistSelection;
462
463 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
464 this.operatorInfo = operatorInfo;
465 this.persistSelection = persistSelection;
466 }
467 }
468
469 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
471 * request after sending. The main thread will notify the request when it is complete.
472 */
473 private static final class MainThreadRequest {
474 /** The argument to use for the request */
475 public Object argument;
476 /** The result of the request that is run on the main thread */
477 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800478 // The subscriber id that this request applies to. Defaults to
479 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
480 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481
Nathan Harold92bed182018-10-12 18:16:49 -0700482 // In cases where subId is unavailable, the caller needs to specify the phone.
483 public Phone phone;
484
vagdeviaf9a5b92018-08-15 16:01:53 -0700485 public WorkSource workSource;
486
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700487 public MainThreadRequest(Object argument) {
488 this.argument = argument;
489 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800490
Nathan Harold92bed182018-10-12 18:16:49 -0700491 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
492 this.argument = argument;
493 if (phone != null) {
494 this.phone = phone;
495 }
496 this.workSource = workSource;
497 }
498
vagdeviaf9a5b92018-08-15 16:01:53 -0700499 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800500 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800501 if (subId != null) {
502 this.subId = subId;
503 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700504 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 }
507
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800508 private static final class IncomingThirdPartyCallArgs {
509 public final ComponentName component;
510 public final String callId;
511 public final String callerDisplayName;
512
513 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
514 String callerDisplayName) {
515 this.component = component;
516 this.callId = callId;
517 this.callerDisplayName = callerDisplayName;
518 }
519 }
520
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 /**
522 * A handler that processes messages on the main thread in the phone process. Since many
523 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
524 * inbound binder threads to the main thread in the phone process. The Binder thread
525 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
526 * on, which will be notified when the operation completes and will contain the result of the
527 * request.
528 *
529 * <p>If a MainThreadRequest object is provided in the msg.obj field,
530 * note that request.result must be set to something non-null for the calling thread to
531 * unblock.
532 */
533 private final class MainThreadHandler extends Handler {
534 @Override
535 public void handleMessage(Message msg) {
536 MainThreadRequest request;
537 Message onCompleted;
538 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000539 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800541 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542
543 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 case CMD_HANDLE_USSD_REQUEST: {
545 request = (MainThreadRequest) msg.obj;
546 final Phone phone = getPhoneFromRequest(request);
547 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
548 String ussdRequest = ussdObject.first;
549 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700550
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 if (!isUssdApiAllowed(request.subId)) {
552 // Carrier does not support use of this API, return failure.
553 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
554 UssdResponse response = new UssdResponse(ussdRequest, null);
555 Bundle returnData = new Bundle();
556 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
557 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700558
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 request.result = true;
560 notifyRequester(request);
561 return;
562 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700563
Pengquan Menga1bb6272018-09-06 09:59:22 -0700564 try {
565 request.result = phone != null
566 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
567 } catch (CallStateException cse) {
568 request.result = false;
569 }
570 // Wake up the requesting thread
571 notifyRequester(request);
572 break;
pkanwar32d516d2016-10-14 19:37:38 -0700573 }
574
Yorke Lee716f67e2015-06-17 15:39:16 -0700575 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700576 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700577 final Phone phone = getPhoneFromRequest(request);
578 request.result = phone != null ?
579 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
580 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700581 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700585
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000589 uiccPort = getUiccPortFromRequest(request);
590 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 loge("iccTransmitApduLogicalChannel: No UICC");
592 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
596 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000597 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 iccArgument.channel, iccArgument.cla, iccArgument.command,
599 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 break;
603
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 ar = (AsyncResult) msg.obj;
606 request = (MainThreadRequest) ar.userObj;
607 if (ar.exception == null && ar.result != null) {
608 request.result = ar.result;
609 } else {
610 request.result = new IccIoResult(0x6F, 0, (byte[])null);
611 if (ar.result == null) {
612 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800613 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800615 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 } else {
617 loge("iccTransmitApduLogicalChannel: Unknown exception");
618 }
619 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 break;
622
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
624 request = (MainThreadRequest) msg.obj;
625 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000626 uiccPort = getUiccPortFromRequest(request);
627 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 loge("iccTransmitApduBasicChannel: No UICC");
629 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 } else {
632 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
633 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000634 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
636 iccArgument.p3, iccArgument.data, onCompleted);
637 }
638 break;
639
640 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result;
645 } else {
646 request.result = new IccIoResult(0x6F, 0, (byte[])null);
647 if (ar.result == null) {
648 loge("iccTransmitApduBasicChannel: Empty response");
649 } else if (ar.exception instanceof CommandException) {
650 loge("iccTransmitApduBasicChannel: CommandException: " +
651 ar.exception);
652 } else {
653 loge("iccTransmitApduBasicChannel: Unknown exception");
654 }
655 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 break;
658
659 case CMD_EXCHANGE_SIM_IO:
660 request = (MainThreadRequest) msg.obj;
661 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000662 uiccPort = getUiccPortFromRequest(request);
663 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 loge("iccExchangeSimIO: No UICC");
665 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 } else {
668 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
669 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000670 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
672 iccArgument.data, onCompleted);
673 }
674 break;
675
676 case EVENT_EXCHANGE_SIM_IO_DONE:
677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result;
681 } else {
682 request.result = new IccIoResult(0x6f, 0, (byte[])null);
683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 break;
686
Derek Tan4d5e5c12014-02-04 11:54:58 -0800687 case CMD_SEND_ENVELOPE:
688 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000689 uiccPort = getUiccPortFromRequest(request);
690 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 loge("sendEnvelopeWithStatus: No UICC");
692 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700693 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700694 } else {
695 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000696 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800698 break;
699
700 case EVENT_SEND_ENVELOPE_DONE:
701 ar = (AsyncResult) msg.obj;
702 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700703 if (ar.exception == null && ar.result != null) {
704 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700706 request.result = new IccIoResult(0x6F, 0, (byte[])null);
707 if (ar.result == null) {
708 loge("sendEnvelopeWithStatus: Empty response");
709 } else if (ar.exception instanceof CommandException) {
710 loge("sendEnvelopeWithStatus: CommandException: " +
711 ar.exception);
712 } else {
713 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
714 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800717 break;
718
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 case CMD_OPEN_CHANNEL:
720 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000721 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800722 IccLogicalChannelRequest openChannelRequest =
723 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000724 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700725 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800726 request.result = new IccOpenLogicalChannelResponse(-1,
727 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700729 } else {
730 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800731 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
732 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 break;
735
736 case EVENT_OPEN_CHANNEL_DONE:
737 ar = (AsyncResult) msg.obj;
738 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 int[] result = (int[]) ar.result;
742 int channelId = result[0];
743 byte[] selectResponse = null;
744 if (result.length > 1) {
745 selectResponse = new byte[result.length - 1];
746 for (int i = 1; i < result.length; ++i) {
747 selectResponse[i - 1] = (byte) result[i];
748 }
749 }
750 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700751 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800752
753 uiccPort = getUiccPortFromRequest(request);
754 IccLogicalChannelRequest channelRequest =
755 (IccLogicalChannelRequest) request.argument;
756 channelRequest.channel = channelId;
757 uiccPort.onLogicalChannelOpened(channelRequest);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 if (ar.result == null) {
760 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700762 if (ar.exception != null) {
763 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
764 }
765
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700766 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700767 if (ar.exception instanceof CommandException) {
768 CommandException.Error error =
769 ((CommandException) (ar.exception)).getCommandError();
770 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700771 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700772 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700773 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700774 }
775 }
776 openChannelResp = new IccOpenLogicalChannelResponse(
777 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700778 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700779 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700780 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 break;
782
783 case CMD_CLOSE_CHANNEL:
784 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000785 uiccPort = getUiccPortFromRequest(request);
786 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700787 loge("iccCloseLogicalChannel: No UICC");
Chen Xu540470b2021-12-14 17:15:47 -0800788 throw new IllegalArgumentException("iccCloseLogicalChannel: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700789 } else {
790 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000791 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700792 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700793 break;
794
795 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800796 ar = (AsyncResult) msg.obj;
797 request = (MainThreadRequest) ar.userObj;
798 if (ar.exception == null) {
799 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800800 uiccPort = getUiccPortFromRequest(request);
801 final int channelId = (Integer) request.argument;
802 uiccPort.onLogicalChannelClosed(channelId);
Chen Xu540470b2021-12-14 17:15:47 -0800803 } else {
804 request.result = false;
805 if (ar.exception instanceof CommandException) {
806 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
807 CommandException.Error error =
808 ((CommandException) (ar.exception)).getCommandError();
809 // before this feature is enabled, this API should only return false if
810 // the operation fails instead of throwing runtime exception for
811 // backward-compatibility.
812 if (Compatibility.isChangeEnabled(
813 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)
814 && error == CommandException.Error.INVALID_ARGUMENTS) {
815 throw new IllegalArgumentException(
816 "iccCloseLogicalChannel: invalid argument ");
817 }
818 } else {
819 loge("iccCloseLogicalChannel: Unknown exception");
820 }
821 if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)) {
822 throw new IllegalStateException(
823 "exception from modem to close iccLogical Channel");
824 }
825 }
826 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800827 break;
828
829 case CMD_NV_READ_ITEM:
830 request = (MainThreadRequest) msg.obj;
831 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800832 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
833 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800834 break;
835
836 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700837 ar = (AsyncResult) msg.obj;
838 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800839 if (ar.exception == null && ar.result != null) {
840 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700841 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800842 request.result = "";
843 if (ar.result == null) {
844 loge("nvReadItem: Empty response");
845 } else if (ar.exception instanceof CommandException) {
846 loge("nvReadItem: CommandException: " +
847 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800849 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700850 }
851 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700852 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700853 break;
854
Jake Hambye994d462014-02-03 13:10:13 -0800855 case CMD_NV_WRITE_ITEM:
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
858 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800859 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700860 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800861 break;
862
863 case EVENT_NV_WRITE_ITEM_DONE:
864 handleNullReturnEvent(msg, "nvWriteItem");
865 break;
866
867 case CMD_NV_WRITE_CDMA_PRL:
868 request = (MainThreadRequest) msg.obj;
869 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800870 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800871 break;
872
873 case EVENT_NV_WRITE_CDMA_PRL_DONE:
874 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
875 break;
876
chen xu6dac5ab2018-10-26 17:39:23 -0700877 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800878 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700879 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800880 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800881 break;
882
chen xu6dac5ab2018-10-26 17:39:23 -0700883 case EVENT_RESET_MODEM_CONFIG_DONE:
884 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800885 break;
886
Sooraj Sasindran37444802020-08-11 10:40:43 -0700887 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
888 request = (MainThreadRequest) msg.obj;
889 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
890 request);
891 Phone phone = getPhoneFromRequest(request);
892 if (phone != null) {
893 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
894 } else {
895 loge("isNRDualConnectivityEnabled: No phone object");
896 request.result = false;
897 notifyRequester(request);
898 }
899 break;
900 }
901
902 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
903 ar = (AsyncResult) msg.obj;
904 request = (MainThreadRequest) ar.userObj;
905 if (ar.exception == null && ar.result != null) {
906 request.result = ar.result;
907 } else {
908 // request.result must be set to something non-null
909 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700910 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700911 request.result = ar.result;
912 } else {
913 request.result = false;
914 }
915 if (ar.result == null) {
916 loge("isNRDualConnectivityEnabled: Empty response");
917 } else if (ar.exception instanceof CommandException) {
918 loge("isNRDualConnectivityEnabled: CommandException: "
919 + ar.exception);
920 } else {
921 loge("isNRDualConnectivityEnabled: Unknown exception");
922 }
923 }
924 notifyRequester(request);
925 break;
926
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700927 case CMD_IS_VONR_ENABLED: {
928 request = (MainThreadRequest) msg.obj;
929 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
930 request);
931 Phone phone = getPhoneFromRequest(request);
932 if (phone != null) {
933 phone.isVoNrEnabled(onCompleted, request.workSource);
934 } else {
935 loge("isVoNrEnabled: No phone object");
936 request.result = false;
937 notifyRequester(request);
938 }
939 break;
940 }
941
942 case EVENT_IS_VONR_ENABLED_DONE:
943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
945 if (ar.exception == null && ar.result != null) {
946 request.result = ar.result;
947 } else {
948 // request.result must be set to something non-null
949 // for the calling thread to unblock
950 if (ar.result != null) {
951 request.result = ar.result;
952 } else {
953 request.result = false;
954 }
955 if (ar.result == null) {
956 loge("isVoNrEnabled: Empty response");
957 } else if (ar.exception instanceof CommandException) {
958 loge("isVoNrEnabled: CommandException: "
959 + ar.exception);
960 } else {
961 loge("isVoNrEnabled: Unknown exception");
962 }
963 }
964 notifyRequester(request);
965 break;
966
Sooraj Sasindran37444802020-08-11 10:40:43 -0700967 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
968 request = (MainThreadRequest) msg.obj;
969 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
970 Phone phone = getPhoneFromRequest(request);
971 if (phone != null) {
972 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
973 request.workSource);
974 } else {
975 loge("enableNrDualConnectivity: No phone object");
976 request.result =
977 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
978 notifyRequester(request);
979 }
980 break;
981 }
982
983 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
984 ar = (AsyncResult) msg.obj;
985 request = (MainThreadRequest) ar.userObj;
986 if (ar.exception == null) {
987 request.result =
988 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
989 } else {
990 request.result =
991 TelephonyManager
992 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
993 if (ar.exception instanceof CommandException) {
994 CommandException.Error error =
995 ((CommandException) (ar.exception)).getCommandError();
996 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
997 request.result =
998 TelephonyManager
999 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001000 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1001 request.result =
1002 TelephonyManager
1003 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001004 }
1005 loge("enableNrDualConnectivity" + ": CommandException: "
1006 + ar.exception);
1007 } else {
1008 loge("enableNrDualConnectivity" + ": Unknown exception");
1009 }
1010 }
1011 notifyRequester(request);
1012 break;
1013 }
1014
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001015 case CMD_ENABLE_VONR: {
1016 request = (MainThreadRequest) msg.obj;
1017 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1018 Phone phone = getPhoneFromRequest(request);
1019 if (phone != null) {
1020 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1021 request.workSource);
1022 } else {
1023 loge("setVoNrEnabled: No phone object");
1024 request.result =
1025 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1026 notifyRequester(request);
1027 }
1028 break;
1029 }
1030
1031 case EVENT_ENABLE_VONR_DONE: {
1032 ar = (AsyncResult) msg.obj;
1033 request = (MainThreadRequest) ar.userObj;
1034 if (ar.exception == null) {
1035 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1036 } else {
1037 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1038 if (ar.exception instanceof CommandException) {
1039 CommandException.Error error =
1040 ((CommandException) (ar.exception)).getCommandError();
1041 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1042 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1043 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1044 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1045 } else {
1046 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1047 }
1048 loge("setVoNrEnabled" + ": CommandException: "
1049 + ar.exception);
1050 } else {
1051 loge("setVoNrEnabled" + ": Unknown exception");
1052 }
1053 }
1054 notifyRequester(request);
1055 break;
1056 }
1057
SongFerngWang3ef3e072020-12-21 16:41:52 +08001058 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001059 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001060 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1061 request);
1062 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001063 break;
1064
SongFerngWang3ef3e072020-12-21 16:41:52 +08001065 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
1068 if (ar.exception == null && ar.result != null) {
1069 request.result = ar.result; // Integer
1070 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301071 // request.result must be set to something non-null
1072 // for the calling thread to unblock
1073 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001074 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001075 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001076 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001077 loge("getAllowedNetworkTypesBitmask: CommandException: "
1078 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001079 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001080 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001081 }
1082 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001083 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001084 break;
1085
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001087 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001088 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1089 request);
1090 Pair<Integer, Long> reasonWithNetworkTypes =
1091 (Pair<Integer, Long>) request.argument;
1092 getPhoneFromRequest(request).setAllowedNetworkTypes(
1093 reasonWithNetworkTypes.first,
1094 reasonWithNetworkTypes.second,
1095 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001096 break;
1097
SongFerngWang3ef3e072020-12-21 16:41:52 +08001098 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1099 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001100 break;
1101
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001102 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1103 request = (MainThreadRequest)msg.obj;
1104 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001105 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001106 break;
1107
1108 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1109 ar = (AsyncResult)msg.obj;
1110 request = (MainThreadRequest)ar.userObj;
1111 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001112 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001113 break;
1114
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001115 case CMD_SET_VOICEMAIL_NUMBER:
1116 request = (MainThreadRequest) msg.obj;
1117 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1118 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001119 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1120 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001121 break;
1122
1123 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1124 handleNullReturnEvent(msg, "setVoicemailNumber");
1125 break;
1126
Stuart Scott54788802015-03-30 13:18:01 -07001127 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1128 request = (MainThreadRequest) msg.obj;
1129 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1130 request);
1131 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1132 break;
1133
1134 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1135 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1136 break;
1137
Shishir Agrawal302c8692015-06-19 13:49:39 -07001138 case CMD_PERFORM_NETWORK_SCAN:
1139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1141 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1142 break;
1143
Hall Liu27d24262020-09-18 19:04:59 -07001144 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001145 request = (MainThreadRequest) msg.obj;
1146 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001147 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1148 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1149 request.argument;
1150 int callForwardingReason = args.first;
1151 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001152 break;
Hall Liu27d24262020-09-18 19:04:59 -07001153 }
1154 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001155 ar = (AsyncResult) msg.obj;
1156 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001157 TelephonyManager.CallForwardingInfoCallback callback =
1158 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1159 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001160 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001161 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001162 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1163 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1164 // Service Class is a bit mask per 3gpp 27.007. Search for
1165 // any service for voice call.
1166 if ((callForwardInfo.serviceClass
1167 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001168 callForwardingInfo = new CallForwardingInfo(
1169 callForwardInfo.status
1170 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001171 callForwardInfo.reason,
1172 callForwardInfo.number,
1173 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001174 break;
1175 }
1176 }
1177 // Didn't find a call forward info for voice call.
1178 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001179 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1180 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001181 }
Hall Liu27d24262020-09-18 19:04:59 -07001182 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001183 } else {
1184 if (ar.result == null) {
1185 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1186 }
1187 if (ar.exception != null) {
1188 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1189 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001190 int errorCode = TelephonyManager
1191 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001192 if (ar.exception instanceof CommandException) {
1193 CommandException.Error error =
1194 ((CommandException) (ar.exception)).getCommandError();
1195 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001196 errorCode = TelephonyManager
1197 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001198 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001199 errorCode = TelephonyManager
1200 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001201 }
1202 }
Hall Liu27d24262020-09-18 19:04:59 -07001203 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001204 }
Shuo Qian4a594052020-01-23 11:59:30 -08001205 break;
Hall Liu27d24262020-09-18 19:04:59 -07001206 }
Shuo Qian4a594052020-01-23 11:59:30 -08001207
Hall Liu27d24262020-09-18 19:04:59 -07001208 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001209 request = (MainThreadRequest) msg.obj;
1210 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001211 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001212 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001213 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1214 request.argument).first;
1215 request.phone.setCallForwardingOption(
1216 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001217 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001218 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001219 callForwardingInfoToSet.getReason(),
1220 callForwardingInfoToSet.getNumber(),
1221 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1222 break;
Hall Liu27d24262020-09-18 19:04:59 -07001223 }
Shuo Qian4a594052020-01-23 11:59:30 -08001224
Hall Liu27d24262020-09-18 19:04:59 -07001225 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001226 ar = (AsyncResult) msg.obj;
1227 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001228 Consumer<Integer> callback =
1229 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1230 request.argument).second;
1231 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001232 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001233 int errorCode = TelephonyManager.CallForwardingInfoCallback
1234 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001235 if (ar.exception instanceof CommandException) {
1236 CommandException.Error error =
1237 ((CommandException) (ar.exception)).getCommandError();
1238 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001239 errorCode = TelephonyManager.CallForwardingInfoCallback
1240 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001241 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001242 errorCode = TelephonyManager.CallForwardingInfoCallback
1243 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001244 }
1245 }
1246 callback.accept(errorCode);
1247 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001248 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001249 }
Shuo Qian4a594052020-01-23 11:59:30 -08001250 break;
Hall Liu27d24262020-09-18 19:04:59 -07001251 }
Shuo Qian4a594052020-01-23 11:59:30 -08001252
Hall Liu27d24262020-09-18 19:04:59 -07001253 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001254 request = (MainThreadRequest) msg.obj;
1255 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1256 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1257 break;
Hall Liu27d24262020-09-18 19:04:59 -07001258 }
Shuo Qian4a594052020-01-23 11:59:30 -08001259
Hall Liu27d24262020-09-18 19:04:59 -07001260 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001261 ar = (AsyncResult) msg.obj;
1262 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001263 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001264 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1265 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001266 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001267 // Service Class is a bit mask per 3gpp 27.007.
1268 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001269 if (callForwardResults.length > 1
1270 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001271 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001272 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001273 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1274 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001275 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001276 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001277 }
1278 } else {
1279 if (ar.result == null) {
1280 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1281 }
1282 if (ar.exception != null) {
1283 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1284 }
1285 if (ar.exception instanceof CommandException) {
1286 CommandException.Error error =
1287 ((CommandException) (ar.exception)).getCommandError();
1288 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1289 callForwardingStatus =
1290 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1291 }
1292 }
1293 }
Hall Liu27d24262020-09-18 19:04:59 -07001294 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001295 break;
Hall Liu27d24262020-09-18 19:04:59 -07001296 }
Shuo Qian4a594052020-01-23 11:59:30 -08001297
Hall Liu27d24262020-09-18 19:04:59 -07001298 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001299 request = (MainThreadRequest) msg.obj;
1300 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001301 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1302 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001303 break;
Hall Liu27d24262020-09-18 19:04:59 -07001304 }
Shuo Qian4a594052020-01-23 11:59:30 -08001305
Hall Liu27d24262020-09-18 19:04:59 -07001306 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001307 ar = (AsyncResult) msg.obj;
1308 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001309 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1310 Consumer<Integer> callback =
1311 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1312 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001313 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001314 if (ar.exception instanceof CommandException) {
1315 CommandException.Error error =
1316 ((CommandException) (ar.exception)).getCommandError();
1317 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1318 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1319 } else {
1320 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1321 }
1322 } else {
1323 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1324 }
1325 } else {
1326 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1327 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001328 }
Shuo Qian4a594052020-01-23 11:59:30 -08001329 break;
Hall Liu27d24262020-09-18 19:04:59 -07001330 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001331 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1332 ar = (AsyncResult) msg.obj;
1333 request = (MainThreadRequest) ar.userObj;
1334 CellNetworkScanResult cellScanResult;
1335 if (ar.exception == null && ar.result != null) {
1336 cellScanResult = new CellNetworkScanResult(
1337 CellNetworkScanResult.STATUS_SUCCESS,
1338 (List<OperatorInfo>) ar.result);
1339 } else {
1340 if (ar.result == null) {
1341 loge("getCellNetworkScanResults: Empty response");
1342 }
1343 if (ar.exception != null) {
1344 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1345 }
1346 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1347 if (ar.exception instanceof CommandException) {
1348 CommandException.Error error =
1349 ((CommandException) (ar.exception)).getCommandError();
1350 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1351 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1352 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1353 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1354 }
1355 }
1356 cellScanResult = new CellNetworkScanResult(errorCode, null);
1357 }
1358 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001359 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001360 break;
1361
1362 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1363 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001364 ManualNetworkSelectionArgument selArg =
1365 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001366 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1367 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001368 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1369 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001370 break;
1371
1372 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001373 ar = (AsyncResult) msg.obj;
1374 request = (MainThreadRequest) ar.userObj;
1375 if (ar.exception == null) {
1376 request.result = true;
1377 } else {
1378 request.result = false;
1379 loge("setNetworkSelectionModeManual " + ar.exception);
1380 }
1381 notifyRequester(request);
1382 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001383 break;
1384
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001385 case CMD_GET_MODEM_ACTIVITY_INFO:
1386 request = (MainThreadRequest) msg.obj;
1387 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001388 if (defaultPhone != null) {
1389 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001390 } else {
1391 ResultReceiver result = (ResultReceiver) request.argument;
1392 Bundle bundle = new Bundle();
1393 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001394 new ModemActivityInfo(0, 0, 0,
1395 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001396 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001397 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001398 break;
1399
Hall Liud0f208c2020-10-14 16:54:44 -07001400 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001401 ar = (AsyncResult) msg.obj;
1402 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001403 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001404 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001405 if (mLastModemActivityInfo == null) {
1406 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1407 mLastModemActivitySpecificInfo[0] =
1408 new ActivityStatsTechSpecificInfo(
1409 0,
1410 0,
1411 new int[ModemActivityInfo.getNumTxPowerLevels()],
1412 0);
1413 mLastModemActivityInfo =
1414 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1415 }
1416
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001417 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001418 // Update the last modem activity info and the result of the request.
1419 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1420 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001421 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001422 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001423 mLastModemActivityInfo =
1424 new ModemActivityInfo(
1425 mLastModemActivityInfo.getTimestampMillis(),
1426 mLastModemActivityInfo.getSleepTimeMillis(),
1427 mLastModemActivityInfo.getIdleTimeMillis(),
1428 mLastModemActivitySpecificInfo);
1429
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001430 } else {
1431 if (ar.result == null) {
1432 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001433 error = TelephonyManager.ModemActivityInfoException
1434 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001435 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001436 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001437 error = TelephonyManager.ModemActivityInfoException
1438 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001439 } else {
1440 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001441 error = TelephonyManager.ModemActivityInfoException
1442 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001443 }
1444 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001445 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001446 if (mLastModemActivityInfo != null) {
1447 bundle.putParcelable(
1448 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1449 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001450 } else {
1451 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1452 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001453 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001454 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001455 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001456 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001457
Meng Wang1a7c35a2016-05-05 20:56:15 -07001458 case CMD_SET_ALLOWED_CARRIERS:
1459 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001460 CarrierRestrictionRules argument =
1461 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001462 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001463 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001464 break;
1465
1466 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1467 ar = (AsyncResult) msg.obj;
1468 request = (MainThreadRequest) ar.userObj;
1469 if (ar.exception == null && ar.result != null) {
1470 request.result = ar.result;
1471 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001472 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1473 if (ar.exception instanceof CommandException) {
1474 loge("setAllowedCarriers: CommandException: " + ar.exception);
1475 CommandException.Error error =
1476 ((CommandException) (ar.exception)).getCommandError();
1477 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1478 request.result =
1479 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1480 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001481 } else {
1482 loge("setAllowedCarriers: Unknown exception");
1483 }
1484 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001485 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001486 break;
1487
1488 case CMD_GET_ALLOWED_CARRIERS:
1489 request = (MainThreadRequest) msg.obj;
1490 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001491 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001492 break;
1493
1494 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1495 ar = (AsyncResult) msg.obj;
1496 request = (MainThreadRequest) ar.userObj;
1497 if (ar.exception == null && ar.result != null) {
1498 request.result = ar.result;
1499 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001500 request.result = new IllegalStateException(
1501 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001502 if (ar.result == null) {
1503 loge("getAllowedCarriers: Empty response");
1504 } else if (ar.exception instanceof CommandException) {
1505 loge("getAllowedCarriers: CommandException: " +
1506 ar.exception);
1507 } else {
1508 loge("getAllowedCarriers: Unknown exception");
1509 }
1510 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001511 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001512 break;
1513
Nathan Haroldb3014052017-01-25 15:57:32 -08001514 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1515 ar = (AsyncResult) msg.obj;
1516 request = (MainThreadRequest) ar.userObj;
1517 if (ar.exception == null && ar.result != null) {
1518 request.result = ar.result;
1519 } else {
1520 request.result = new IllegalArgumentException(
1521 "Failed to retrieve Forbidden Plmns");
1522 if (ar.result == null) {
1523 loge("getForbiddenPlmns: Empty response");
1524 } else {
1525 loge("getForbiddenPlmns: Unknown exception");
1526 }
1527 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001528 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001529 break;
1530
1531 case CMD_GET_FORBIDDEN_PLMNS:
1532 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001533 uiccPort = getUiccPortFromRequest(request);
1534 if (uiccPort == null) {
1535 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001536 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001537 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001538 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001539 break;
1540 }
1541 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001542 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001543 if (uiccApp == null) {
1544 loge("getForbiddenPlmns() no app with specified type -- "
1545 + appType);
1546 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001547 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001548 break;
1549 } else {
1550 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1551 + " specified type -- " + appType);
1552 }
1553 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1554 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1555 onCompleted);
1556 break;
1557
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001558 case CMD_SWITCH_SLOTS:
1559 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001560 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001561 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001562 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001563 break;
1564
1565 case EVENT_SWITCH_SLOTS_DONE:
1566 ar = (AsyncResult) msg.obj;
1567 request = (MainThreadRequest) ar.userObj;
1568 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001569 notifyRequester(request);
1570 break;
1571 case CMD_GET_NETWORK_SELECTION_MODE:
1572 request = (MainThreadRequest) msg.obj;
1573 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1574 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1575 break;
1576
1577 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1578 ar = (AsyncResult) msg.obj;
1579 request = (MainThreadRequest) ar.userObj;
1580 if (ar.exception != null) {
1581 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1582 } else {
1583 int mode = ((int[]) ar.result)[0];
1584 if (mode == 0) {
1585 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1586 } else {
1587 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1588 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001589 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001590 notifyRequester(request);
1591 break;
1592 case CMD_GET_CDMA_ROAMING_MODE:
1593 request = (MainThreadRequest) msg.obj;
1594 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1595 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1596 break;
1597 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1598 ar = (AsyncResult) msg.obj;
1599 request = (MainThreadRequest) ar.userObj;
1600 if (ar.exception != null) {
1601 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1602 } else {
1603 request.result = ((int[]) ar.result)[0];
1604 }
1605 notifyRequester(request);
1606 break;
1607 case CMD_SET_CDMA_ROAMING_MODE:
1608 request = (MainThreadRequest) msg.obj;
1609 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1610 int mode = (int) request.argument;
1611 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1612 break;
1613 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1614 ar = (AsyncResult) msg.obj;
1615 request = (MainThreadRequest) ar.userObj;
1616 request.result = ar.exception == null;
1617 notifyRequester(request);
1618 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001619 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1620 request = (MainThreadRequest) msg.obj;
1621 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1622 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1623 break;
1624 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1625 ar = (AsyncResult) msg.obj;
1626 request = (MainThreadRequest) ar.userObj;
1627 if (ar.exception != null) {
1628 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1629 } else {
1630 request.result = ((int[]) ar.result)[0];
1631 }
1632 notifyRequester(request);
1633 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001634 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1635 request = (MainThreadRequest) msg.obj;
1636 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1637 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001638 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1639 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001640 break;
1641 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1642 ar = (AsyncResult) msg.obj;
1643 request = (MainThreadRequest) ar.userObj;
1644 request.result = ar.exception == null;
1645 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001646 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001647 case CMD_GET_ALL_CELL_INFO:
1648 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001649 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001650 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001651 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001652 case EVENT_GET_ALL_CELL_INFO_DONE:
1653 ar = (AsyncResult) msg.obj;
1654 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001655 // If a timeout occurs, the response will be null
1656 request.result = (ar.exception == null && ar.result != null)
1657 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001658 synchronized (request) {
1659 request.notifyAll();
1660 }
1661 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001662 case CMD_REQUEST_CELL_INFO_UPDATE:
1663 request = (MainThreadRequest) msg.obj;
1664 request.phone.requestCellInfoUpdate(request.workSource,
1665 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1666 break;
1667 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1668 ar = (AsyncResult) msg.obj;
1669 request = (MainThreadRequest) ar.userObj;
1670 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1671 try {
1672 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001673 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001674 cb.onError(
1675 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1676 ar.exception.getClass().getName(),
1677 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001678 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001679 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001680 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001681 } else {
1682 // use the result as returned
1683 cb.onCellInfo((List<CellInfo>) ar.result);
1684 }
1685 } catch (RemoteException re) {
1686 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1687 }
1688 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001689 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001690 request = (MainThreadRequest) msg.obj;
1691 WorkSource ws = (WorkSource) request.argument;
1692 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001693 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001694 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001695 }
1696 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001697 ar = (AsyncResult) msg.obj;
1698 request = (MainThreadRequest) ar.userObj;
1699 if (ar.exception == null) {
1700 request.result = ar.result;
1701 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001702 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001703 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001704 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001705 }
1706
1707 synchronized (request) {
1708 request.notifyAll();
1709 }
1710 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001711 }
chen xu6dac5ab2018-10-26 17:39:23 -07001712 case CMD_MODEM_REBOOT:
1713 request = (MainThreadRequest) msg.obj;
1714 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001715 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001716 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001717 case EVENT_CMD_MODEM_REBOOT_DONE:
1718 handleNullReturnEvent(msg, "rebootModem");
1719 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001720 case CMD_REQUEST_ENABLE_MODEM:
1721 request = (MainThreadRequest) msg.obj;
1722 boolean enable = (boolean) request.argument;
1723 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001724 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001725 PhoneConfigurationManager.getInstance()
1726 .enablePhone(request.phone, enable, onCompleted);
1727 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001728 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001729 ar = (AsyncResult) msg.obj;
1730 request = (MainThreadRequest) ar.userObj;
1731 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001732 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001733 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001734 if ((boolean) request.result) {
1735 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1736 updateModemStateMetrics();
1737 } else {
1738 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1739 + ar.exception);
1740 }
1741 notifyRequester(request);
1742 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001743 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001744 case CMD_GET_MODEM_STATUS:
1745 request = (MainThreadRequest) msg.obj;
1746 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1747 PhoneConfigurationManager.getInstance()
1748 .getPhoneStatusFromModem(request.phone, onCompleted);
1749 break;
1750 case EVENT_GET_MODEM_STATUS_DONE:
1751 ar = (AsyncResult) msg.obj;
1752 request = (MainThreadRequest) ar.userObj;
1753 int id = request.phone.getPhoneId();
1754 if (ar.exception == null && ar.result != null) {
1755 request.result = ar.result;
1756 //update the cache as modem status has changed
1757 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1758 (boolean) request.result);
1759 } else {
1760 // Return true if modem status cannot be retrieved. For most cases,
1761 // modem status is on. And for older version modems, GET_MODEM_STATUS
1762 // and disable modem are not supported. Modem is always on.
1763 // TODO: this should be fixed in R to support a third
1764 // status UNKNOWN b/131631629
1765 request.result = true;
1766 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1767 + ar.exception);
1768 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001769 notifyRequester(request);
1770 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001771 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1772 request = (MainThreadRequest) msg.obj;
1773 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1774 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1775 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1776 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1777 break;
1778 }
1779 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1780 ar = (AsyncResult) msg.obj;
1781 request = (MainThreadRequest) ar.userObj;
1782 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1783 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1784 args.second.accept(ar.exception == null);
1785 notifyRequester(request);
1786 break;
1787 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001788 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1789 request = (MainThreadRequest) msg.obj;
1790 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1791 Phone phone = getPhoneFromRequest(request);
1792 if (phone != null) {
1793 phone.getSystemSelectionChannels(onCompleted);
1794 } else {
1795 loge("getSystemSelectionChannels: No phone object");
1796 request.result = new ArrayList<RadioAccessSpecifier>();
1797 notifyRequester(request);
1798 }
1799 break;
1800 }
1801 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1802 ar = (AsyncResult) msg.obj;
1803 request = (MainThreadRequest) ar.userObj;
1804 if (ar.exception == null && ar.result != null) {
1805 request.result = ar.result;
1806 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001807 request.result = new IllegalStateException(
1808 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001809 if (ar.result == null) {
1810 loge("getSystemSelectionChannels: Empty response");
1811 } else {
1812 loge("getSystemSelectionChannels: Unknown exception");
1813 }
1814 }
1815 notifyRequester(request);
1816 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001817 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1818 ar = (AsyncResult) msg.obj;
1819 request = (MainThreadRequest) ar.userObj;
1820 if (ar.exception == null && ar.result != null) {
1821 request.result = ar.result;
1822 } else {
1823 request.result = -1;
1824 loge("Failed to set Forbidden Plmns");
1825 if (ar.result == null) {
1826 loge("setForbidenPlmns: Empty response");
1827 } else if (ar.exception != null) {
1828 loge("setForbiddenPlmns: Exception: " + ar.exception);
1829 request.result = -1;
1830 } else {
1831 loge("setForbiddenPlmns: Unknown exception");
1832 }
1833 }
1834 notifyRequester(request);
1835 break;
1836 case CMD_SET_FORBIDDEN_PLMNS:
1837 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001838 uiccPort = getUiccPortFromRequest(request);
1839 if (uiccPort == null) {
1840 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001841 request.result = -1;
1842 notifyRequester(request);
1843 break;
1844 }
1845 Pair<Integer, List<String>> setFplmnsArgs =
1846 (Pair<Integer, List<String>>) request.argument;
1847 appType = setFplmnsArgs.first;
1848 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001849 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001850 if (uiccApp == null) {
1851 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1852 request.result = -1;
1853 loge("Failed to get UICC App");
1854 notifyRequester(request);
1855 } else {
1856 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1857 ((SIMRecords) uiccApp.getIccRecords())
1858 .setForbiddenPlmns(onCompleted, fplmns);
1859 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001860 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001861 case CMD_ERASE_MODEM_CONFIG:
1862 request = (MainThreadRequest) msg.obj;
1863 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1864 defaultPhone.eraseModemConfig(onCompleted);
1865 break;
1866 case EVENT_ERASE_MODEM_CONFIG_DONE:
1867 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001868 break;
zoey chene02881a2019-12-30 16:11:23 +08001869
Kai Shif70f46f2021-03-03 13:59:46 -08001870 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1871 request = (MainThreadRequest) msg.obj;
1872 request.result = defaultPhone.eraseDataInSharedPreferences();
1873 notifyRequester(request);
1874 break;
1875
zoey chene02881a2019-12-30 16:11:23 +08001876 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1877 request = (MainThreadRequest) msg.obj;
1878 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1879 Pair<String, String> changed = (Pair<String, String>) request.argument;
1880 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1881 changed.first, changed.second, onCompleted);
1882 break;
1883 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1884 ar = (AsyncResult) msg.obj;
1885 request = (MainThreadRequest) ar.userObj;
1886 if (ar.exception == null) {
1887 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001888 // If the operation is successful, update the PIN storage
1889 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1890 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001891 UiccController.getInstance().getPinStorage()
1892 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001893 } else {
1894 request.result = msg.arg1;
1895 }
1896 notifyRequester(request);
1897 break;
1898
Michele Berionne5e411512020-11-13 02:36:59 +00001899 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001900 request = (MainThreadRequest) msg.obj;
1901 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1902 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1903 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1904 enabled.first, enabled.second, onCompleted);
1905 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001906 }
zoey chene02881a2019-12-30 16:11:23 +08001907 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1908 ar = (AsyncResult) msg.obj;
1909 request = (MainThreadRequest) ar.userObj;
1910 if (ar.exception == null) {
1911 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001912 // If the operation is successful, update the PIN storage
1913 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1914 int phoneId = getPhoneFromRequest(request).getPhoneId();
1915 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001916 UiccController.getInstance().getPinStorage()
1917 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001918 } else {
1919 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1920 }
zoey chene02881a2019-12-30 16:11:23 +08001921 } else {
1922 request.result = msg.arg1;
1923 }
Michele Berionne5e411512020-11-13 02:36:59 +00001924
1925
zoey chene02881a2019-12-30 16:11:23 +08001926 notifyRequester(request);
1927 break;
1928
Peter Wangdafb9ac2020-01-15 14:13:38 -08001929 case MSG_NOTIFY_USER_ACTIVITY:
1930 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001931 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001932 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1933 getDefaultPhone().getContext().sendBroadcastAsUser(
1934 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1935 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001936
1937 case CMD_SET_DATA_THROTTLING: {
1938 request = (MainThreadRequest) msg.obj;
1939 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1940 DataThrottlingRequest dataThrottlingRequest =
1941 (DataThrottlingRequest) request.argument;
1942 Phone phone = getPhoneFromRequest(request);
1943 if (phone != null) {
1944 phone.setDataThrottling(onCompleted,
1945 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1946 dataThrottlingRequest.getCompletionDurationMillis());
1947 } else {
1948 loge("setDataThrottling: No phone object");
1949 request.result =
1950 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1951 notifyRequester(request);
1952 }
1953
1954 break;
1955 }
1956 case EVENT_SET_DATA_THROTTLING_DONE:
1957 ar = (AsyncResult) msg.obj;
1958 request = (MainThreadRequest) ar.userObj;
1959
1960 if (ar.exception == null) {
1961 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1962 } else if (ar.exception instanceof CommandException) {
1963 loge("setDataThrottling: CommandException: " + ar.exception);
1964 CommandException.Error error =
1965 ((CommandException) (ar.exception)).getCommandError();
1966
1967 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1968 request.result = TelephonyManager
1969 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1970 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1971 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001972 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1973 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001974 } else {
1975 request.result =
1976 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1977 }
1978 } else {
1979 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1980 }
1981 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1982 notifyRequester(request);
1983 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001984
1985 case CMD_SET_SIM_POWER: {
1986 request = (MainThreadRequest) msg.obj;
1987 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1988 request = (MainThreadRequest) msg.obj;
1989 int stateToSet =
1990 ((Pair<Integer, IIntegerConsumer>)
1991 request.argument).first;
1992 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1993 break;
1994 }
1995 case EVENT_SET_SIM_POWER_DONE: {
1996 ar = (AsyncResult) msg.obj;
1997 request = (MainThreadRequest) ar.userObj;
1998 IIntegerConsumer callback =
1999 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2000 if (ar.exception != null) {
2001 loge("setSimPower exception: " + ar.exception);
2002 int errorCode = TelephonyManager.CallForwardingInfoCallback
2003 .RESULT_ERROR_UNKNOWN;
2004 if (ar.exception instanceof CommandException) {
2005 CommandException.Error error =
2006 ((CommandException) (ar.exception)).getCommandError();
2007 if (error == CommandException.Error.SIM_ERR) {
2008 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2009 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2010 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2011 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2012 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2013 } else {
2014 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2015 }
2016 }
2017 try {
2018 callback.accept(errorCode);
2019 } catch (RemoteException e) {
2020 // Ignore if the remote process is no longer available to call back.
2021 Log.w(LOG_TAG, "setSimPower: callback not available.");
2022 }
2023 } else {
2024 try {
2025 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2026 } catch (RemoteException e) {
2027 // Ignore if the remote process is no longer available to call back.
2028 Log.w(LOG_TAG, "setSimPower: callback not available.");
2029 }
2030 }
2031 break;
2032 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002033 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2034 request = (MainThreadRequest) msg.obj;
2035
2036 final Phone phone = getPhoneFromRequest(request);
2037 if (phone == null || phone.getServiceStateTracker() == null) {
2038 request.result = new IllegalStateException("Phone or SST is null");
2039 notifyRequester(request);
2040 break;
2041 }
2042
2043 Pair<Integer, SignalStrengthUpdateRequest> pair =
2044 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2045 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2046 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002047 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002048 request.subId, pair.first /*callingUid*/,
2049 pair.second /*request*/, onCompleted);
2050 break;
2051 }
2052 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2053 ar = (AsyncResult) msg.obj;
2054 request = (MainThreadRequest) ar.userObj;
2055 // request.result will be the exception of ar if present, true otherwise.
2056 // Be cautious not to leave result null which will wait() forever
2057 request.result = ar.exception != null ? ar.exception : true;
2058 notifyRequester(request);
2059 break;
2060 }
2061 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2062 request = (MainThreadRequest) msg.obj;
2063
2064 Phone phone = getPhoneFromRequest(request);
2065 if (phone == null || phone.getServiceStateTracker() == null) {
2066 request.result = new IllegalStateException("Phone or SST is null");
2067 notifyRequester(request);
2068 break;
2069 }
2070
2071 Pair<Integer, SignalStrengthUpdateRequest> pair =
2072 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2073 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2074 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002075 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002076 request.subId, pair.first /*callingUid*/,
2077 pair.second /*request*/, onCompleted);
2078 break;
2079 }
2080 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2081 ar = (AsyncResult) msg.obj;
2082 request = (MainThreadRequest) ar.userObj;
2083 request.result = ar.exception != null ? ar.exception : true;
2084 notifyRequester(request);
2085 break;
2086 }
Jordan Liu109698e2020-11-24 14:50:34 -08002087
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002088 case CMD_GET_SLICING_CONFIG: {
2089 request = (MainThreadRequest) msg.obj;
2090 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2091 request.phone.getSlicingConfig(onCompleted);
2092 break;
2093 }
2094 case EVENT_GET_SLICING_CONFIG_DONE: {
2095 ar = (AsyncResult) msg.obj;
2096 request = (MainThreadRequest) ar.userObj;
2097 ResultReceiver result = (ResultReceiver) request.argument;
2098
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002099 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002100 Bundle bundle = new Bundle();
2101 int resultCode = 0;
2102 if (ar.exception != null) {
2103 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2104 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002105 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002106 } else if (ar.result == null) {
2107 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002108 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002109 } else {
2110 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002111 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2112 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002113 }
2114
2115 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002116 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002117 }
2118 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2119 result.send(resultCode, bundle);
2120 notifyRequester(request);
2121 break;
2122 }
2123
Michele Berionne5e411512020-11-13 02:36:59 +00002124 case CMD_PREPARE_UNATTENDED_REBOOT:
2125 request = (MainThreadRequest) msg.obj;
2126 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002127 UiccController.getInstance().getPinStorage()
2128 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002129 notifyRequester(request);
2130 break;
2131
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 default:
2133 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2134 break;
2135 }
2136 }
Jake Hambye994d462014-02-03 13:10:13 -08002137
Pengquan Menga1bb6272018-09-06 09:59:22 -07002138 private void notifyRequester(MainThreadRequest request) {
2139 synchronized (request) {
2140 request.notifyAll();
2141 }
2142 }
2143
Jake Hambye994d462014-02-03 13:10:13 -08002144 private void handleNullReturnEvent(Message msg, String command) {
2145 AsyncResult ar = (AsyncResult) msg.obj;
2146 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2147 if (ar.exception == null) {
2148 request.result = true;
2149 } else {
2150 request.result = false;
2151 if (ar.exception instanceof CommandException) {
2152 loge(command + ": CommandException: " + ar.exception);
2153 } else {
2154 loge(command + ": Unknown exception");
2155 }
2156 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002157 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 }
2160
2161 /**
2162 * Posts the specified command to be executed on the main thread,
2163 * waits for the request to complete, and returns the result.
2164 * @see #sendRequestAsync
2165 */
2166 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002167 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2168 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002169 }
2170
2171 /**
2172 * Posts the specified command to be executed on the main thread,
2173 * waits for the request to complete, and returns the result.
2174 * @see #sendRequestAsync
2175 */
2176 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2177 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002178 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002179 }
2180
2181 /**
2182 * Posts the specified command to be executed on the main thread,
2183 * waits for the request to complete, and returns the result.
2184 * @see #sendRequestAsync
2185 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002186 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002187 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2188 }
2189
2190 /**
2191 * Posts the specified command to be executed on the main thread,
2192 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2193 * if not timeout or null otherwise.
2194 * @see #sendRequestAsync
2195 */
2196 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2197 long timeoutInMs) {
2198 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002199 }
2200
2201 /**
2202 * Posts the specified command to be executed on the main thread,
2203 * waits for the request to complete, and returns the result.
2204 * @see #sendRequestAsync
2205 */
Nathan Harold92bed182018-10-12 18:16:49 -07002206 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002207 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002208 }
2209
2210 /**
2211 * Posts the specified command to be executed on the main thread,
2212 * waits for the request to complete, and returns the result.
2213 * @see #sendRequestAsync
2214 */
2215 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002216 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2217 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002218 }
2219
2220 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002221 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2222 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2223 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002224 * @see #sendRequestAsync
2225 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002226 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2227 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2229 throw new RuntimeException("This method will deadlock if called from the main thread.");
2230 }
2231
Nathan Harold92bed182018-10-12 18:16:49 -07002232 MainThreadRequest request = null;
2233 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2234 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2235 } else if (phone != null) {
2236 request = new MainThreadRequest(argument, phone, workSource);
2237 } else {
2238 request = new MainThreadRequest(argument, subId, workSource);
2239 }
2240
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 Message msg = mMainThreadHandler.obtainMessage(command, request);
2242 msg.sendToTarget();
2243
Rambo Wang0f050d82021-02-12 11:43:36 -08002244
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002246 if (timeoutInMs >= 0) {
2247 // Wait for at least timeoutInMs before returning null request result
2248 long now = SystemClock.elapsedRealtime();
2249 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002250 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002251 try {
2252 request.wait(deadline - now);
2253 } catch (InterruptedException e) {
2254 // Do nothing, go back and check if request is completed or timeout
2255 } finally {
2256 now = SystemClock.elapsedRealtime();
2257 }
2258 }
2259 } else {
2260 // Wait for the request to complete
2261 while (request.result == null) {
2262 try {
2263 request.wait();
2264 } catch (InterruptedException e) {
2265 // Do nothing, go back and wait until the request is complete
2266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268 }
2269 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002270 if (request.result == null) {
2271 Log.wtf(LOG_TAG,
2272 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2273 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 return request.result;
2275 }
2276
2277 /**
2278 * Asynchronous ("fire and forget") version of sendRequest():
2279 * Posts the specified command to be executed on the main thread, and
2280 * returns immediately.
2281 * @see #sendRequest
2282 */
2283 private void sendRequestAsync(int command) {
2284 mMainThreadHandler.sendEmptyMessage(command);
2285 }
2286
2287 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002288 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002289 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002290 */
2291 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002292 sendRequestAsync(command, argument, null, null);
2293 }
2294
2295 /**
2296 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2297 * @see {@link #sendRequest(int,Object)}
2298 */
2299 private void sendRequestAsync(
2300 int command, Object argument, Phone phone, WorkSource workSource) {
2301 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002302 Message msg = mMainThreadHandler.obtainMessage(command, request);
2303 msg.sendToTarget();
2304 }
2305
2306 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 * Initialize the singleton PhoneInterfaceManager instance.
2308 * This is only done once, at startup, from PhoneApp.onCreate().
2309 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002310 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 synchronized (PhoneInterfaceManager.class) {
2312 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002313 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 } else {
2315 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2316 }
2317 return sInstance;
2318 }
2319 }
2320
2321 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002322 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002325 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002326 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002328 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002330 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002331 mTelephonySharedPreferences =
2332 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002333 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002334 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002335 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002336 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002337
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 publish();
2339 }
2340
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002341 private Phone getDefaultPhone() {
2342 Phone thePhone = getPhone(getDefaultSubscription());
2343 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2344 }
2345
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346 private void publish() {
2347 if (DBG) log("publish: " + this);
2348
Peter Wangc035ce42020-01-08 21:00:22 -08002349 TelephonyFrameworkInitializer
2350 .getTelephonyServiceManager()
2351 .getTelephonyServiceRegisterer()
2352 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 }
2354
Stuart Scott584921c2015-01-15 17:10:34 -08002355 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002356 if (request.phone != null) {
2357 return request.phone;
2358 } else {
2359 return getPhoneFromSubId(request.subId);
2360 }
2361 }
2362
2363 private Phone getPhoneFromSubId(int subId) {
2364 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2365 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002366 }
2367
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002368 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002369 Phone phone = getPhoneFromRequest(request);
2370 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002371 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002372 }
2373
Wink Saville36469e72014-06-11 15:17:00 -07002374 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002375 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002376 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378
Kai Shif70f46f2021-03-03 13:59:46 -08002379 private void sendEraseModemConfig(@NonNull Phone phone) {
2380 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2381 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2382 }
2383
2384 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2385 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2386 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002387 }
2388
Peter Wang44b186e2020-01-13 23:33:09 -08002389 private boolean isImsAvailableOnDevice() {
2390 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2391 if (pm == null) {
2392 // For some reason package manger is not available.. This will fail internally anyway,
2393 // so do not throw error and allow.
2394 return true;
2395 }
2396 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2397 }
2398
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002400 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002401 }
2402
Wink Savilleb564aae2014-10-23 10:18:09 -07002403 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 if (DBG) log("dial: " + number);
2405 // No permission check needed here: This is just a wrapper around the
2406 // ACTION_DIAL intent, which is available to any app since it puts up
2407 // the UI before it does anything.
2408
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002409 final long identity = Binder.clearCallingIdentity();
2410 try {
2411 String url = createTelUrl(number);
2412 if (url == null) {
2413 return;
2414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416 // PENDING: should we just silently fail if phone is offhook or ringing?
2417 PhoneConstants.State state = mCM.getState(subId);
2418 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2419 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2420 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2421 mApp.startActivity(intent);
2422 }
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 }
2426 }
2427
2428 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002429 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002430 }
2431
Wink Savilleb564aae2014-10-23 10:18:09 -07002432 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 if (DBG) log("call: " + number);
2434
2435 // This is just a wrapper around the ACTION_CALL intent, but we still
2436 // need to do a permission check since we're calling startActivity()
2437 // from the context of the phone app.
2438 enforceCallPermission();
2439
Jordan Liu1617b712019-07-10 15:06:26 -07002440 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 != AppOpsManager.MODE_ALLOWED) {
2442 return;
2443 }
2444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445 final long identity = Binder.clearCallingIdentity();
2446 try {
2447 String url = createTelUrl(number);
2448 if (url == null) {
2449 return;
2450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452 boolean isValid = false;
2453 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2454 if (slist != null) {
2455 for (SubscriptionInfo subInfoRecord : slist) {
2456 if (subInfoRecord.getSubscriptionId() == subId) {
2457 isValid = true;
2458 break;
2459 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002460 }
Wink Saville08874612014-08-31 19:19:58 -07002461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002462 if (!isValid) {
2463 return;
2464 }
Wink Saville08874612014-08-31 19:19:58 -07002465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002466 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2467 intent.putExtra(SUBSCRIPTION_KEY, subId);
2468 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2469 mApp.startActivity(intent);
2470 } finally {
2471 Binder.restoreCallingIdentity(identity);
2472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 }
2474
Wink Savilleb564aae2014-10-23 10:18:09 -07002475 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002476 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002477 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2478 }
2479
Wink Savilleb564aae2014-10-23 10:18:09 -07002480 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002481 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002482 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2483 }
2484
Wink Savilleb564aae2014-10-23 10:18:09 -07002485 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002487
2488 final long identity = Binder.clearCallingIdentity();
2489 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002490 Phone phone = getPhone(subId);
2491 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492 checkSimPin.start();
2493 return checkSimPin.unlockSim(null, pin);
2494 } finally {
2495 Binder.restoreCallingIdentity(identity);
2496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
2498
Wink Savilleb564aae2014-10-23 10:18:09 -07002499 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002501
2502 final long identity = Binder.clearCallingIdentity();
2503 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002504 Phone phone = getPhone(subId);
2505 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 checkSimPuk.start();
2507 return checkSimPuk.unlockSim(puk, pin);
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
2510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 }
2512
2513 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002514 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 * a synchronous one.
2516 */
2517 private static class UnlockSim extends Thread {
2518
2519 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002520 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521
2522 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002523 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2524 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525
2526 // For replies from SimCard interface
2527 private Handler mHandler;
2528
2529 // For async handler to identify request type
2530 private static final int SUPPLY_PIN_COMPLETE = 100;
2531
Michele Berionne5e411512020-11-13 02:36:59 +00002532 UnlockSim(int phoneId, IccCard simCard) {
2533 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002534 mSimCard = simCard;
2535 }
2536
2537 @Override
2538 public void run() {
2539 Looper.prepare();
2540 synchronized (UnlockSim.this) {
2541 mHandler = new Handler() {
2542 @Override
2543 public void handleMessage(Message msg) {
2544 AsyncResult ar = (AsyncResult) msg.obj;
2545 switch (msg.what) {
2546 case SUPPLY_PIN_COMPLETE:
2547 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2548 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002549 mRetryCount = msg.arg1;
2550 if (ar.exception != null) {
2551 if (ar.exception instanceof CommandException &&
2552 ((CommandException)(ar.exception)).getCommandError()
2553 == CommandException.Error.PASSWORD_INCORRECT) {
2554 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002555 } //When UiccCardApp dispose,handle message and return exception
2556 else if (ar.exception instanceof CommandException &&
2557 ((CommandException) (ar.exception)).getCommandError()
2558 == CommandException.Error.ABORTED) {
2559 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002560 } else {
2561 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2562 }
2563 } else {
2564 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 mDone = true;
2567 UnlockSim.this.notifyAll();
2568 }
2569 break;
2570 }
2571 }
2572 };
2573 UnlockSim.this.notifyAll();
2574 }
2575 Looper.loop();
2576 }
2577
2578 /*
2579 * Use PIN or PUK to unlock SIM card
2580 *
2581 * If PUK is null, unlock SIM card with PIN
2582 *
2583 * If PUK is not null, unlock SIM card with PUK and set PIN code
2584 */
Wink Saville9de0f752013-10-22 19:04:03 -07002585 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586
2587 while (mHandler == null) {
2588 try {
2589 wait();
2590 } catch (InterruptedException e) {
2591 Thread.currentThread().interrupt();
2592 }
2593 }
2594 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2595
2596 if (puk == null) {
2597 mSimCard.supplyPin(pin, callback);
2598 } else {
2599 mSimCard.supplyPuk(puk, pin, callback);
2600 }
2601
2602 while (!mDone) {
2603 try {
2604 Log.d(LOG_TAG, "wait for done");
2605 wait();
2606 } catch (InterruptedException e) {
2607 // Restore the interrupted status
2608 Thread.currentThread().interrupt();
2609 }
2610 }
2611 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002612 int[] resultArray = new int[2];
2613 resultArray[0] = mResult;
2614 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002615
2616 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002617 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002618 }
2619
Wink Saville9de0f752013-10-22 19:04:03 -07002620 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002621 }
2622 }
2623
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002624 /**
2625 * This method has been removed due to privacy and stability concerns.
2626 */
2627 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002629 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2630 return;
Wink Saville36469e72014-06-11 15:17:00 -07002631 }
2632
Nathan Harold1f889d82020-06-04 17:05:26 -07002633 @Override
2634 public void updateServiceLocationWithPackageName(String callingPackage) {
2635 mApp.getSystemService(AppOpsManager.class)
2636 .checkPackage(Binder.getCallingUid(), callingPackage);
2637
Nathan Haroldf096d982020-11-18 17:18:06 -08002638 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002639 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2640 // Callers targeting S have no business invoking this method.
2641 return;
2642 }
2643
2644 LocationAccessPolicy.LocationPermissionResult locationResult =
2645 LocationAccessPolicy.checkLocationPermission(mApp,
2646 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2647 .setCallingPackage(callingPackage)
2648 .setCallingFeatureId(null)
2649 .setCallingPid(Binder.getCallingPid())
2650 .setCallingUid(Binder.getCallingUid())
2651 .setMethod("updateServiceLocation")
2652 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2653 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2654 .build());
2655 // Apps that lack location permission have no business calling this method;
2656 // however, because no permission was declared in the public API, denials must
2657 // all be "soft".
2658 switch (locationResult) {
2659 case DENIED_HARD: /* fall through */
2660 case DENIED_SOFT:
2661 return;
2662 }
2663
2664 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002667 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002669 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002670 }
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002676 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002677 @Override
2678 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002679 return isRadioOnWithFeature(callingPackage, null);
2680 }
2681
2682
2683 @Override
2684 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2685 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2686 callingFeatureId);
2687 }
2688
2689 @Deprecated
2690 @Override
2691 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2692 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002693 }
2694
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002695 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002696 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2697 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002698 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002699 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002700 return false;
2701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 return isRadioOnForSubscriber(subId);
2706 } finally {
2707 Binder.restoreCallingIdentity(identity);
2708 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002709 }
2710
2711 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712 final long identity = Binder.clearCallingIdentity();
2713 try {
2714 final Phone phone = getPhone(subId);
2715 if (phone != null) {
2716 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2717 } else {
2718 return false;
2719 }
2720 } finally {
2721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 }
2724
2725 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002726 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 }
Wink Saville36469e72014-06-11 15:17:00 -07002728
Wink Savilleb564aae2014-10-23 10:18:09 -07002729 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731
2732 final long identity = Binder.clearCallingIdentity();
2733 try {
2734 final Phone phone = getPhone(subId);
2735 if (phone != null) {
2736 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002740 }
Wink Saville36469e72014-06-11 15:17:00 -07002741 }
2742
2743 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002744 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002745 }
2746
Wink Savilleb564aae2014-10-23 10:18:09 -07002747 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002748 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 final Phone phone = getPhone(subId);
2753 if (phone == null) {
2754 return false;
2755 }
2756 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2757 toggleRadioOnOffForSubscriber(subId);
2758 }
2759 return true;
2760 } finally {
2761 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002762 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 }
Wink Saville36469e72014-06-11 15:17:00 -07002764
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002765 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002766 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002767 /*
2768 * If any of the Radios are available, it will need to be
2769 * shutdown. So return true if any Radio is available.
2770 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771 final long identity = Binder.clearCallingIdentity();
2772 try {
2773 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2774 Phone phone = PhoneFactory.getPhone(i);
2775 if (phone != null && phone.isRadioAvailable()) return true;
2776 }
2777 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2778 return false;
2779 } finally {
2780 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002781 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002782 }
2783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002784 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002785 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 enforceModifyPermission();
2787
2788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2791 logv("Shutting down Phone " + i);
2792 shutdownRadioUsingPhoneId(i);
2793 }
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002796 }
2797 }
2798
2799 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002800 Phone phone = PhoneFactory.getPhone(phoneId);
2801 if (phone != null && phone.isRadioAvailable()) {
2802 phone.shutdownRadio();
2803 }
2804 }
2805
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002806 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002807 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808
2809 final long identity = Binder.clearCallingIdentity();
2810 try {
2811 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2812 if (defaultPhone != null) {
2813 defaultPhone.setRadioPower(turnOn);
2814 return true;
2815 } else {
2816 loge("There's no default phone.");
2817 return false;
2818 }
2819 } finally {
2820 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002821 }
Wink Saville36469e72014-06-11 15:17:00 -07002822 }
2823
Wink Savilleb564aae2014-10-23 10:18:09 -07002824 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002825 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826
2827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 final Phone phone = getPhone(subId);
2830 if (phone != null) {
2831 phone.setRadioPower(turnOn);
2832 return true;
2833 } else {
2834 return false;
2835 }
2836 } finally {
2837 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002838 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839 }
2840
Wink Saville36469e72014-06-11 15:17:00 -07002841 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002842 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002843 public boolean enableDataConnectivity() {
2844 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845
2846 final long identity = Binder.clearCallingIdentity();
2847 try {
2848 int subId = mSubscriptionController.getDefaultDataSubId();
2849 final Phone phone = getPhone(subId);
2850 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002851 if (phone.isUsingNewDataStack()) {
2852 phone.getDataSettingsManager().setDataEnabled(
2853 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2854 } else {
2855 phone.getDataEnabledSettings().setDataEnabled(
2856 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2857 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 return true;
2859 } else {
2860 return false;
2861 }
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002865 }
2866
Wink Saville36469e72014-06-11 15:17:00 -07002867 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002868 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 public boolean disableDataConnectivity() {
2870 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002871
2872 final long identity = Binder.clearCallingIdentity();
2873 try {
2874 int subId = mSubscriptionController.getDefaultDataSubId();
2875 final Phone phone = getPhone(subId);
2876 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002877 if (phone.isUsingNewDataStack()) {
2878 phone.getDataSettingsManager().setDataEnabled(
2879 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2880 } else {
2881 phone.getDataEnabledSettings().setDataEnabled(
2882 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2883 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884 return true;
2885 } else {
2886 return false;
2887 }
2888 } finally {
2889 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002890 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 }
2892
Sanket Padawe356d7632015-06-22 14:03:32 -07002893 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002894 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002895 final long identity = Binder.clearCallingIdentity();
2896 try {
2897 final Phone phone = getPhone(subId);
2898 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002899 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900 } else {
2901 return false;
2902 }
2903 } finally {
2904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002906 }
2907
2908 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002909 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002910 }
2911
pkanwarae03a6b2016-11-06 20:37:09 -08002912 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002913 enforceCallPermission();
2914
2915 final long identity = Binder.clearCallingIdentity();
2916 try {
2917 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2918 return;
2919 }
2920 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2921 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2922 } finally {
2923 Binder.restoreCallingIdentity(identity);
2924 }
pkanwar32d516d2016-10-14 19:37:38 -07002925 };
2926
Wink Savilleb564aae2014-10-23 10:18:09 -07002927 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002928 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2933 return false;
2934 }
2935 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2936 } finally {
2937 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002939 }
2940
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002941 /**
2942 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2943 * tag on getCallState Binder call.
2944 */
2945 @Deprecated
2946 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002948 if (CompatChanges.isChangeEnabled(
2949 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2950 Binder.getCallingUid())) {
2951 // Do not allow this API to be called on API version 31+, it should only be
2952 // called on old apps using this Binder call directly.
2953 throw new SecurityException("This method can only be used for applications "
2954 + "targeting API version 30 or less.");
2955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956 final long identity = Binder.clearCallingIdentity();
2957 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002958 Phone phone = getPhone(getDefaultSubscription());
2959 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2960 PhoneConstantConversions.convertCallState(phone.getState());
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
2963 }
2964 }
2965
2966 @Override
2967 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2968 if (CompatChanges.isChangeEnabled(
2969 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2970 Binder.getCallingUid())) {
2971 // Check READ_PHONE_STATE for API version 31+
2972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2973 featureId, "getCallStateForSubscription")) {
2974 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2975 + "targeting API level 31+.");
2976 }
2977 }
2978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2982 PhoneConstantConversions.convertCallState(phone.getState());
2983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002986 }
2987
Sanket Padawe356d7632015-06-22 14:03:32 -07002988 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002989 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002990 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2991 }
2992
2993 @Override
2994 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 final long identity = Binder.clearCallingIdentity();
2996 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002997 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08002999 if (phone.isUsingNewDataStack()) {
3000 return phone.getDataNetworkController().getInternetDataNetworkState();
3001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
3003 } else {
3004 return PhoneConstantConversions.convertDataState(
3005 PhoneConstants.DataState.DISCONNECTED);
3006 }
3007 } finally {
3008 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 }
3011
Sanket Padawe356d7632015-06-22 14:03:32 -07003012 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003013 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003014 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3015 }
3016
3017 @Override
3018 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019 final long identity = Binder.clearCallingIdentity();
3020 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003021 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 if (phone != null) {
3023 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
3024 } else {
3025 return TelephonyManager.DATA_ACTIVITY_NONE;
3026 }
3027 } finally {
3028 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003030 }
3031
3032 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003033 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003034 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003035 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003036
3037 LocationAccessPolicy.LocationPermissionResult locationResult =
3038 LocationAccessPolicy.checkLocationPermission(mApp,
3039 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3040 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003041 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003042 .setCallingPid(Binder.getCallingPid())
3043 .setCallingUid(Binder.getCallingUid())
3044 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003045 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003046 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3047 .build());
3048 switch (locationResult) {
3049 case DENIED_HARD:
3050 throw new SecurityException("Not allowed to access cell location");
3051 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003052 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3053 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003054 }
3055
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003056 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003057 final long identity = Binder.clearCallingIdentity();
3058 try {
3059 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003060 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003061 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
Svetoslav64fad262015-04-14 14:35:21 -07003065 }
3066
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003067 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003068 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003069 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3070 // registered cell info, so return a NULL country instead.
3071 final long identity = Binder.clearCallingIdentity();
3072 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003073 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3074 // Get default phone in this case.
3075 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3076 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003077 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003078 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003079 if (phone == null) return "";
3080 ServiceStateTracker sst = phone.getServiceStateTracker();
3081 if (sst == null) return "";
3082 LocaleTracker lt = sst.getLocaleTracker();
3083 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003084 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003085 } finally {
3086 Binder.restoreCallingIdentity(identity);
3087 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003088 }
3089
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003090 /**
3091 * This method was removed due to potential issues caused by performing partial
3092 * updates of service state, and lack of a credible use case.
3093 *
3094 * This has the ability to break the telephony implementation by disabling notification of
3095 * changes in device connectivity. DO NOT USE THIS!
3096 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003097 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 public void enableLocationUpdates() {
3099 mApp.enforceCallingOrSelfPermission(
3100 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003101 }
3102
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003103 /**
3104 * This method was removed due to potential issues caused by performing partial
3105 * updates of service state, and lack of a credible use case.
3106 *
3107 * This has the ability to break the telephony implementation by disabling notification of
3108 * changes in device connectivity. DO NOT USE THIS!
3109 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003110 @Override
3111 public void disableLocationUpdates() {
3112 mApp.enforceCallingOrSelfPermission(
3113 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003114 }
3115
3116 @Override
3117 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003118 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3119 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003120 try {
3121 mApp.getSystemService(AppOpsManager.class)
3122 .checkPackage(Binder.getCallingUid(), callingPackage);
3123 } catch (SecurityException e) {
3124 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3125 throw e;
3126 }
3127
Nathan Haroldf096d982020-11-18 17:18:06 -08003128 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003129 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3130 throw new SecurityException(
3131 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3132 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003133
Jordan Liu1617b712019-07-10 15:06:26 -07003134 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003135 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3136 return null;
3137 }
Svetoslav64fad262015-04-14 14:35:21 -07003138
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003139 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003140
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003141 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003142 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143
Nathan Haroldf180aac2018-06-01 18:43:55 -07003144 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3145 for (CellInfo ci : info) {
3146 if (ci instanceof CellInfoGsm) {
3147 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3148 } else if (ci instanceof CellInfoWcdma) {
3149 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3150 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003151 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003152 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 }
3154
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003155 private List<CellInfo> getCachedCellInfo() {
3156 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3157 for (Phone phone : PhoneFactory.getPhones()) {
3158 List<CellInfo> info = phone.getAllCellInfo();
3159 if (info != null) cellInfos.addAll(info);
3160 }
3161 return cellInfos;
3162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003163
3164 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003165 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003166 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003167 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003168
3169 LocationAccessPolicy.LocationPermissionResult locationResult =
3170 LocationAccessPolicy.checkLocationPermission(mApp,
3171 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3172 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003173 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003174 .setCallingPid(Binder.getCallingPid())
3175 .setCallingUid(Binder.getCallingUid())
3176 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003177 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003178 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3179 .build());
3180 switch (locationResult) {
3181 case DENIED_HARD:
3182 throw new SecurityException("Not allowed to access cell info");
3183 case DENIED_SOFT:
3184 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003185 }
3186
Nathan Haroldf096d982020-11-18 17:18:06 -08003187 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003188 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3189 return getCachedCellInfo();
3190 }
3191
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003192 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003193 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3197 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003198 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003199 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 if (info != null) cellInfos.addAll(info);
3201 }
3202 return cellInfos;
3203 } finally {
3204 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 }
3206 }
3207
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003208 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003209 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3210 String callingFeatureId) {
3211 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3212 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003213 }
3214
3215 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003216 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3217 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003218 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003219 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003220 }
3221
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003222 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3223 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003224 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003225 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003226
3227 LocationAccessPolicy.LocationPermissionResult locationResult =
3228 LocationAccessPolicy.checkLocationPermission(mApp,
3229 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3230 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003231 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003232 .setCallingPid(Binder.getCallingPid())
3233 .setCallingUid(Binder.getCallingUid())
3234 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003235 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3236 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003237 .build());
3238 switch (locationResult) {
3239 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003240 if (TelephonyPermissions
3241 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003242 // Safetynet logging for b/154934934
3243 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3244 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003245 throw new SecurityException("Not allowed to access cell info");
3246 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003247 if (TelephonyPermissions
3248 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003249 // Safetynet logging for b/154934934
3250 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3251 }
Nathan Harold5320c422019-05-09 10:26:08 -07003252 try {
3253 cb.onCellInfo(new ArrayList<CellInfo>());
3254 } catch (RemoteException re) {
3255 // Drop without consequences
3256 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003257 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003258 }
3259
Nathan Harolda939a962019-05-09 10:13:47 -07003260
3261 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003262 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3263
3264 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3265 }
3266
3267 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003268 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003269 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003270 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003271
3272 final long identity = Binder.clearCallingIdentity();
3273 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003274 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003275 } finally {
3276 Binder.restoreCallingIdentity(identity);
3277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003278 }
3279
Shishir Agrawala9f32182016-04-12 12:00:16 -07003280 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003281 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003282 Phone phone = PhoneFactory.getPhone(slotIndex);
3283 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003284 return null;
3285 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003286 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003287 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003288 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003289 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003290 return null;
3291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292
3293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 return phone.getImei();
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
3298 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003299 }
3300
3301 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003302 public String getTypeAllocationCodeForSlot(int slotIndex) {
3303 Phone phone = PhoneFactory.getPhone(slotIndex);
3304 String tac = null;
3305 if (phone != null) {
3306 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003307 try {
3308 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3309 } catch (IndexOutOfBoundsException e) {
3310 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3311 return null;
3312 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003313 }
3314 return tac;
3315 }
3316
3317 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003318 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003319 try {
3320 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3321 } catch (SecurityException se) {
3322 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3323 throw new SecurityException("Package " + callingPackage + " does not belong to "
3324 + Binder.getCallingUid());
3325 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003326 Phone phone = PhoneFactory.getPhone(slotIndex);
3327 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003328 return null;
3329 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003330
Jeff Davidson913390f2018-02-23 17:11:49 -08003331 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003332 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003333 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003334 return null;
3335 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003336
3337 final long identity = Binder.clearCallingIdentity();
3338 try {
3339 return phone.getMeid();
3340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
Jack Yu2af8d712017-03-15 17:14:14 -07003343 }
3344
3345 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003346 public String getManufacturerCodeForSlot(int slotIndex) {
3347 Phone phone = PhoneFactory.getPhone(slotIndex);
3348 String manufacturerCode = null;
3349 if (phone != null) {
3350 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003351 try {
3352 manufacturerCode =
3353 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3354 } catch (IndexOutOfBoundsException e) {
3355 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3356 return null;
3357 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003358 }
3359 return manufacturerCode;
3360 }
3361
3362 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003363 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3364 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003365 Phone phone = PhoneFactory.getPhone(slotIndex);
3366 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003367 return null;
3368 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003369 int subId = phone.getSubId();
3370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003371 mApp, subId, callingPackage, callingFeatureId,
3372 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003373 return null;
3374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003375
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 return phone.getDeviceSvn();
3379 } finally {
3380 Binder.restoreCallingIdentity(identity);
3381 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003382 }
3383
fionaxu43304da2017-11-27 22:51:16 -08003384 @Override
3385 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 final Phone phone = getPhone(subId);
3389 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3390 } finally {
3391 Binder.restoreCallingIdentity(identity);
3392 }
fionaxu43304da2017-11-27 22:51:16 -08003393 }
3394
3395 @Override
3396 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003397 final long identity = Binder.clearCallingIdentity();
3398 try {
3399 final Phone phone = getPhone(subId);
3400 return phone == null ? null : phone.getCarrierName();
3401 } finally {
3402 Binder.restoreCallingIdentity(identity);
3403 }
fionaxu43304da2017-11-27 22:51:16 -08003404 }
3405
calvinpanffe225e2018-11-01 19:43:06 +08003406 @Override
chen xu0026ca62019-03-06 15:28:50 -08003407 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 final Phone phone = getPhone(subId);
3411 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003412 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003413 } finally {
3414 Binder.restoreCallingIdentity(identity);
3415 }
3416 }
3417
3418 @Override
chen xu0026ca62019-03-06 15:28:50 -08003419 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003423 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
3427 }
3428
chen xu651eec72018-11-11 19:03:44 -08003429 @Override
chen xu864e11c2018-12-06 22:10:03 -08003430 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3431 if (!isSubscriptionMccMnc) {
3432 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3433 }
chen xu651eec72018-11-11 19:03:44 -08003434 final Phone phone = PhoneFactory.getPhone(slotIndex);
3435 if (phone == null) {
3436 return TelephonyManager.UNKNOWN_CARRIER_ID;
3437 }
3438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3441 } finally {
3442 Binder.restoreCallingIdentity(identity);
3443 }
3444 }
3445
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003446 //
3447 // Internal helper methods.
3448 //
3449
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003450 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003451 * Make sure the caller is the calling package itself
3452 *
3453 * @throws SecurityException if the caller is not the calling package
3454 */
3455 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3456 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003457 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3458 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003459 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003460 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003461 } catch (PackageManager.NameNotFoundException e) {
3462 // packageUid is -1
3463 }
3464 if (packageUid != callingUid) {
3465 throw new SecurityException(message + ": Package " + callingPackage
3466 + " does not belong to " + callingUid);
3467 }
3468 }
3469
3470 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003471 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3472 *
3473 * @throws SecurityException if the caller does not have the required permission
3474 */
3475 private void enforceModifyPermission() {
3476 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3477 }
3478
Shuo Qian3b6ee772019-11-13 17:43:31 -08003479 private void enforceActiveEmergencySessionPermission() {
3480 mApp.enforceCallingOrSelfPermission(
3481 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3482 }
3483
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003484 /**
3485 * Make sure the caller has the CALL_PHONE permission.
3486 *
3487 * @throws SecurityException if the caller does not have the required permission
3488 */
3489 private void enforceCallPermission() {
3490 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3491 }
3492
paulhu5a773602019-08-23 19:17:33 +08003493 private void enforceSettingsPermission() {
3494 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003495 }
3496
Michele Berionne5e411512020-11-13 02:36:59 +00003497 private void enforceRebootPermission() {
3498 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3499 }
3500
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003501 private String createTelUrl(String number) {
3502 if (TextUtils.isEmpty(number)) {
3503 return null;
3504 }
3505
Jake Hambye994d462014-02-03 13:10:13 -08003506 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003507 }
3508
Ihab Awadf9e92732013-12-05 18:02:52 -08003509 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003510 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3511 }
3512
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003513 private static void logv(String msg) {
3514 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3515 }
3516
Ihab Awadf9e92732013-12-05 18:02:52 -08003517 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003518 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3519 }
3520
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003521 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003522 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003523 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003524 }
3525
Sanket Padawe356d7632015-06-22 14:03:32 -07003526 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003527 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003528 final long identity = Binder.clearCallingIdentity();
3529 try {
3530 final Phone phone = PhoneFactory.getPhone(slotIndex);
3531 if (phone == null) {
3532 return PhoneConstants.PHONE_TYPE_NONE;
3533 } else {
3534 return phone.getPhoneType();
3535 }
3536 } finally {
3537 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003539 }
3540
3541 /**
3542 * Returns the CDMA ERI icon index to display
3543 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003544 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003545 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3546 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3547 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003548 }
3549
Sanket Padawe356d7632015-06-22 14:03:32 -07003550 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003551 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3552 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003553 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003554 mApp, subId, callingPackage, callingFeatureId,
3555 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003556 return -1;
3557 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003558
3559 final long identity = Binder.clearCallingIdentity();
3560 try {
3561 final Phone phone = getPhone(subId);
3562 if (phone != null) {
3563 return phone.getCdmaEriIconIndex();
3564 } else {
3565 return -1;
3566 }
3567 } finally {
3568 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003570 }
3571
3572 /**
3573 * Returns the CDMA ERI icon mode,
3574 * 0 - ON
3575 * 1 - FLASHING
3576 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003577 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003578 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3579 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3580 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003581 }
3582
Sanket Padawe356d7632015-06-22 14:03:32 -07003583 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003584 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3585 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003587 mApp, subId, callingPackage, callingFeatureId,
3588 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003589 return -1;
3590 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003591
3592 final long identity = Binder.clearCallingIdentity();
3593 try {
3594 final Phone phone = getPhone(subId);
3595 if (phone != null) {
3596 return phone.getCdmaEriIconMode();
3597 } else {
3598 return -1;
3599 }
3600 } finally {
3601 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003603 }
3604
3605 /**
3606 * Returns the CDMA ERI text,
3607 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003608 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003609 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3610 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3611 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003612 }
3613
Sanket Padawe356d7632015-06-22 14:03:32 -07003614 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003615 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3616 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003618 mApp, subId, callingPackage, callingFeatureId,
3619 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003620 return null;
3621 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003622
3623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 final Phone phone = getPhone(subId);
3626 if (phone != null) {
3627 return phone.getCdmaEriText();
3628 } else {
3629 return null;
3630 }
3631 } finally {
3632 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003634 }
3635
3636 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003637 * Returns the CDMA MDN.
3638 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003639 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003640 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3642 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643
3644 final long identity = Binder.clearCallingIdentity();
3645 try {
3646 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003647 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648 return phone.getLine1Number();
3649 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003650 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003651 return null;
3652 }
3653 } finally {
3654 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003655 }
3656 }
3657
3658 /**
3659 * Returns the CDMA MIN.
3660 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003661 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003662 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3664 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665
3666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 final Phone phone = getPhone(subId);
3669 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3670 return phone.getCdmaMin();
3671 } else {
3672 return null;
3673 }
3674 } finally {
3675 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003676 }
3677 }
3678
Hall Liud892bec2018-11-30 14:51:45 -08003679 @Override
3680 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3681 INumberVerificationCallback callback, String callingPackage) {
3682 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3683 != PERMISSION_GRANTED) {
3684 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3685 }
3686 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3687
3688 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3689 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003690 throw new SecurityException("Calling package must be configured in the device config: "
3691 + "calling package: " + callingPackage
3692 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003693 }
3694
3695 if (range == null) {
3696 throw new NullPointerException("Range must be non-null");
3697 }
3698
3699 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003700 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003701
3702 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3703 }
3704
Junda Liuca05d5d2014-08-14 22:36:34 -07003705 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003706 * Returns true if CDMA provisioning needs to run.
3707 */
3708 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003709 final long identity = Binder.clearCallingIdentity();
3710 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003711 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003715 }
3716
3717 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003718 * Sets the voice mail number of a given subId.
3719 */
3720 @Override
3721 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003722 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3723 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724
3725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3728 new Pair<String, String>(alphaTag, number), new Integer(subId));
3729 return success;
3730 } finally {
3731 Binder.restoreCallingIdentity(identity);
3732 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003733 }
3734
Ta-wei Yen87c49842016-05-13 21:19:52 -07003735 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003736 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3737 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003738 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3739 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003740 if (!TextUtils.equals(callingPackage, systemDialer)) {
3741 throw new SecurityException("caller must be system dialer");
3742 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743
3744 final long identity = Binder.clearCallingIdentity();
3745 try {
3746 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3747 if (phoneAccountHandle == null) {
3748 return null;
3749 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003750 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751 } finally {
3752 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003753 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003754 }
3755
3756 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003757 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3758 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003759 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003761 mApp, subId, callingPackage, callingFeatureId,
3762 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003763 return null;
3764 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003765
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003766 final long identity = Binder.clearCallingIdentity();
3767 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003768 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003769 } finally {
3770 Binder.restoreCallingIdentity(identity);
3771 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003772 }
3773
3774 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003775 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3776 VisualVoicemailSmsFilterSettings settings) {
3777 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003778
3779 final long identity = Binder.clearCallingIdentity();
3780 try {
3781 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003782 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003783 } finally {
3784 Binder.restoreCallingIdentity(identity);
3785 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003786 }
3787
3788 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003789 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3790 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003795 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 } finally {
3797 Binder.restoreCallingIdentity(identity);
3798 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003799 }
3800
3801 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003802 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3803 String callingPackage, int subId) {
3804 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805
3806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003809 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810 } finally {
3811 Binder.restoreCallingIdentity(identity);
3812 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003813 }
3814
3815 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003816 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003817 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003818
3819 final long identity = Binder.clearCallingIdentity();
3820 try {
3821 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003822 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003823 } finally {
3824 Binder.restoreCallingIdentity(identity);
3825 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003826 }
3827
3828 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003829 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3830 String callingAttributionTag, int subId, String number, int port, String text,
3831 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003832 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003833 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003834 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003835 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003836 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3837 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003838 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003839
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003840 /**
fionaxu0152e512016-11-14 13:36:14 -08003841 * Sets the voice activation state of a given subId.
3842 */
3843 @Override
3844 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3846 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003847
3848 final long identity = Binder.clearCallingIdentity();
3849 try {
3850 final Phone phone = getPhone(subId);
3851 if (phone != null) {
3852 phone.setVoiceActivationState(activationState);
3853 } else {
3854 loge("setVoiceActivationState fails with invalid subId: " + subId);
3855 }
3856 } finally {
3857 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003858 }
3859 }
3860
3861 /**
3862 * Sets the data activation state of a given subId.
3863 */
3864 @Override
3865 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3867 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003868
3869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 final Phone phone = getPhone(subId);
3872 if (phone != null) {
3873 phone.setDataActivationState(activationState);
3874 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003875 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003876 }
3877 } finally {
3878 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003879 }
3880 }
3881
3882 /**
3883 * Returns the voice activation state of a given subId.
3884 */
3885 @Override
3886 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003887 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003888
fionaxu0152e512016-11-14 13:36:14 -08003889 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003890 final long identity = Binder.clearCallingIdentity();
3891 try {
3892 if (phone != null) {
3893 return phone.getVoiceActivationState();
3894 } else {
3895 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3896 }
3897 } finally {
3898 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003899 }
3900 }
3901
3902 /**
3903 * Returns the data activation state of a given subId.
3904 */
3905 @Override
3906 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908
fionaxu0152e512016-11-14 13:36:14 -08003909 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910 final long identity = Binder.clearCallingIdentity();
3911 try {
3912 if (phone != null) {
3913 return phone.getDataActivationState();
3914 } else {
3915 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3916 }
3917 } finally {
3918 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003919 }
3920 }
3921
3922 /**
Wink Saville36469e72014-06-11 15:17:00 -07003923 * Returns the unread count of voicemails for a subId
3924 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003925 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003926 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3927 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003929 mApp, subId, callingPackage, callingFeatureId,
3930 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003931 return 0;
3932 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 final Phone phone = getPhone(subId);
3936 if (phone != null) {
3937 return phone.getVoiceMessageCount();
3938 } else {
3939 return 0;
3940 }
3941 } finally {
3942 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003943 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003944 }
3945
3946 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003947 * returns true, if the device is in a state where both voice and data
3948 * are supported simultaneously. This can change based on location or network condition.
3949 */
3950 @Override
3951 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 final Phone phone = getPhone(subId);
3955 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3956 } finally {
3957 Binder.restoreCallingIdentity(identity);
3958 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003959 }
3960
3961 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003962 * Send the dialer code if called from the current default dialer or the caller has
3963 * carrier privilege.
3964 * @param inputCode The dialer code to send
3965 */
3966 @Override
3967 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003968 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003969 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003970 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3971 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003972 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003973 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003974 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003975 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003976
3977 final long identity = Binder.clearCallingIdentity();
3978 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003979 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003980 } finally {
3981 Binder.restoreCallingIdentity(identity);
3982 }
fionaxu235cc5e2017-03-06 22:25:57 -08003983 }
3984
Pengquan Menga1bb6272018-09-06 09:59:22 -07003985 @Override
3986 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003987 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003988 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003989 mApp, subId, "getNetworkSelectionMode");
3990 final long identity = Binder.clearCallingIdentity();
3991 try {
3992 if (!isActiveSubscription(subId)) {
3993 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3994 }
3995 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3996 } finally {
3997 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003998 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003999 }
4000
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004002 public boolean isInEmergencySmsMode() {
4003 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4004 final long identity = Binder.clearCallingIdentity();
4005 try {
4006 for (Phone phone : PhoneFactory.getPhones()) {
4007 if (phone.isInEmergencySmsMode()) {
4008 return true;
4009 }
4010 }
4011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
4014 return false;
4015 }
4016
shilu366312e2019-12-17 09:28:10 -08004017 /**
4018 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4019 * @param subId The subscription to use to check the configuration.
4020 * @param c The callback that will be used to send the result.
4021 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004022 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004023 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4024 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004025 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004026 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08004027
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004028 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4029 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4030 "IMS not available on device.");
4031 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004032 final long token = Binder.clearCallingIdentity();
4033 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004034 int slotId = getSlotIndexOrException(subId);
4035 verifyImsMmTelConfiguredOrThrow(slotId);
4036 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004037 } catch (ImsException e) {
4038 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 } finally {
4040 Binder.restoreCallingIdentity(token);
4041 }
4042 }
4043
shilu366312e2019-12-17 09:28:10 -08004044 /**
4045 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4046 * @param subId The subscription to use to check the configuration.
4047 * @param c The callback that will be used to send the result.
4048 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004049 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004050 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004051 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004052 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004053 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4054 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4055 }
Meng Wangafbc5852019-09-19 17:37:13 -07004056 final long token = Binder.clearCallingIdentity();
4057 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004058 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4059 .removeRegistrationCallbackForSubscription(c, subId);
4060 } catch (ImsException e) {
4061 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4062 + "is inactive, ignoring unregister.");
4063 // If the subscription is no longer active, just return, since the callback
4064 // will already have been removed internally.
4065 } finally {
4066 Binder.restoreCallingIdentity(token);
4067 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004068 }
4069
Brad Ebingera34a6c22019-10-22 17:36:18 -07004070 /**
4071 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4072 */
4073 @Override
4074 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4075 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4076 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4077 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4078 "IMS not available on device.");
4079 }
4080 final long token = Binder.clearCallingIdentity();
4081 try {
4082 Phone phone = getPhone(subId);
4083 if (phone == null) {
4084 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4085 + subId + "'");
4086 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4087 }
4088 phone.getImsRegistrationState(regState -> {
4089 try {
4090 consumer.accept((regState == null)
4091 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4092 } catch (RemoteException e) {
4093 // Ignore if the remote process is no longer available to call back.
4094 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4095 }
4096 });
4097 } finally {
4098 Binder.restoreCallingIdentity(token);
4099 }
4100 }
4101
4102 /**
4103 * Get the transport type for the IMS service registration state.
4104 */
4105 @Override
4106 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004107 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004108 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004109 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4110 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4111 "IMS not available on device.");
4112 }
4113 final long token = Binder.clearCallingIdentity();
4114 try {
4115 Phone phone = getPhone(subId);
4116 if (phone == null) {
4117 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4118 + subId + "'");
4119 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4120 }
4121 phone.getImsRegistrationTech(regTech -> {
4122 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4123 int regTechConverted = (regTech == null)
4124 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4125 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4126 regTechConverted);
4127 try {
4128 consumer.accept(regTechConverted);
4129 } catch (RemoteException e) {
4130 // Ignore if the remote process is no longer available to call back.
4131 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4132 }
4133 });
4134 } finally {
4135 Binder.restoreCallingIdentity(token);
4136 }
4137 }
4138
shilu366312e2019-12-17 09:28:10 -08004139 /**
4140 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4141 * @param subId The subscription to use to check the configuration.
4142 * @param c The callback that will be used to send the result.
4143 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004145 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4146 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004147 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004148 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004149 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4150 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4151 "IMS not available on device.");
4152 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 final long token = Binder.clearCallingIdentity();
4154 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004155 int slotId = getSlotIndexOrException(subId);
4156 verifyImsMmTelConfiguredOrThrow(slotId);
4157 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004158 } catch (ImsException e) {
4159 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 } finally {
4161 Binder.restoreCallingIdentity(token);
4162 }
4163 }
4164
shilu366312e2019-12-17 09:28:10 -08004165 /**
4166 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4167 * @param subId The subscription to use to check the configuration.
4168 * @param c The callback that will be used to send the result.
4169 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004170 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004171 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004172 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004173 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004174 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4175 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4176 }
Meng Wangafbc5852019-09-19 17:37:13 -07004177
4178 final long token = Binder.clearCallingIdentity();
4179 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004180 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004181 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004182 } catch (ImsException e) {
4183 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4184 + "is inactive, ignoring unregister.");
4185 // If the subscription is no longer active, just return, since the callback
4186 // will already have been removed internally.
4187 } finally {
4188 Binder.restoreCallingIdentity(token);
4189 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 }
4191
4192 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004193 public boolean isCapable(int subId, int capability, int regTech) {
4194 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 final long token = Binder.clearCallingIdentity();
4196 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004197 int slotId = getSlotIndexOrException(subId);
4198 verifyImsMmTelConfiguredOrThrow(slotId);
4199 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004200 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4202 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004203 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004204 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4205 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004206 } finally {
4207 Binder.restoreCallingIdentity(token);
4208 }
4209 }
4210
4211 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004212 public boolean isAvailable(int subId, int capability, int regTech) {
4213 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 final long token = Binder.clearCallingIdentity();
4215 try {
4216 Phone phone = getPhone(subId);
4217 if (phone == null) return false;
4218 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004219 } catch (com.android.ims.ImsException e) {
4220 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4221 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004222 } finally {
4223 Binder.restoreCallingIdentity(token);
4224 }
4225 }
4226
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004227 /**
4228 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4229 * subscription.
4230 * @param subId The subscription to use to check the configuration.
4231 * @param callback The callback that will be used to send the result.
4232 * @param capability The MmTelFeature capability that will be used to send the result.
4233 * @param transportType The transport type of the MmTelFeature capability.
4234 */
4235 @Override
4236 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4237 int transportType) {
4238 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4239 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4240 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4241 "IMS not available on device.");
4242 }
4243 final long token = Binder.clearCallingIdentity();
4244 try {
4245 int slotId = getSlotIndex(subId);
4246 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4247 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4248 + subId + "'");
4249 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4250 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004251 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004252 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4253 transportType, aBoolean -> {
4254 try {
4255 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4256 } catch (RemoteException e) {
4257 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4258 + "running. Ignore");
4259 }
4260 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004261 } catch (ImsException e) {
4262 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004263 } finally {
4264 Binder.restoreCallingIdentity(token);
4265 }
4266 }
4267
shilu366312e2019-12-17 09:28:10 -08004268 /**
4269 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4270 * @param subId The subscription to use to check the configuration.
4271 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004272 @Override
4273 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004274 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004275 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004276
Brad Ebinger35c841c2018-10-01 10:40:55 -07004277 final long token = Binder.clearCallingIdentity();
4278 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004279 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004280 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004281 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004282 } catch (ImsException e) {
4283 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 } finally {
4285 Binder.restoreCallingIdentity(token);
4286 }
4287 }
4288
4289 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004290 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004292 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004293 final long identity = Binder.clearCallingIdentity();
4294 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004295 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004296 // This setting doesn't require an active ImsService connection, so do not verify. The
4297 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004298 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004299 } catch (ImsException e) {
4300 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004301 } finally {
4302 Binder.restoreCallingIdentity(identity);
4303 }
4304 }
4305
shilu366312e2019-12-17 09:28:10 -08004306 /**
4307 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4308 * @param subId The subscription to use to check the configuration.
4309 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004310 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004311 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004312 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004313 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004314 final long identity = Binder.clearCallingIdentity();
4315 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004316 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004317 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004318 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004319 } catch (ImsException e) {
4320 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004321 } finally {
4322 Binder.restoreCallingIdentity(identity);
4323 }
4324 }
4325
4326 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004327 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004329 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004330 final long identity = Binder.clearCallingIdentity();
4331 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004332 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004333 // This setting doesn't require an active ImsService connection, so do not verify. The
4334 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004335 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004336 } catch (ImsException e) {
4337 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004338 } finally {
4339 Binder.restoreCallingIdentity(identity);
4340 }
4341 }
4342
shilu366312e2019-12-17 09:28:10 -08004343 /**
4344 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4345 * @param subId The subscription to use to check the configuration.
4346 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004347 @Override
4348 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004349 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004350 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004351 final long identity = Binder.clearCallingIdentity();
4352 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004353 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004354 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004355 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004356 } catch (ImsException e) {
4357 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
4361 }
4362
4363 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004364 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004366 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 final long identity = Binder.clearCallingIdentity();
4368 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004369 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004370 // This setting doesn't require an active ImsService connection, so do not verify. The
4371 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004372 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004373 } catch (ImsException e) {
4374 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 } finally {
4376 Binder.restoreCallingIdentity(identity);
4377 }
4378 }
4379
shilu366312e2019-12-17 09:28:10 -08004380 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004381 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4382 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4383 * @param subId The subscription to use to check the configuration.
4384 */
4385 @Override
4386 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004387 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004388 mApp, subId, "isCrossSimCallingEnabledByUser");
4389 final long identity = Binder.clearCallingIdentity();
4390 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004391 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004392 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004393 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004394 } catch (ImsException e) {
4395 throw new ServiceSpecificException(e.getCode());
4396 } finally {
4397 Binder.restoreCallingIdentity(identity);
4398 }
4399 }
4400
4401 /**
4402 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4403 * Requires MODIFY_PHONE_STATE permission.
4404 * @param subId The subscription to use to check the configuration.
4405 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4406 * false otherwise
4407 */
4408 @Override
4409 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4411 "setCrossSimCallingEnabled");
4412 final long identity = Binder.clearCallingIdentity();
4413 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004414 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004415 // This setting doesn't require an active ImsService connection, so do not verify. The
4416 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004417 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004418 } catch (ImsException e) {
4419 throw new ServiceSpecificException(e.getCode());
4420 } finally {
4421 Binder.restoreCallingIdentity(identity);
4422 }
4423 }
4424
4425 /**
shilu366312e2019-12-17 09:28:10 -08004426 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4427 * @param subId The subscription to use to check the configuration.
4428 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004429 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004430
Brad Ebinger35c841c2018-10-01 10:40:55 -07004431 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004432 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004433 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004434 final long identity = Binder.clearCallingIdentity();
4435 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004436 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004437 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004438 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004439 } catch (ImsException e) {
4440 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004441 } finally {
4442 Binder.restoreCallingIdentity(identity);
4443 }
4444 }
4445
4446 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004447 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004449 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004450 final long identity = Binder.clearCallingIdentity();
4451 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004452 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004453 // This setting doesn't require an active ImsService connection, so do not verify. The
4454 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004455 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004456 } catch (ImsException e) {
4457 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004458 } finally {
4459 Binder.restoreCallingIdentity(identity);
4460 }
4461 }
4462
4463 @Override
4464 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4466 "setVoWiFiNonPersistent");
4467 final long identity = Binder.clearCallingIdentity();
4468 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004469 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004470 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004471 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004472 } catch (ImsException e) {
4473 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004474 } finally {
4475 Binder.restoreCallingIdentity(identity);
4476 }
4477 }
4478
shilu366312e2019-12-17 09:28:10 -08004479 /**
4480 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4481 * @param subId The subscription to use to check the configuration.
4482 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004483 @Override
4484 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004485 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004486 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004487 final long identity = Binder.clearCallingIdentity();
4488 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004489 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004490 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004491 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004492 } catch (ImsException e) {
4493 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004494 } finally {
4495 Binder.restoreCallingIdentity(identity);
4496 }
4497 }
4498
4499 @Override
4500 public void setVoWiFiModeSetting(int subId, int mode) {
4501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4502 "setVoWiFiModeSetting");
4503 final long identity = Binder.clearCallingIdentity();
4504 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004505 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004506 // This setting doesn't require an active ImsService connection, so do not verify. The
4507 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004508 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004509 } catch (ImsException e) {
4510 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
4514 }
4515
4516 @Override
4517 public int getVoWiFiRoamingModeSetting(int subId) {
4518 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4519 final long identity = Binder.clearCallingIdentity();
4520 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004521 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004522 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004523 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004524 } catch (ImsException e) {
4525 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004526 } finally {
4527 Binder.restoreCallingIdentity(identity);
4528 }
4529 }
4530
4531 @Override
4532 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4534 "setVoWiFiRoamingModeSetting");
4535 final long identity = Binder.clearCallingIdentity();
4536 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004537 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004538 // This setting doesn't require an active ImsService connection, so do not verify. The
4539 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004540 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004541 } catch (ImsException e) {
4542 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004543 } finally {
4544 Binder.restoreCallingIdentity(identity);
4545 }
4546 }
4547
4548 @Override
4549 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4551 "setRttCapabilityEnabled");
4552 final long identity = Binder.clearCallingIdentity();
4553 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004554 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004555 // This setting doesn't require an active ImsService connection, so do not verify. The
4556 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004557 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004558 } catch (ImsException e) {
4559 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004560 } finally {
4561 Binder.restoreCallingIdentity(identity);
4562 }
4563 }
4564
shilu366312e2019-12-17 09:28:10 -08004565 /**
4566 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4567 * @param subId The subscription to use to check the configuration.
4568 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004569 @Override
4570 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004571 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004572 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004573 final long identity = Binder.clearCallingIdentity();
4574 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004575 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004576 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004577 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004578 } catch (ImsException e) {
4579 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004580 } finally {
4581 Binder.restoreCallingIdentity(identity);
4582 }
4583 }
4584
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004585 @Override
4586 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4587 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4588 final long identity = Binder.clearCallingIdentity();
4589 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004590 if (!isImsAvailableOnDevice()) {
4591 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4592 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004593 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004594 int slotId = getSlotIndexOrException(subId);
4595 verifyImsMmTelConfiguredOrThrow(slotId);
4596 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004597 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004598 } catch (ImsException e) {
4599 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004600 } finally {
4601 Binder.restoreCallingIdentity(identity);
4602 }
4603 }
4604
4605 @Override
4606 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4607 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4608 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004609 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4610 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4611 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004612 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004613 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004614 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004615 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004616 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4617 + "is inactive, ignoring unregister.");
4618 // If the subscription is no longer active, just return, since the callback will already
4619 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004620 } finally {
4621 Binder.restoreCallingIdentity(identity);
4622 }
4623 }
4624
allenwtsu99c623b2020-01-03 18:24:23 +08004625
4626 private void checkModifyPhoneStatePermission(int subId, String message) {
4627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4628 message);
4629 }
4630
4631 private boolean isImsProvisioningRequired(int subId, int capability,
4632 boolean isMmtelCapability) {
4633 Phone phone = getPhone(subId);
4634 if (phone == null) {
4635 loge("phone instance null for subid " + subId);
4636 return false;
4637 }
4638 if (isMmtelCapability) {
4639 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4640 return false;
4641 }
4642 } else {
4643 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4644 return false;
4645 }
4646 }
4647 return true;
4648 }
4649
4650 @Override
4651 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4652 boolean isProvisioned) {
4653 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4654
4655 final long identity = Binder.clearCallingIdentity();
4656 try {
4657 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4658 if (!isImsProvisioningRequired(subId, capability, false)) {
4659 return;
4660 }
4661
4662 // this capability requires provisioning, route to the correct API.
4663 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4664 switch (capability) {
4665 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4666 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4667 ims.setEabProvisioned(isProvisioned);
4668 break;
4669 default: {
4670 throw new IllegalArgumentException("Tried to set provisioning for "
4671 + "rcs capability '" + capability + "', which does not require "
4672 + "provisioning.");
4673 }
4674 }
4675 } finally {
4676 Binder.restoreCallingIdentity(identity);
4677 }
4678
4679 }
4680
4681
4682 @Override
4683 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4684 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4685 final long identity = Binder.clearCallingIdentity();
4686 try {
4687 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4688 if (!isImsProvisioningRequired(subId, capability, false)) {
4689 return true;
4690 }
4691
4692 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4693 switch (capability) {
4694 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4695 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4696 return ims.isEabProvisionedOnDevice();
4697
4698 default: {
4699 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4700 + "capability '" + capability + "', which does not require "
4701 + "provisioning.");
4702 }
4703 }
4704
4705 } finally {
4706 Binder.restoreCallingIdentity(identity);
4707 }
4708 }
4709
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004710 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004711 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4712 boolean isProvisioned) {
4713 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004714 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4715 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4716 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004717 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4718 }
allenwtsu99c623b2020-01-03 18:24:23 +08004719 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004720 final long identity = Binder.clearCallingIdentity();
4721 try {
4722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004723 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004724 return;
4725 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004726 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4727 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4728 loge("setImsProvisioningStatusForCapability: called for technology that does "
4729 + "not support provisioning - " + tech);
4730 return;
4731 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004732
4733 // this capability requires provisioning, route to the correct API.
4734 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4735 switch (capability) {
4736 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4737 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4738 ims.setVolteProvisioned(isProvisioned);
4739 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4740 ims.setWfcProvisioned(isProvisioned);
4741 }
4742 break;
4743 }
4744 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4745 // There is currently no difference in VT provisioning type.
4746 ims.setVtProvisioned(isProvisioned);
4747 break;
4748 }
4749 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4750 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4751 // change the capability of the feature instead if needed.
4752 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4753 == isProvisioned) {
4754 // No change in provisioning.
4755 return;
4756 }
4757 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4758 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004759 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004760 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004761 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4762 + ", Exception" + e.getMessage());
4763 }
4764 break;
4765 }
4766 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004767 throw new IllegalArgumentException("Tried to set provisioning for "
4768 + "MmTel capability '" + capability + "', which does not require "
4769 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004770 }
4771 }
4772
4773 } finally {
4774 Binder.restoreCallingIdentity(identity);
4775 }
4776 }
4777
4778 @Override
4779 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4780 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004781 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4782 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4783 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004784 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4785 }
4786 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4787 final long identity = Binder.clearCallingIdentity();
4788 try {
4789 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004790 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004791 return true;
4792 }
4793
Brad Ebinger0d79c572021-04-17 15:20:49 -07004794 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4795 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4796 loge("getImsProvisioningStatusForCapability: called for technology that does "
4797 + "not support provisioning - " + tech);
4798 return true;
4799 }
4800
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004801 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4802 switch (capability) {
4803 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4804 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4805 return ims.isVolteProvisionedOnDevice();
4806 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4807 return ims.isWfcProvisionedOnDevice();
4808 }
4809 // This should never happen, since we are checking tech above to make sure it
4810 // is either LTE or IWLAN.
4811 throw new IllegalArgumentException("Invalid radio technology for voice "
4812 + "capability.");
4813 }
4814 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4815 // There is currently no difference in VT provisioning type.
4816 return ims.isVtProvisionedOnDevice();
4817 }
4818 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4819 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4820 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4821 }
4822 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004823 throw new IllegalArgumentException(
4824 "Tried to get provisioning for MmTel capability '" + capability
4825 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004826 }
4827 }
4828
4829 } finally {
4830 Binder.restoreCallingIdentity(identity);
4831 }
4832 }
4833
4834 @Override
4835 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4836 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4837 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4838 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4839 }
4840 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4841 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4842 return (provisionedBits & capability) > 0;
4843 }
4844
4845 @Override
4846 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4847 boolean isProvisioned) {
4848 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4849 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4850 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4851 }
4852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4853 "setProvisioningStatusForCapability");
4854 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4855 // If the current provisioning status for capability already matches isProvisioned,
4856 // do nothing.
4857 if (((provisionedBits & capability) > 0) == isProvisioned) {
4858 return;
4859 }
4860 if (isProvisioned) {
4861 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4862 } else {
4863 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4864 }
4865 }
4866
4867 /**
4868 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4869 * technology. The bitfield should mirror the bitfield defined by
4870 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4871 */
4872 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4873 String key = getMmTelProvisioningKey(subId, tech);
4874 // Default is no capabilities are provisioned.
4875 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4876 }
4877
4878 /**
4879 * Sets the MmTel capability provisioning bitfield (defined by
4880 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4881 * technology specified.
4882 *
4883 * Note: This is a synchronous command and should not be called on UI thread.
4884 */
4885 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4886 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4887 String key = getMmTelProvisioningKey(subId, tech);
4888 editor.putInt(key, newField);
4889 editor.commit();
4890 }
4891
4892 private static String getMmTelProvisioningKey(int subId, int tech) {
4893 // resulting key is provision_ims_mmtel_{subId}_{tech}
4894 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4895 }
4896
4897 /**
4898 * Query CarrierConfig to see if the specified capability requires provisioning for the
4899 * carrier associated with the subscription id.
4900 */
4901 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4902 int capability) {
4903 CarrierConfigManager configManager = new CarrierConfigManager(context);
4904 PersistableBundle c = configManager.getConfigForSubId(subId);
4905 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004906 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004907 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4908 false);
4909 boolean requireVoiceVtProvisioning = c.getBoolean(
4910 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4911
4912 // First check to make sure that the capability requires provisioning.
4913 switch (capability) {
4914 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4915 // intentional fallthrough
4916 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4917 if (requireVoiceVtProvisioning) {
4918 // Voice and Video requires provisioning
4919 return true;
4920 }
4921 break;
4922 }
4923 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4924 if (requireUtProvisioning) {
4925 // UT requires provisioning
4926 return true;
4927 }
4928 break;
4929 }
4930 }
4931 return false;
4932 }
4933
allenwtsu99c623b2020-01-03 18:24:23 +08004934 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4935 int capability) {
4936 CarrierConfigManager configManager = new CarrierConfigManager(context);
4937 PersistableBundle c = configManager.getConfigForSubId(subId);
4938
4939 boolean requireRcsProvisioning = c.getBoolean(
4940 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4941
4942 // First check to make sure that the capability requires provisioning.
4943 switch (capability) {
4944 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4945 // intentional fallthrough
4946 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4947 if (requireRcsProvisioning) {
4948 // OPTION or PRESENCE requires provisioning
4949 return true;
4950 }
4951 break;
4952 }
4953 }
4954 return false;
4955 }
4956
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004957 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004958 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004959 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4960 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4961 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004962 enforceReadPrivilegedPermission("getImsProvisioningInt");
4963 final long identity = Binder.clearCallingIdentity();
4964 try {
4965 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004966 int slotId = getSlotIndex(subId);
4967 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4968 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4969 + subId + "' for key:" + key);
4970 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4971 }
calvinpanb5a34062021-02-08 19:59:36 +08004972 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004973 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004974 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4975 + subId + "' for key:" + key);
4976 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004977 } finally {
4978 Binder.restoreCallingIdentity(identity);
4979 }
4980 }
4981
4982 @Override
4983 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004984 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4985 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4986 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004987 enforceReadPrivilegedPermission("getImsProvisioningString");
4988 final long identity = Binder.clearCallingIdentity();
4989 try {
4990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004991 int slotId = getSlotIndex(subId);
4992 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4993 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4994 + subId + "' for key:" + key);
4995 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4996 }
calvinpanb5a34062021-02-08 19:59:36 +08004997 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004998 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004999 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5000 + subId + "' for key:" + key);
5001 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005002 } finally {
5003 Binder.restoreCallingIdentity(identity);
5004 }
5005 }
5006
5007 @Override
5008 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005009 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5010 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5011 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5013 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005014 final long identity = Binder.clearCallingIdentity();
5015 try {
5016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005017 int slotId = getSlotIndex(subId);
5018 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5019 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5020 + subId + "' for key:" + key);
5021 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5022 }
calvinpanb5a34062021-02-08 19:59:36 +08005023 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5024 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005025 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005026 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005027 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005028 } finally {
5029 Binder.restoreCallingIdentity(identity);
5030 }
5031 }
5032
5033 @Override
5034 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005035 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5036 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5037 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5039 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005040 final long identity = Binder.clearCallingIdentity();
5041 try {
5042 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005043 int slotId = getSlotIndex(subId);
5044 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5045 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5046 + subId + "' for key:" + key);
5047 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5048 }
calvinpanb5a34062021-02-08 19:59:36 +08005049 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5050 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005051 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005052 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005053 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005054 } finally {
5055 Binder.restoreCallingIdentity(identity);
5056 }
5057 }
5058
Brad Ebinger919631e2021-06-02 17:46:35 -07005059 /**
5060 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5061 * for the given slot ID or no ImsResolver instance has been created.
5062 * @param slotId The slot ID that the IMS service is created for.
5063 * @throws ImsException If there is no ImsService configured for this slot.
5064 */
5065 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5066 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5067 ImsFeature.FEATURE_MMTEL)) {
5068 throw new ImsException("This subscription does not support MMTEL over IMS",
5069 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5070 }
5071 }
5072
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005073 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005074 int slotId = SubscriptionManager.getSlotIndex(subId);
5075 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005076 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5077 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005078 }
5079 return slotId;
5080 }
5081
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005082 private int getSlotIndex(int subId) {
5083 int slotId = SubscriptionManager.getSlotIndex(subId);
5084 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5085 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5086 }
5087 return slotId;
5088 }
5089
Wink Saville36469e72014-06-11 15:17:00 -07005090 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005091 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005092 */
5093 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005094 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5095 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005096 try {
5097 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5098 } catch (SecurityException se) {
5099 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5100 throw new SecurityException("Package " + callingPackage + " does not belong to "
5101 + Binder.getCallingUid());
5102 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005103 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005104 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005105 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005106 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005107 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005108 mApp, subId, callingPackage, callingFeatureId,
5109 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005110 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5111 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113 final long identity = Binder.clearCallingIdentity();
5114 try {
5115 final Phone phone = getPhone(subId);
5116 if (phone != null) {
5117 return phone.getServiceState().getDataNetworkType();
5118 } else {
5119 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5120 }
5121 } finally {
5122 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005124 }
5125
5126 /**
5127 * Returns the data network type
5128 */
5129 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005130 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005131 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5132 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005133 }
5134
5135 /**
5136 * Returns the data network type for a subId
5137 */
5138 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005139 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5140 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005141 String functionName = "getDataNetworkTypeForSubscriber";
5142 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5143 mApp, functionName)) {
5144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5145 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5146 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5147 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005148 }
5149
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005150 final long identity = Binder.clearCallingIdentity();
5151 try {
5152 final Phone phone = getPhone(subId);
5153 if (phone != null) {
5154 return phone.getServiceState().getDataNetworkType();
5155 } else {
5156 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5157 }
5158 } finally {
5159 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005160 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005161 }
5162
5163 /**
Wink Saville36469e72014-06-11 15:17:00 -07005164 * Returns the Voice network type for a subId
5165 */
5166 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005167 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5168 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005169 String functionName = "getVoiceNetworkTypeForSubscriber";
5170 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5171 mApp, functionName)) {
5172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5173 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5174 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5175 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005176 }
5177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178 final long identity = Binder.clearCallingIdentity();
5179 try {
5180 final Phone phone = getPhone(subId);
5181 if (phone != null) {
5182 return phone.getServiceState().getVoiceNetworkType();
5183 } else {
5184 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5185 }
5186 } finally {
5187 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005189 }
5190
5191 /**
5192 * @return true if a ICC card is present
5193 */
5194 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005195 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005196 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5197 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005198 }
5199
5200 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005201 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005202 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005203 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005204 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 final long identity = Binder.clearCallingIdentity();
5206 try {
5207 final Phone phone = PhoneFactory.getPhone(slotIndex);
5208 if (phone != null) {
5209 return phone.getIccCard().hasIccCard();
5210 } else {
5211 return false;
5212 }
5213 } finally {
5214 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005216 }
5217
5218 /**
5219 * Return if the current radio is LTE on CDMA. This
5220 * is a tri-state return value as for a period of time
5221 * the mode may be unknown.
5222 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005223 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005224 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005225 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005226 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005227 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005228 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5229 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5230 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005231 }
5232
Sanket Padawe356d7632015-06-22 14:03:32 -07005233 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005234 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5235 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005236 try {
5237 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5238 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005239 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5240 }
5241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 final long identity = Binder.clearCallingIdentity();
5243 try {
5244 final Phone phone = getPhone(subId);
5245 if (phone == null) {
5246 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5247 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005248 return TelephonyProperties.lte_on_cdma_device()
5249 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 }
5251 } finally {
5252 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005253 }
Wink Saville36469e72014-06-11 15:17:00 -07005254 }
5255
Wink Saville36469e72014-06-11 15:17:00 -07005256 /**
5257 * {@hide}
5258 * Returns Default subId, 0 in the case of single standby.
5259 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005260 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005261 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005262 }
5263
Shishir Agrawala9f32182016-04-12 12:00:16 -07005264 private int getSlotForDefaultSubscription() {
5265 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5266 }
5267
Wink Savilleb564aae2014-10-23 10:18:09 -07005268 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005269 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005270 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005271
Pengquan Menge92a50d2018-09-21 15:54:48 -07005272 private boolean isActiveSubscription(int subId) {
5273 return mSubscriptionController.isActiveSubId(subId);
5274 }
5275
Ihab Awadf2177b72013-11-25 13:33:23 -08005276 /**
5277 * @see android.telephony.TelephonyManager.WifiCallingChoices
5278 */
5279 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 final long identity = Binder.clearCallingIdentity();
5281 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005282 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5284 getWhenToMakeWifiCallsDefaultPreference());
5285 } finally {
5286 Binder.restoreCallingIdentity(identity);
5287 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005288 }
5289
5290 /**
5291 * @see android.telephony.TelephonyManager.WifiCallingChoices
5292 */
5293 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 final long identity = Binder.clearCallingIdentity();
5295 try {
5296 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005297 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5299 } finally {
5300 Binder.restoreCallingIdentity(identity);
5301 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005302 }
5303
Sailesh Nepald1e68152013-12-12 19:08:02 -08005304 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005305 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005306 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005307 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005308
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005309 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5310 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5311 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005312 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005313 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5314 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005315 }
5316 return PhoneFactory.getPhone(phoneId);
5317 }
5318
Shishir Agrawal566b7612013-10-28 14:41:00 -07005319 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005320 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005321 @NonNull IccLogicalChannelRequest request) {
5322 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5323 /*message=*/ "iccOpenLogicalChannel");
5324
5325 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5326 // Verify that the callingPackage in the request belongs to the calling UID
5327 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5328
5329 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005330 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005331
Rambo Wanga1782702021-11-10 20:15:19 -08005332 private Phone getPhoneFromValidIccLogicalChannelRequest(
5333 @NonNull IccLogicalChannelRequest request, String message) {
5334 Phone phone;
5335 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5337 mApp, request.subId, message);
5338 phone = getPhoneFromSubId(request.subId);
5339 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5340 enforceModifyPermission();
5341 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5342 } else {
5343 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005344 }
Rambo Wanga1782702021-11-10 20:15:19 -08005345 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005346 }
5347
5348 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005349 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350 final long identity = Binder.clearCallingIdentity();
5351 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005352 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005354 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5355 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005356 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5357 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 loge("The calling package is not allowed to access ISD-R.");
5359 throw new SecurityException(
5360 "The calling package is not allowed to access ISD-R.");
5361 }
Derek Tan740e1672017-06-27 14:56:27 -07005362 }
Derek Tan740e1672017-06-27 14:56:27 -07005363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005365 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5366 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005367 return response;
5368 } finally {
5369 Binder.restoreCallingIdentity(identity);
5370 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005371 }
5372
5373 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005374 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5375 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5376 /*message=*/"iccCloseLogicalChannel");
5377
5378 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5379
5380 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005381 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005382
Rambo Wanga1782702021-11-10 20:15:19 -08005383 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5384 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005385 final long identity = Binder.clearCallingIdentity();
5386 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005387 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005388 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 }
Rambo Wanga1782702021-11-10 20:15:19 -08005390 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005391 null /* workSource */);
Rambo Wanga1782702021-11-10 20:15:19 -08005392 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 return success;
5394 } finally {
5395 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005396 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005397 }
5398
5399 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005400 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005401 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5403 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005404 if (DBG) {
5405 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5406 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5407 + p3 + " data=" + data);
5408 }
5409 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5410 command, p1, p2, p3, data);
5411 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005412
Jordan Liu4c733742019-02-28 12:03:40 -08005413 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005414 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5415 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005416 enforceModifyPermission();
5417 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005418 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5419 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5420 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005421 }
5422 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005423 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5424 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005425 }
5426
5427 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5428 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429 final long identity = Binder.clearCallingIdentity();
5430 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005431 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432 return "";
5433 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005434
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005436 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5437 null /* workSource */);
5438 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 // Append the returned status code to the end of the response payload.
5441 String s = Integer.toHexString(
5442 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5443 if (response.payload != null) {
5444 s = IccUtils.bytesToHexString(response.payload) + s;
5445 }
5446 return s;
5447 } finally {
5448 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005449 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005450 }
Jake Hambye994d462014-02-03 13:10:13 -08005451
Evan Charltonc66da362014-05-16 14:06:40 -07005452 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005453 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5454 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5456 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005458 if (DBG) {
5459 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5460 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5461 }
5462 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5463 cla, command, p1, p2, p3, data);
5464 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005465
Jordan Liu4c733742019-02-28 12:03:40 -08005466 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005467 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5468 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005469 enforceModifyPermission();
5470 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5471 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005472 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5473 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5474 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005475 }
5476
5477 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005478 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5479 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005480 }
5481
5482 // open APDU basic channel assuming the caller has sufficient permissions
5483 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5484 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485 final long identity = Binder.clearCallingIdentity();
5486 try {
5487 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5488 && TextUtils.equals(ISDR_AID, data)) {
5489 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005490 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5491 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492 if (bestComponent == null
5493 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5494 loge("The calling package is not allowed to select ISD-R.");
5495 throw new SecurityException(
5496 "The calling package is not allowed to select ISD-R.");
5497 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005498 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005501 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5502 null /* workSource */);
5503 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505 // Append the returned status code to the end of the response payload.
5506 String s = Integer.toHexString(
5507 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5508 if (response.payload != null) {
5509 s = IccUtils.bytesToHexString(response.payload) + s;
5510 }
5511 return s;
5512 } finally {
5513 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005514 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005515 }
5516
5517 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005518 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005519 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5521 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 final long identity = Binder.clearCallingIdentity();
5524 try {
5525 if (DBG) {
5526 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5527 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5528 }
5529
5530 IccIoResult response =
5531 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5532 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5533 subId);
5534
5535 if (DBG) {
5536 log("Exchange SIM_IO [R]" + response);
5537 }
5538
5539 byte[] result = null;
5540 int length = 2;
5541 if (response.payload != null) {
5542 length = 2 + response.payload.length;
5543 result = new byte[length];
5544 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5545 } else {
5546 result = new byte[length];
5547 }
5548
5549 result[length - 1] = (byte) response.sw2;
5550 result[length - 2] = (byte) response.sw1;
5551 return result;
5552 } finally {
5553 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005554 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005555 }
5556
Nathan Haroldb3014052017-01-25 15:57:32 -08005557 /**
5558 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5559 * on a particular subscription
5560 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005561 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5562 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005563 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005564 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005565 return null;
5566 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567
5568 final long identity = Binder.clearCallingIdentity();
5569 try {
5570 if (appType != TelephonyManager.APPTYPE_USIM
5571 && appType != TelephonyManager.APPTYPE_SIM) {
5572 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5573 return null;
5574 }
5575 Object response = sendRequest(
5576 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5577 if (response instanceof String[]) {
5578 return (String[]) response;
5579 }
yincheng zhao2737e882019-09-06 17:06:54 -07005580 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005582 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 } finally {
5584 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005585 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005586 }
5587
yincheng zhao2737e882019-09-06 17:06:54 -07005588 /**
5589 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5590 * subscription.
5591 *
5592 * @param subId the id of the subscription.
5593 * @param appType the uicc app type, must be USIM or SIM.
5594 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5595 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005596 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005597 * @return number of fplmns that is successfully written to the SIM.
5598 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005599 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5600 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5602 mApp, subId, "setForbiddenPlmns");
5603
yincheng zhao2737e882019-09-06 17:06:54 -07005604 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5605 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5606 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5607 }
5608 if (fplmns == null) {
5609 throw new IllegalArgumentException("Fplmn List provided is null");
5610 }
5611 for (String fplmn : fplmns) {
5612 if (!CellIdentity.isValidPlmn(fplmn)) {
5613 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5614 }
5615 }
5616 final long identity = Binder.clearCallingIdentity();
5617 try {
5618 Object response = sendRequest(
5619 CMD_SET_FORBIDDEN_PLMNS,
5620 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5621 subId);
5622 return (int) response;
5623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
5626 }
5627
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005628 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005629 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5631 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5636 if (response.payload == null) {
5637 return "";
5638 }
Evan Charltonc66da362014-05-16 14:06:40 -07005639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 // Append the returned status code to the end of the response payload.
5641 String s = Integer.toHexString(
5642 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5643 s = IccUtils.bytesToHexString(response.payload) + s;
5644 return s;
5645 } finally {
5646 Binder.restoreCallingIdentity(identity);
5647 }
Evan Charltonc66da362014-05-16 14:06:40 -07005648 }
5649
Jake Hambye994d462014-02-03 13:10:13 -08005650 /**
5651 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5652 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5653 *
5654 * @param itemID the ID of the item to read
5655 * @return the NV item as a String, or null on error.
5656 */
5657 @Override
5658 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005659 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5661 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662
5663 final long identity = Binder.clearCallingIdentity();
5664 try {
5665 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005666 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5668 return value;
5669 } finally {
5670 Binder.restoreCallingIdentity(identity);
5671 }
Jake Hambye994d462014-02-03 13:10:13 -08005672 }
5673
5674 /**
5675 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5676 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5677 *
5678 * @param itemID the ID of the item to read
5679 * @param itemValue the value to write, as a String
5680 * @return true on success; false on any failure
5681 */
5682 @Override
5683 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005684 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5686 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687
5688 final long identity = Binder.clearCallingIdentity();
5689 try {
5690 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5691 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005692 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5694 return success;
5695 } finally {
5696 Binder.restoreCallingIdentity(identity);
5697 }
Jake Hambye994d462014-02-03 13:10:13 -08005698 }
5699
5700 /**
5701 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5702 * Used for device configuration by some CDMA operators.
5703 *
5704 * @param preferredRoamingList byte array containing the new PRL
5705 * @return true on success; false on any failure
5706 */
5707 @Override
5708 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5710 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711
5712 final long identity = Binder.clearCallingIdentity();
5713 try {
5714 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5715 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5716 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5717 return success;
5718 } finally {
5719 Binder.restoreCallingIdentity(identity);
5720 }
Jake Hambye994d462014-02-03 13:10:13 -08005721 }
5722
5723 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005724 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005725 * Used for device configuration by some CDMA operators.
5726 *
chen xu6dac5ab2018-10-26 17:39:23 -07005727 * @param slotIndex - device slot.
5728 *
Jake Hambye994d462014-02-03 13:10:13 -08005729 * @return true on success; false on any failure
5730 */
5731 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005732 public boolean resetModemConfig(int slotIndex) {
5733 Phone phone = PhoneFactory.getPhone(slotIndex);
5734 if (phone != null) {
5735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5736 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737
chen xu6dac5ab2018-10-26 17:39:23 -07005738 final long identity = Binder.clearCallingIdentity();
5739 try {
5740 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5741 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5742 return success;
5743 } finally {
5744 Binder.restoreCallingIdentity(identity);
5745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746 }
chen xu6dac5ab2018-10-26 17:39:23 -07005747 return false;
5748 }
5749
5750 /**
5751 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5752 *
5753 * @param slotIndex - device slot.
5754 *
5755 * @return true on success; false on any failure
5756 */
5757 @Override
5758 public boolean rebootModem(int slotIndex) {
5759 Phone phone = PhoneFactory.getPhone(slotIndex);
5760 if (phone != null) {
5761 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5762 mApp, phone.getSubId(), "rebootModem");
5763
5764 final long identity = Binder.clearCallingIdentity();
5765 try {
5766 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5767 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5768 return success;
5769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
5772 }
5773 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005774 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005775
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005776 public String[] getPcscfAddress(String apnType, String callingPackage,
5777 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005778 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005779 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5780 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005781 return new String[0];
5782 }
5783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005784 final long identity = Binder.clearCallingIdentity();
5785 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005786 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 } finally {
5788 Binder.restoreCallingIdentity(identity);
5789 }
Wink Saville36469e72014-06-11 15:17:00 -07005790 }
5791
Brad Ebinger51f743a2017-01-23 13:50:20 -08005792 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005793 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5794 * {@link #disableIms(int)}.
5795 * @param slotIndex device slot.
5796 */
5797 public void resetIms(int slotIndex) {
5798 enforceModifyPermission();
5799
5800 final long identity = Binder.clearCallingIdentity();
5801 try {
5802 if (mImsResolver == null) {
5803 // may happen if the does not support IMS.
5804 return;
5805 }
5806 mImsResolver.disableIms(slotIndex);
5807 mImsResolver.enableIms(slotIndex);
5808 } finally {
5809 Binder.restoreCallingIdentity(identity);
5810 }
5811 }
5812
5813 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005814 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5815 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005816 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005817 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819
5820 final long identity = Binder.clearCallingIdentity();
5821 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005822 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005823 // may happen if the device does not support IMS.
5824 return;
5825 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005826 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 } finally {
5828 Binder.restoreCallingIdentity(identity);
5829 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005830 }
5831
5832 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005833 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5834 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005835 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005836 public void disableIms(int slotId) {
5837 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005838
5839 final long identity = Binder.clearCallingIdentity();
5840 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005841 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005842 // may happen if the device does not support IMS.
5843 return;
5844 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005845 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 } finally {
5847 Binder.restoreCallingIdentity(identity);
5848 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005849 }
5850
5851 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005852 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5853 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005854 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005855 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005856 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005857 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858
5859 final long identity = Binder.clearCallingIdentity();
5860 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005861 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005862 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5863 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005864 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005865 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866 } finally {
5867 Binder.restoreCallingIdentity(identity);
5868 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005869 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005870 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005871 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5872 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005873 @Override
5874 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005875 enforceModifyPermission();
5876
5877 final long identity = Binder.clearCallingIdentity();
5878 try {
5879 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005880 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005881 } finally {
5882 Binder.restoreCallingIdentity(identity);
5883 }
5884 }
5885
5886 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005887 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005888 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005889 */
5890 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5891 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892
5893 final long identity = Binder.clearCallingIdentity();
5894 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005895 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005896 // may happen if the device does not support IMS.
5897 return null;
5898 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005899 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005903 }
5904
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005905 /**
5906 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005907 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005908 */
5909 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5910 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911
5912 final long identity = Binder.clearCallingIdentity();
5913 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005914 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005915 // may happen if the device does not support IMS.
5916 return null;
5917 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005918 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919 } finally {
5920 Binder.restoreCallingIdentity(identity);
5921 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005922 }
5923
Brad Ebinger884c07b2018-02-15 16:17:40 -08005924 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005925 * Sets the ImsService Package Name that Telephony will bind to.
5926 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005927 * @param slotIndex the slot ID that the ImsService should bind for.
5928 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005929 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005930 * @param featureTypes An integer array of feature types associated with a packageName.
5931 * @param packageName The name of the package that the current configuration will be replaced
5932 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005933 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005934 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005935 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5936 int[] featureTypes, String packageName) {
5937 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5938 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5940 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005941 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 final long identity = Binder.clearCallingIdentity();
5944 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005945 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005946 // may happen if the device does not support IMS.
5947 return false;
5948 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005949 Map<Integer, String> featureConfig = new HashMap<>();
5950 for (int featureType : featureTypes) {
5951 featureConfig.put(featureType, packageName);
5952 }
5953 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5954 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955 } finally {
5956 Binder.restoreCallingIdentity(identity);
5957 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005958 }
5959
5960 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005961 * Clears any carrier ImsService overrides for the slot index specified that were previously
5962 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5963 *
5964 * This should only be used for testing.
5965 *
5966 * @param slotIndex the slot ID that the ImsService should bind for.
5967 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5968 */
5969 @Override
5970 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5971 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5972 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5973 "clearCarrierImsServiceOverride");
5974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5975 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5976 "clearCarrierImsServiceOverride");
5977
5978 final long identity = Binder.clearCallingIdentity();
5979 try {
5980 if (mImsResolver == null) {
5981 // may happen if the device does not support IMS.
5982 return false;
5983 }
5984 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5985 } finally {
5986 Binder.restoreCallingIdentity(identity);
5987 }
5988 }
5989
5990 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005991 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005992 *
5993 * @param slotId The slot that the ImsService is associated with.
5994 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5995 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005996 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005997 * @return the package name of the ImsService configuration.
5998 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005999 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6000 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07006001 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08006002 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006003 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08006004 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6005 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 final long identity = Binder.clearCallingIdentity();
6008 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006009 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006010 // may happen if the device does not support IMS.
6011 return "";
6012 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006013 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006014 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6015 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 } finally {
6017 Binder.restoreCallingIdentity(identity);
6018 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006019 }
6020
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006021 /**
6022 * Get the MmTelFeature state associated with the requested subscription id.
6023 * @param subId The subscription that the MmTelFeature is associated with.
6024 * @param callback A callback with an integer containing the
6025 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6026 */
6027 @Override
6028 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6029 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
6030 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6031 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6032 "IMS not available on device.");
6033 }
6034 final long token = Binder.clearCallingIdentity();
6035 try {
6036 int slotId = getSlotIndex(subId);
6037 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6038 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6039 + subId + "'");
6040 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6041 }
Brad Ebinger919631e2021-06-02 17:46:35 -07006042 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006043 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6044 try {
6045 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6046 } catch (RemoteException e) {
6047 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6048 + "Ignore");
6049 }
6050 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006051 } catch (ImsException e) {
6052 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006053 } finally {
6054 Binder.restoreCallingIdentity(token);
6055 }
6056 }
6057
Daniel Brightbb5840b2021-01-12 15:48:18 -08006058 /**
6059 * Sets the ims registration state on all valid {@link Phone}s.
6060 */
6061 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006062 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063
6064 final long identity = Binder.clearCallingIdentity();
6065 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006066 // NOTE: Before S, this method only set the default phone.
6067 for (final Phone phone : PhoneFactory.getPhones()) {
6068 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6069 phone.setImsRegistrationState(registered);
6070 }
6071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 } finally {
6073 Binder.restoreCallingIdentity(identity);
6074 }
Wink Saville36469e72014-06-11 15:17:00 -07006075 }
6076
6077 /**
Stuart Scott54788802015-03-30 13:18:01 -07006078 * Set the network selection mode to automatic.
6079 *
6080 */
6081 @Override
6082 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6084 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085
6086 final long identity = Binder.clearCallingIdentity();
6087 try {
shilufc958392020-01-20 11:36:01 -08006088 if (!isActiveSubscription(subId)) {
6089 return;
6090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006092 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6093 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006094 } finally {
6095 Binder.restoreCallingIdentity(identity);
6096 }
Stuart Scott54788802015-03-30 13:18:01 -07006097 }
6098
Jack Yud10cdd42020-09-28 20:28:01 -07006099 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006100 * Ask the radio to connect to the input network and change selection mode to manual.
6101 *
6102 * @param subId the id of the subscription.
6103 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6104 * the operator to attach to.
6105 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6106 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6107 * normal network selection next time.
6108 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006109 */
6110 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006111 public boolean setNetworkSelectionModeManual(
6112 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6114 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006115
6116 if (!isActiveSubscription(subId)) {
6117 return false;
6118 }
6119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006120 final long identity = Binder.clearCallingIdentity();
6121 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006122 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006124 if (DBG) {
6125 log("setNetworkSelectionModeManual: subId: " + subId
6126 + " operator: " + operatorInfo);
6127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6129 } finally {
6130 Binder.restoreCallingIdentity(identity);
6131 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006132 }
shilu84f6e8b2019-12-19 13:58:01 -08006133 /**
6134 * Get the manual network selection
6135 *
6136 * @param subId the id of the subscription.
6137 *
6138 * @return the previously saved user selected PLMN
6139 */
6140 @Override
6141 public String getManualNetworkSelectionPlmn(int subId) {
6142 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006143 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006144 mApp, subId, "getManualNetworkSelectionPlmn");
6145
6146 final long identity = Binder.clearCallingIdentity();
6147 try {
6148 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006149 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006150 }
6151
6152 final Phone phone = getPhone(subId);
6153 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006154 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006155 }
6156 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6157 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6158 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6159 } finally {
6160 Binder.restoreCallingIdentity(identity);
6161 }
6162 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006163
6164 /**
6165 * Scans for available networks.
6166 */
6167 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006168 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6169 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6171 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006172 LocationAccessPolicy.LocationPermissionResult locationResult =
6173 LocationAccessPolicy.checkLocationPermission(mApp,
6174 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6175 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006176 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006177 .setCallingPid(Binder.getCallingPid())
6178 .setCallingUid(Binder.getCallingUid())
6179 .setMethod("getCellNetworkScanResults")
6180 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006181 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6182 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006183 .build());
6184 switch (locationResult) {
6185 case DENIED_HARD:
6186 throw new SecurityException("Not allowed to access scan results -- location");
6187 case DENIED_SOFT:
6188 return null;
6189 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190
Pengquan Menga1bb6272018-09-06 09:59:22 -07006191 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 try {
6193 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006194 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006195 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006196 } finally {
6197 Binder.restoreCallingIdentity(identity);
6198 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006199 }
6200
6201 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006202 * Get the call forwarding info, given the call forwarding reason.
6203 */
6204 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006205 public void getCallForwarding(int subId, int callForwardingReason,
6206 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006207 enforceReadPrivilegedPermission("getCallForwarding");
6208 long identity = Binder.clearCallingIdentity();
6209 try {
6210 if (DBG) {
6211 log("getCallForwarding: subId " + subId
6212 + " callForwardingReason" + callForwardingReason);
6213 }
Hall Liu27d24262020-09-18 19:04:59 -07006214
6215 Phone phone = getPhone(subId);
6216 if (phone == null) {
6217 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006218 callback.onError(
6219 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006220 } catch (RemoteException e) {
6221 // ignore
6222 }
6223 return;
6224 }
6225
6226 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6227 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6228 @Override
6229 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6230 try {
6231 callback.onCallForwardingInfoAvailable(info);
6232 } catch (RemoteException e) {
6233 // ignore
6234 }
6235 }
6236
6237 @Override
6238 public void onError(int error) {
6239 try {
6240 callback.onError(error);
6241 } catch (RemoteException e) {
6242 // ignore
6243 }
6244 }
6245 });
6246 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006247 } finally {
6248 Binder.restoreCallingIdentity(identity);
6249 }
6250 }
6251
6252 /**
6253 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6254 * reason, the number to forward, and the timeout before the forwarding is attempted.
6255 */
6256 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006257 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6258 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006259 enforceModifyPermission();
6260 long identity = Binder.clearCallingIdentity();
6261 try {
6262 if (DBG) {
6263 log("setCallForwarding: subId " + subId
6264 + " callForwardingInfo" + callForwardingInfo);
6265 }
Hall Liu27d24262020-09-18 19:04:59 -07006266
6267 Phone phone = getPhone(subId);
6268 if (phone == null) {
6269 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006270 callback.accept(
6271 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006272 } catch (RemoteException e) {
6273 // ignore
6274 }
6275 return;
6276 }
6277
6278 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6279 FunctionalUtils.ignoreRemoteException(callback::accept));
6280
6281 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006282 } finally {
6283 Binder.restoreCallingIdentity(identity);
6284 }
6285 }
6286
6287 /**
Hall Liu27d24262020-09-18 19:04:59 -07006288 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006289 */
6290 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006291 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006292 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006293 long identity = Binder.clearCallingIdentity();
6294 try {
Hall Liu27d24262020-09-18 19:04:59 -07006295 Phone phone = getPhone(subId);
6296 if (phone == null) {
6297 try {
6298 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6299 } catch (RemoteException e) {
6300 // ignore
6301 }
6302 return;
6303 }
SongFerngWang0e767992021-03-31 22:08:45 +08006304 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6305 PersistableBundle c = configManager.getConfigForSubId(subId);
6306 boolean requireUssd = c.getBoolean(
6307 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006308
Shuo Qian4a594052020-01-23 11:59:30 -08006309 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006310 if (requireUssd) {
6311 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6312 getSubscriptionCarrierId(subId));
6313 String newUssdCommand = "";
6314 try {
6315 newUssdCommand = carrierXmlParser.getFeature(
6316 CarrierXmlParser.FEATURE_CALL_WAITING)
6317 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6318 } catch (NullPointerException e) {
6319 loge("Failed to generate USSD number" + e);
6320 }
6321 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6322 mMainThreadHandler, callback, carrierXmlParser,
6323 CarrierXmlParser.SsEntry.SSAction.QUERY);
6324 final String ussdCommand = newUssdCommand;
6325 Executors.newSingleThreadExecutor().execute(() -> {
6326 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6327 });
6328 } else {
6329 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6330 callback::accept);
6331 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6332 }
Shuo Qian4a594052020-01-23 11:59:30 -08006333 } finally {
6334 Binder.restoreCallingIdentity(identity);
6335 }
6336 }
6337
6338 /**
Hall Liu27d24262020-09-18 19:04:59 -07006339 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006340 */
6341 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006342 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006343 enforceModifyPermission();
6344 long identity = Binder.clearCallingIdentity();
6345 try {
Hall Liu27d24262020-09-18 19:04:59 -07006346 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6347
6348 Phone phone = getPhone(subId);
6349 if (phone == null) {
6350 try {
6351 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6352 } catch (RemoteException e) {
6353 // ignore
6354 }
6355 return;
6356 }
6357
SongFerngWang0e767992021-03-31 22:08:45 +08006358 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6359 PersistableBundle c = configManager.getConfigForSubId(subId);
6360 boolean requireUssd = c.getBoolean(
6361 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006362
SongFerngWang0e767992021-03-31 22:08:45 +08006363 if (DBG) log("getCallWaitingStatus: subId " + subId);
6364 if (requireUssd) {
6365 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6366 getSubscriptionCarrierId(subId));
6367 CarrierXmlParser.SsEntry.SSAction ssAction =
6368 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6369 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6370 String newUssdCommand = "";
6371 try {
6372 newUssdCommand = carrierXmlParser.getFeature(
6373 CarrierXmlParser.FEATURE_CALL_WAITING)
6374 .makeCommand(ssAction, null);
6375 } catch (NullPointerException e) {
6376 loge("Failed to generate USSD number" + e);
6377 }
6378 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6379 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6380 final String ussdCommand = newUssdCommand;
6381 Executors.newSingleThreadExecutor().execute(() -> {
6382 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6383 });
6384 } else {
6385 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6386 FunctionalUtils.ignoreRemoteException(callback::accept));
6387
6388 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6389 }
Shuo Qian4a594052020-01-23 11:59:30 -08006390 } finally {
6391 Binder.restoreCallingIdentity(identity);
6392 }
6393 }
6394
6395 /**
yinxub1bed742017-04-17 11:45:04 -07006396 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006397 *
yinxub1bed742017-04-17 11:45:04 -07006398 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006399 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6400 * location related information which will be sent if the caller already possess
6401 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006402 * @param request contains the radio access networks with bands/channels to scan
6403 * @param messenger callback messenger for scan results or errors
6404 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006405 * @return the id of the requested scan which can be used to stop the scan.
6406 */
6407 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006408 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6409 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006410 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6412 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006413 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006414 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6415 if (!renounceFineLocationAccess) {
6416 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6417 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6418 .setCallingPackage(callingPackage)
6419 .setCallingFeatureId(callingFeatureId)
6420 .setCallingPid(Binder.getCallingPid())
6421 .setCallingUid(Binder.getCallingUid())
6422 .setMethod("requestNetworkScan")
6423 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6424 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6425 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6426 .build());
6427 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006428 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006429 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6430 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006431 if (e != null) {
6432 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6433 throw e;
6434 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006435 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006436 return TelephonyScanManager.INVALID_SCAN_ID;
6437 }
6438 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439 }
Hall Liu912dfd32019-04-25 14:02:26 -07006440 int callingUid = Binder.getCallingUid();
6441 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006442 final long identity = Binder.clearCallingIdentity();
6443 try {
6444 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006445 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006446 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006447 } finally {
6448 Binder.restoreCallingIdentity(identity);
6449 }
yinxu504e1392017-04-12 16:03:22 -07006450 }
6451
Hall Liub2ac8ef2019-02-28 15:56:23 -08006452 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006453 NetworkScanRequest request, int subId, String callingPackage) {
6454 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006455 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6456 boolean hasNetworkScanPermission =
6457 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6458 == PERMISSION_GRANTED;
6459
6460 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6461 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6462 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006463 }
6464
6465 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6466 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006467 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6468 return new SecurityException("Specific channels must not be"
6469 + " scanned without location access.");
6470 }
6471 }
6472 }
6473
Hall Liub2ac8ef2019-02-28 15:56:23 -08006474 return null;
6475 }
6476
yinxu504e1392017-04-12 16:03:22 -07006477 /**
6478 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006479 *
6480 * @param subId id of the subscription
6481 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006482 */
6483 @Override
6484 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006485 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6486 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487
Hall Liu912dfd32019-04-25 14:02:26 -07006488 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489 final long identity = Binder.clearCallingIdentity();
6490 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006491 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006492 } finally {
6493 Binder.restoreCallingIdentity(identity);
6494 }
yinxu504e1392017-04-12 16:03:22 -07006495 }
6496
6497 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006498 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006499 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006500 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006501 */
6502 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006503 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006504 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006505 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006506 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006507
6508 final long identity = Binder.clearCallingIdentity();
6509 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006510 if (DBG) log("getAllowedNetworkTypesBitmask");
6511 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6512 int networkTypesBitmask = (result != null ? result[0] : -1);
6513 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6514 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006515 } finally {
6516 Binder.restoreCallingIdentity(identity);
6517 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006518 }
6519
6520 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006521 * Get the allowed network types for certain reason.
6522 *
6523 * @param subId the id of the subscription.
6524 * @param reason the reason the allowed network type change is taking place
6525 * @return the allowed network types.
6526 */
6527 @Override
6528 public long getAllowedNetworkTypesForReason(int subId,
6529 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006530 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006531 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006532 final long identity = Binder.clearCallingIdentity();
6533 try {
6534 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6535 } finally {
6536 Binder.restoreCallingIdentity(identity);
6537 }
6538 }
6539
6540 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006541 * Enable/Disable E-UTRA-NR Dual Connectivity
6542 * @param subId subscription id of the sim card
6543 * @param nrDualConnectivityState expected NR dual connectivity state
6544 * This can be passed following states
6545 * <ol>
6546 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6547 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6548 * <li>Disable NR dual connectivity and force secondary cell to be released
6549 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6550 * </ol>
6551 * @return operation result.
6552 */
6553 @Override
6554 public int setNrDualConnectivityState(int subId,
6555 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6557 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006558 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006559 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6560 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6561 }
6562
Sooraj Sasindran37444802020-08-11 10:40:43 -07006563 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6564 final long identity = Binder.clearCallingIdentity();
6565 try {
6566 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6567 nrDualConnectivityState, subId,
6568 workSource);
6569 if (DBG) log("enableNRDualConnectivity result: " + result);
6570 return result;
6571 } finally {
6572 Binder.restoreCallingIdentity(identity);
6573 }
6574 }
6575
6576 /**
6577 * Is E-UTRA-NR Dual Connectivity enabled
6578 * @return true if dual connectivity is enabled else false
6579 */
6580 @Override
6581 public boolean isNrDualConnectivityEnabled(int subId) {
6582 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006583 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006584 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006585 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006586 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6587 return false;
6588 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006589 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6590 final long identity = Binder.clearCallingIdentity();
6591 try {
6592 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6593 null, subId, workSource);
6594 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6595 return isEnabled;
6596 } finally {
6597 Binder.restoreCallingIdentity(identity);
6598 }
6599 }
6600
6601 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006602 * Set the allowed network types of the device and
6603 * provide the reason triggering the allowed network change.
6604 *
6605 * @param subId the id of the subscription.
6606 * @param reason the reason the allowed network type change is taking place
6607 * @param allowedNetworkTypes the allowed network types.
6608 * @return true on success; false on any failure.
6609 */
6610 @Override
6611 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006612 @TelephonyManager.AllowedNetworkTypesReason int reason,
6613 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6615 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006616 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006617 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6618 return false;
6619 }
6620 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6621 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006622 return false;
6623 }
6624
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006625 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6626 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6627
6628
6629 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6630 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6631 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006632 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006633
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006634 final long identity = Binder.clearCallingIdentity();
6635 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006636 Boolean success = (Boolean) sendRequest(
6637 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6638 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6639
6640 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6641 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006642 } finally {
6643 Binder.restoreCallingIdentity(identity);
6644 }
6645 }
6646
6647 /**
Miaoa84611c2019-03-15 09:21:10 +08006648 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006649 *
Miaoa84611c2019-03-15 09:21:10 +08006650 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006651 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006652 * @hide
6653 */
6654 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006655 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006656 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006658 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659 try {
Miaoa84611c2019-03-15 09:21:10 +08006660 if (phone != null) {
6661 return phone.hasMatchedTetherApnSetting();
6662 } else {
6663 return false;
6664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665 } finally {
6666 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006667 }
Junda Liu475951f2014-11-07 16:45:03 -08006668 }
6669
6670 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006671 * Get the user enabled state of Mobile Data.
6672 *
6673 * TODO: remove and use isUserDataEnabled.
6674 * This can't be removed now because some vendor codes
6675 * calls through ITelephony directly while they should
6676 * use TelephonyManager.
6677 *
6678 * @return true on enabled
6679 */
6680 @Override
6681 public boolean getDataEnabled(int subId) {
6682 return isUserDataEnabled(subId);
6683 }
6684
6685 /**
6686 * Get whether mobile data is enabled per user setting.
6687 *
6688 * There are other factors deciding whether mobile data is actually enabled, but they are
6689 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006690 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006691 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6692 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006693 *
6694 * @return {@code true} if data is enabled else {@code false}
6695 */
6696 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006697 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006698 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006699 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006700 try {
6701 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6702 functionName);
6703 } catch (Exception e) {
6704 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6705 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006706 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006708 mApp, subId, functionName);
6709
Robert Greenwalt646120a2014-05-23 11:54:03 -07006710 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711
6712 final long identity = Binder.clearCallingIdentity();
6713 try {
6714 int phoneId = mSubscriptionController.getPhoneId(subId);
6715 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6716 Phone phone = PhoneFactory.getPhone(phoneId);
6717 if (phone != null) {
6718 boolean retVal = phone.isUserDataEnabled();
6719 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6720 return retVal;
6721 } else {
6722 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6723 return false;
6724 }
6725 } finally {
6726 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006727 }
6728 }
6729
6730 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006731 * Checks if the device is capable of mobile data by considering whether whether the
6732 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6733 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006734 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006735 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006736 */
6737 @Override
6738 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006739 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006740 try {
6741 try {
6742 mApp.enforceCallingOrSelfPermission(
6743 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006744 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006745 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006746 try {
6747 mApp.enforceCallingOrSelfPermission(
6748 android.Manifest.permission.READ_PHONE_STATE,
6749 functionName);
6750 } catch (Exception e2) {
6751 mApp.enforceCallingOrSelfPermission(
6752 permission.READ_BASIC_PHONE_STATE, functionName);
6753 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006754 }
6755 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006756 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758
6759 final long identity = Binder.clearCallingIdentity();
6760 try {
6761 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762 Phone phone = PhoneFactory.getPhone(phoneId);
6763 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006764 boolean retVal;
6765 if (phone.isUsingNewDataStack()) {
6766 retVal = phone.getDataNetworkController().getDataSettingsManager()
6767 .isDataEnabled();
6768 } else {
6769 retVal = phone.getDataEnabledSettings().isDataEnabled();
6770 }
6771 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772 return retVal;
6773 } else {
6774 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6775 return false;
6776 }
6777 } finally {
6778 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006779 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006780 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006781
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006782 /**
6783 * Check if data is enabled for a specific reason
6784 * @param subId Subscription index
6785 * @param reason the reason the data enable change is taking place
6786 * @return {@code true} if the overall data is enabled; {@code false} if not.
6787 */
6788 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006789 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006790 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006791 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006792 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006793 try {
6794 mApp.enforceCallingOrSelfPermission(
6795 android.Manifest.permission.ACCESS_NETWORK_STATE,
6796 functionName);
6797 } catch (Exception e) {
6798 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6799 functionName);
6800 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006801 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006802 try {
6803 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006804 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006805 } catch (Exception e2) {
6806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006807 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006808 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006809 }
6810
6811
6812 final long identity = Binder.clearCallingIdentity();
6813 try {
6814 int phoneId = mSubscriptionController.getPhoneId(subId);
6815 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006816 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006817 + " reason=" + reason);
6818 }
6819 Phone phone = PhoneFactory.getPhone(phoneId);
6820 if (phone != null) {
6821 boolean retVal;
Jack Yu99e87332021-12-17 23:14:15 -08006822 if (phone.isUsingNewDataStack()) {
6823 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006824 } else {
Jack Yu99e87332021-12-17 23:14:15 -08006825 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6826 retVal = phone.isUserDataEnabled();
6827 } else {
6828 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6829 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006830 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006831 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006832 return retVal;
6833 } else {
6834 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006835 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006836 + subId + " retVal=false");
6837 }
6838 return false;
6839 }
6840 } finally {
6841 Binder.restoreCallingIdentity(identity);
6842 }
6843 }
6844
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006845 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006846 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006847 if (uid == Process.PHONE_UID) {
6848 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6849 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006850 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6851 }
6852
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006853 //load access rules from carrier configs, and check those as well: b/139133814
6854 SubscriptionController subController = SubscriptionController.getInstance();
6855 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6856 || subController == null) return privilegeFromSim;
6857
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006858 PackageManager pkgMgr = phone.getContext().getPackageManager();
6859 String[] packages = pkgMgr.getPackagesForUid(uid);
6860
6861 final long identity = Binder.clearCallingIdentity();
6862 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006863 int subId = phone.getSubId();
6864 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6865 // A test override is in place for the privileges for this subId, so don't try to
6866 // read the subscription privileges.
6867 return privilegeFromSim;
6868 }
6869 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006870 SubscriptionManager subManager = (SubscriptionManager)
6871 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6872 for (String pkg : packages) {
6873 if (subManager.canManageSubscription(subInfo, pkg)) {
6874 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6875 }
6876 }
6877 return privilegeFromSim;
6878 } finally {
6879 Binder.restoreCallingIdentity(identity);
6880 }
6881 }
6882
6883 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6884 String pkgName) {
6885 //load access rules from carrier configs, and check those as well: b/139133814
6886 SubscriptionController subController = SubscriptionController.getInstance();
6887 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6888 || subController == null) return privilegeFromSim;
6889
6890 final long identity = Binder.clearCallingIdentity();
6891 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006892 int subId = phone.getSubId();
6893 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6894 // A test override is in place for the privileges for this subId, so don't try to
6895 // read the subscription privileges.
6896 return privilegeFromSim;
6897 }
6898 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006899 SubscriptionManager subManager = (SubscriptionManager)
6900 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6901 return subManager.canManageSubscription(subInfo, pkgName)
6902 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6903 } finally {
6904 Binder.restoreCallingIdentity(identity);
6905 }
6906 }
6907
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006908 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006909 public int getCarrierPrivilegeStatus(int subId) {
6910 final Phone phone = getPhone(subId);
6911 if (phone == null) {
6912 loge("getCarrierPrivilegeStatus: Invalid subId");
6913 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6914 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006915 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6916 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006917 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006918 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6919 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006920
6921 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006922 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006923 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006924 }
Junda Liu29340342014-07-10 15:23:27 -07006925
6926 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006927 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006928 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006929 final Phone phone = getPhone(subId);
6930 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006931 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006932 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6933 }
6934 UiccProfile profile =
6935 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6936 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006937 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006938 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6939 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006940 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006941 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006942 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006943 }
6944
6945 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006946 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006947 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006948 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006949 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006950 }
6951
6952 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006953 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6954 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006955 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006956 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6957 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006958 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006959 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006960 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006961 }
6962
6963 @Override
6964 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006965 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006966 if (TextUtils.isEmpty(pkgName))
6967 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006968 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6969 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006970 UiccPort port = UiccController.getInstance().getUiccPort(i);
6971 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006972 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006973 continue;
6974 }
6975
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006976 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006977 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006978 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006979 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6980 break;
6981 }
6982 }
6983
6984 return result;
Junda Liu29340342014-07-10 15:23:27 -07006985 }
Derek Tan89e89d42014-07-08 17:00:10 -07006986
6987 @Override
Junda Liue64de782015-04-16 17:19:16 -07006988 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006989 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006990 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6991 loge("phoneId " + phoneId + " is not valid.");
6992 return null;
6993 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006994 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6995 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006996 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006997 return null ;
6998 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006999 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007000 }
7001
Amith Yamasani6e118872016-02-19 12:53:51 -08007002 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007003 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007004 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007005 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08007006 List<String> privilegedPackages = new ArrayList<>();
7007 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007008 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07007009 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007010 if (port != null) {
7011 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08007012 if (packages == null) {
7013 // Only check packages in user 0 for now
7014 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07007015 PackageManager.MATCH_DISABLED_COMPONENTS
7016 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09007017 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08007018 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08007019 }
7020 for (int p = packages.size() - 1; p >= 0; p--) {
7021 PackageInfo pkgInfo = packages.get(p);
7022 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00007023 && getCarrierPrivilegeStatusFromCarrierConfigRules(
7024 port.getCarrierPrivilegeStatus(pkgInfo),
7025 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07007026 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08007027 privilegedPackages.add(pkgInfo.packageName);
7028 }
7029 }
7030 }
7031 }
7032 return privilegedPackages;
7033 }
7034
chen xuf7e9fe82019-05-09 19:31:02 -07007035 @Override
7036 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007037 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
7038
7039 final long identity = Binder.clearCallingIdentity();
7040
chen xuf7e9fe82019-05-09 19:31:02 -07007041 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007042 try {
7043 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7044 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7045 }
7046 } finally {
7047 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007048 }
7049 return privilegedPackages;
7050 }
7051
Wink Savilleb564aae2014-10-23 10:18:09 -07007052 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007053 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007054 UiccPort port = phone == null ? null : phone.getUiccPort();
7055 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007056 return null;
7057 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007058 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007059 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007060 return null;
7061 }
7062 return iccId;
7063 }
7064
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007065 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007066 public void setCallComposerStatus(int subId, int status) {
7067 enforceModifyPermission();
7068
7069 final long identity = Binder.clearCallingIdentity();
7070 try {
7071 Phone phone = getPhone(subId);
7072 if (phone != null) {
7073 Phone defaultPhone = phone.getImsPhone();
7074 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7075 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7076 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007077 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7078 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007079 }
7080 }
Shuo Qian284ae752020-12-22 19:10:14 -08007081 } catch (ImsException e) {
7082 throw new ServiceSpecificException(e.getCode());
7083 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007084 Binder.restoreCallingIdentity(identity);
7085 }
7086 }
7087
7088 @Override
7089 public int getCallComposerStatus(int subId) {
7090 enforceReadPrivilegedPermission("getCallComposerStatus");
7091
7092 final long identity = Binder.clearCallingIdentity();
7093 try {
7094 Phone phone = getPhone(subId);
7095 if (phone != null) {
7096 Phone defaultPhone = phone.getImsPhone();
7097 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7098 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7099 return imsPhone.getCallComposerStatus();
7100 }
7101 }
7102 } finally {
7103 Binder.restoreCallingIdentity(identity);
7104 }
7105 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7106 }
7107
7108 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007109 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7110 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007111 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007112 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007113
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007114 final long identity = Binder.clearCallingIdentity();
7115 try {
7116 final String iccId = getIccId(subId);
7117 final Phone phone = getPhone(subId);
7118 if (phone == null) {
7119 return false;
7120 }
7121 final String subscriberId = phone.getSubscriberId();
7122
7123 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007124 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007125 + subscriberId + " to " + number);
7126 }
7127
7128 if (TextUtils.isEmpty(iccId)) {
7129 return false;
7130 }
7131
7132 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7133
7134 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7135 if (alphaTag == null) {
7136 editor.remove(alphaTagPrefKey);
7137 } else {
7138 editor.putString(alphaTagPrefKey, alphaTag);
7139 }
7140
7141 // Record both the line number and IMSI for this ICCID, since we need to
7142 // track all merged IMSIs based on line number
7143 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7144 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7145 if (number == null) {
7146 editor.remove(numberPrefKey);
7147 editor.remove(subscriberPrefKey);
7148 } else {
7149 editor.putString(numberPrefKey, number);
7150 editor.putString(subscriberPrefKey, subscriberId);
7151 }
7152
7153 editor.commit();
7154 return true;
7155 } finally {
7156 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007157 }
Derek Tan7226c842014-07-02 17:42:23 -07007158 }
7159
7160 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007161 public String getLine1NumberForDisplay(int subId, String callingPackage,
7162 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007163 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007165 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007166 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007167 return null;
7168 }
Derek Tan97ebb422014-09-05 16:55:38 -07007169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170 final long identity = Binder.clearCallingIdentity();
7171 try {
7172 String iccId = getIccId(subId);
7173 if (iccId != null) {
7174 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7175 if (DBG_MERGE) {
7176 log("getLine1NumberForDisplay returning "
7177 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7178 }
7179 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007180 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7182 return null;
7183 } finally {
7184 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007185 }
Derek Tan7226c842014-07-02 17:42:23 -07007186 }
7187
7188 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007189 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7190 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007192 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007193 return null;
7194 }
Derek Tan97ebb422014-09-05 16:55:38 -07007195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196 final long identity = Binder.clearCallingIdentity();
7197 try {
7198 String iccId = getIccId(subId);
7199 if (iccId != null) {
7200 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7201 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7202 }
7203 return null;
7204 } finally {
7205 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007206 }
Derek Tan7226c842014-07-02 17:42:23 -07007207 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007208
7209 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007210 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7211 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007212 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7213 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007215 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007216 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007217 return null;
7218 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007219
Jordan Liub49b04b2019-05-06 14:45:15 -07007220 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7221 // the process, where TelephonyManager was instantiated.
7222 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007223 final long identity = Binder.clearCallingIdentity();
7224 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007225 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007226 final TelephonyManager tele = TelephonyManager.from(context);
7227 final SubscriptionManager sub = SubscriptionManager.from(context);
7228
7229 // Figure out what subscribers are currently active
7230 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007231
Jordan Liub49b04b2019-05-06 14:45:15 -07007232 // Only consider subs which match the current subId
7233 // This logic can be simplified. See b/131189269 for progress.
7234 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007235 activeSubscriberIds.add(tele.getSubscriberId(subId));
7236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237
7238 // First pass, find a number override for an active subscriber
7239 String mergeNumber = null;
7240 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7241 for (String key : prefs.keySet()) {
7242 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7243 final String subscriberId = (String) prefs.get(key);
7244 if (activeSubscriberIds.contains(subscriberId)) {
7245 final String iccId = key.substring(
7246 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7247 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7248 mergeNumber = (String) prefs.get(numberKey);
7249 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007250 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251 + " for active subscriber " + subscriberId);
7252 }
7253 if (!TextUtils.isEmpty(mergeNumber)) {
7254 break;
7255 }
7256 }
7257 }
7258 }
7259
7260 // Shortcut when no active merged subscribers
7261 if (TextUtils.isEmpty(mergeNumber)) {
7262 return null;
7263 }
7264
7265 // Second pass, find all subscribers under that line override
7266 final ArraySet<String> result = new ArraySet<>();
7267 for (String key : prefs.keySet()) {
7268 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7269 final String number = (String) prefs.get(key);
7270 if (mergeNumber.equals(number)) {
7271 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7272 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7273 final String subscriberId = (String) prefs.get(subscriberKey);
7274 if (!TextUtils.isEmpty(subscriberId)) {
7275 result.add(subscriberId);
7276 }
7277 }
7278 }
7279 }
7280
7281 final String[] resultArray = result.toArray(new String[result.size()]);
7282 Arrays.sort(resultArray);
7283 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007284 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007285 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7286 }
7287 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007288 } finally {
7289 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007290 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007291 }
7292
7293 @Override
zoey chen38003472019-12-13 17:16:31 +08007294 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7295 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007296
7297 final long identity = Binder.clearCallingIdentity();
7298 try {
7299 final TelephonyManager telephonyManager = mApp.getSystemService(
7300 TelephonyManager.class);
7301 String subscriberId = telephonyManager.getSubscriberId(subId);
7302 if (subscriberId == null) {
7303 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007304 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007305 + subId);
7306 }
7307 return null;
7308 }
7309
7310 final SubscriptionInfo info = SubscriptionController.getInstance()
7311 .getSubscriptionInfo(subId);
7312 final ParcelUuid groupUuid = info.getGroupUuid();
7313 // If it doesn't belong to any group, return just subscriberId of itself.
7314 if (groupUuid == null) {
7315 return new String[]{subscriberId};
7316 }
7317
7318 // Get all subscriberIds from the group.
7319 final List<String> mergedSubscriberIds = new ArrayList<>();
7320 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007321 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007322 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007323 for (SubscriptionInfo subInfo : groupInfos) {
7324 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7325 if (subscriberId != null) {
7326 mergedSubscriberIds.add(subscriberId);
7327 }
7328 }
7329
7330 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7331 } finally {
7332 Binder.restoreCallingIdentity(identity);
7333
7334 }
7335 }
7336
7337 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007338 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007339 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007340 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341
7342 final long identity = Binder.clearCallingIdentity();
7343 try {
7344 final Phone phone = getPhone(subId);
7345 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7346 } finally {
7347 Binder.restoreCallingIdentity(identity);
7348 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007349 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007350
7351 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007352 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007353 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7354 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007355 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7356 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007357
7358 final long identity = Binder.clearCallingIdentity();
7359 try {
7360 final Phone phone = getPhone(subId);
7361 if (phone == null) {
7362 return false;
7363 }
7364 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7365 cdmaNonRoamingList);
7366 } finally {
7367 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007368 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007369 }
7370
7371 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007372 @Deprecated
7373 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7374 enforceModifyPermission();
7375
7376 int returnValue = 0;
7377 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007378 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007379 if(result.exception == null) {
7380 if (result.result != null) {
7381 byte[] responseData = (byte[])(result.result);
7382 if(responseData.length > oemResp.length) {
7383 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7384 responseData.length + "bytes. Buffer Size is " +
7385 oemResp.length + "bytes.");
7386 }
7387 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7388 returnValue = responseData.length;
7389 }
7390 } else {
7391 CommandException ex = (CommandException) result.exception;
7392 returnValue = ex.getCommandError().ordinal();
7393 if(returnValue > 0) returnValue *= -1;
7394 }
7395 } catch (RuntimeException e) {
7396 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7397 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7398 if(returnValue > 0) returnValue *= -1;
7399 }
7400
7401 return returnValue;
7402 }
7403
7404 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007405 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007406 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007407 try {
7408 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007409 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007410 mApp, phone.getSubId(), "getRadioAccessFamily");
7411 } catch (SecurityException e) {
7412 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7413 throw e;
7414 }
chen xub97461a2018-10-26 14:17:57 -07007415 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007416 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007417 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419 final long identity = Binder.clearCallingIdentity();
7420 try {
chen xub97461a2018-10-26 14:17:57 -07007421 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007422 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007423 mApp, phone.getSubId(), "getRadioAccessFamily");
7424 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007425 } finally {
7426 Binder.restoreCallingIdentity(identity);
7427 }
chen xub97461a2018-10-26 14:17:57 -07007428 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007429 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007430
7431 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007432 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007433 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007434 try {
7435 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7436 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007437 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007438 }
7439 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007440 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007441 }
7442 RoleManager rm = mApp.getSystemService(RoleManager.class);
7443 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7444 if (!dialerRoleHolders.contains(callingPackage)) {
7445 throw new SecurityException("App must be the dialer role holder to"
7446 + " upload a call composer pic");
7447 }
7448
7449 Executors.newSingleThreadExecutor().execute(() -> {
7450 ByteArrayOutputStream output = new ByteArrayOutputStream(
7451 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7452 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7453 boolean readUntilEnd = false;
7454 int totalBytesRead = 0;
7455 byte[] buffer = new byte[16 * 1024];
7456 while (true) {
7457 int numRead;
7458 try {
7459 numRead = input.read(buffer);
7460 } catch (IOException e) {
7461 try {
7462 fd.checkError();
7463 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7464 null);
7465 } catch (IOException e1) {
7466 // This means that the other side closed explicitly with an error. If this
7467 // happens, log and ignore.
7468 loge("Remote end of call composer picture pipe closed: " + e1);
7469 }
7470 break;
7471 }
7472 if (numRead == -1) {
7473 readUntilEnd = true;
7474 break;
7475 }
7476 totalBytesRead += numRead;
7477 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7478 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7479 try {
7480 input.close();
7481 } catch (IOException e) {
7482 // ignore
7483 }
7484 break;
7485 }
7486 output.write(buffer, 0, numRead);
7487 }
7488 // Generally, the remote end will close the file descriptors. The only case where we
7489 // close is above, where the picture size is too big.
7490
7491 try {
7492 fd.checkError();
7493 } catch (IOException e) {
7494 loge("Remote end for call composer closed with an error: " + e);
7495 return;
7496 }
7497
Hall Liuaa4211e2021-01-20 15:43:39 -08007498 if (!readUntilEnd) {
7499 loge("Did not finish reading entire image; aborting");
7500 return;
7501 }
Hall Liu82694d52020-12-11 18:22:04 -08007502
Hall Liuaa4211e2021-01-20 15:43:39 -08007503 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7504 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7505 new CallComposerPictureTransfer.Factory() {},
7506 imageData,
7507 (result) -> {
7508 if (result.first != null) {
7509 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7510 Bundle outputResult = new Bundle();
7511 outputResult.putParcelable(
7512 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7513 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7514 outputResult);
7515 } else {
7516 callback.send(result.second, null);
7517 }
7518 }
7519 );
Hall Liu82694d52020-12-11 18:22:04 -08007520 });
7521 }
7522
7523 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007524 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007525 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007526 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527
7528 final long identity = Binder.clearCallingIdentity();
7529 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007530 ImsManager.getInstance(defaultPhone.getContext(),
7531 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 } finally {
7533 Binder.restoreCallingIdentity(identity);
7534 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007535 }
7536
7537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007538 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007539 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7541 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007542 return false;
7543 }
Svet Ganovb320e182015-04-16 12:30:10 -07007544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 final long identity = Binder.clearCallingIdentity();
7546 try {
7547 // Check the user preference and the system-level IMS setting. Even if the user has
7548 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7549 // In the long run, we may instead need to check if there exists a connection service
7550 // which can support video calling.
7551 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007552 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007553 return imsManager.isVtEnabledByPlatform()
7554 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7555 && imsManager.isVtEnabledByUser();
7556 } finally {
7557 Binder.restoreCallingIdentity(identity);
7558 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007559 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007560
Andrew Leea1239f22015-03-02 17:44:07 -08007561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007562 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7563 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007565 mApp, subId, callingPackage, callingFeatureId,
7566 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007567 return false;
7568 }
7569
7570 final long identity = Binder.clearCallingIdentity();
7571 try {
7572 CarrierConfigManager configManager =
7573 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007574 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007575 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7576 } finally {
7577 Binder.restoreCallingIdentity(identity);
7578 }
Andrew Leea1239f22015-03-02 17:44:07 -08007579 }
7580
7581 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007582 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007584 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007585 return false;
7586 }
7587
7588 final long identity = Binder.clearCallingIdentity();
7589 try {
7590 CarrierConfigManager configManager =
7591 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007592 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7594 } finally {
7595 Binder.restoreCallingIdentity(identity);
7596 }
Andrew Leea1239f22015-03-02 17:44:07 -08007597 }
7598
Andrew Lee9431b832015-03-09 18:46:45 -07007599 @Override
7600 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007601 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007602 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007603 }
7604
7605 @Override
7606 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007607 final long identity = Binder.clearCallingIdentity();
7608 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007609 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007610 } finally {
7611 Binder.restoreCallingIdentity(identity);
7612 }
Andrew Lee9431b832015-03-09 18:46:45 -07007613 }
7614
Hall Liuf6668912018-10-31 17:05:23 -07007615 /**
7616 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7617 * support for the feature and device firmware support.
7618 *
7619 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7620 */
7621 @Override
7622 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007623 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007624 final Phone phone = getPhone(subscriptionId);
7625 if (phone == null) {
7626 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7627 return false;
7628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007629 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007630 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007631 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7632 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007633 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634 return isCarrierSupported && isDeviceSupported;
7635 } finally {
7636 Binder.restoreCallingIdentity(identity);
7637 }
Hall Liu98187582018-01-22 19:15:32 -08007638 }
7639
Hall Liuf6668912018-10-31 17:05:23 -07007640 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007641 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7642 * RTT setting, will return true if the device and carrier both support RTT.
7643 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007644 */
7645 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007646 final long identity = Binder.clearCallingIdentity();
7647 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007648 boolean isRttSupported = isRttSupported(subscriptionId);
7649 boolean isUserRttSettingOn = Settings.Secure.getInt(
7650 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7651 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7652 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7653 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007654 } finally {
7655 Binder.restoreCallingIdentity(identity);
7656 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007657 }
7658
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007659 @Deprecated
7660 @Override
7661 public String getDeviceId(String callingPackage) {
7662 return getDeviceIdWithFeature(callingPackage, null);
7663 }
7664
Sanket Padawe7310cc72015-01-14 09:53:20 -08007665 /**
7666 * Returns the unique device ID of phone, for example, the IMEI for
7667 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7668 *
7669 * <p>Requires Permission:
7670 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7671 */
7672 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007673 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007674 try {
7675 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7676 } catch (SecurityException se) {
7677 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7678 throw new SecurityException("Package " + callingPackage + " does not belong to "
7679 + Binder.getCallingUid());
7680 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007681 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007682 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007683 return null;
7684 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007685 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007686 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007687 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007688 return null;
7689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690
7691 final long identity = Binder.clearCallingIdentity();
7692 try {
7693 return phone.getDeviceId();
7694 } finally {
7695 Binder.restoreCallingIdentity(identity);
7696 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007697 }
7698
Ping Sunc67b7c22016-03-02 19:16:45 +08007699 /**
7700 * {@hide}
7701 * Returns the IMS Registration Status on a particular subid
7702 *
7703 * @param subId
7704 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007705 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007706 Phone phone = getPhone(subId);
7707 if (phone != null) {
7708 return phone.isImsRegistered();
7709 } else {
7710 return false;
7711 }
7712 }
7713
Santos Cordon7a1885b2015-02-03 11:15:19 -08007714 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007715 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007716 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007717 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007718 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007719 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7720 }
7721 final long identity = Binder.clearCallingIdentity();
7722 try {
7723 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7724 } finally {
7725 Binder.restoreCallingIdentity(identity);
7726 }
7727 }
7728
7729 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007730 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007731 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007732 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007733 mApp,
7734 subscriptionId,
7735 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007736 final long identity = Binder.clearCallingIdentity();
7737 try {
7738 Phone phone = getPhone(subscriptionId);
7739 if (phone == null) {
7740 return null;
7741 }
7742 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7743 } finally {
7744 Binder.restoreCallingIdentity(identity);
7745 }
7746 }
7747
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007748 /**
7749 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007750 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007751 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007752 final long identity = Binder.clearCallingIdentity();
7753 try {
7754 Phone phone = getPhone(subId);
7755 if (phone != null) {
7756 return phone.isWifiCallingEnabled();
7757 } else {
7758 return false;
7759 }
7760 } finally {
7761 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007762 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007763 }
7764
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007765 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007766 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007767 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007768 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769 final long identity = Binder.clearCallingIdentity();
7770 try {
7771 Phone phone = getPhone(subId);
7772 if (phone != null) {
7773 return phone.isVideoEnabled();
7774 } else {
7775 return false;
7776 }
7777 } finally {
7778 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007779 }
7780 }
7781
7782 /**
7783 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7784 * defined in {@link ImsRegistrationImplBase}.
7785 */
7786 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007787 final long identity = Binder.clearCallingIdentity();
7788 try {
7789 Phone phone = getPhone(subId);
7790 if (phone != null) {
7791 return phone.getImsRegistrationTech();
7792 } else {
7793 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7794 }
7795 } finally {
7796 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007797 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007798 }
7799
Stuart Scott8eef64f2015-04-08 15:13:54 -07007800 @Override
7801 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007802 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007803 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7804 return;
7805 }
Kai Shif70f46f2021-03-03 13:59:46 -08007806 Phone defaultPhone = getDefaultPhone();
7807 if (defaultPhone != null) {
7808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7809 mApp, getDefaultPhone().getSubId(), "factoryReset");
7810 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007811 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007812
Svet Ganovcc087f82015-05-12 20:35:54 -07007813 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007814 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7815 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007816 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007817 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007818 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007819 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007820 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007821 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007822 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007823 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007824 // There has been issues when Sms raw table somehow stores orphan
7825 // fragments. They lead to garbled message when new fragments come
7826 // in and combined with those stale ones. In case this happens again,
7827 // user can reset all network settings which will clean up this table.
7828 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007829 // Clean up IMS settings as well here.
7830 int slotId = getSlotIndex(subId);
7831 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7832 ImsManager.getInstance(mApp, slotId).factoryReset();
7833 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007834
Kai Shif70f46f2021-03-03 13:59:46 -08007835 if (defaultPhone == null) {
7836 return;
7837 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007838 // Erase modem config if erase modem on network setting is enabled.
7839 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7840 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7841 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007842 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007843 }
Kai Shif70f46f2021-03-03 13:59:46 -08007844
7845 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007846 } finally {
7847 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007848 }
7849 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007850
SongFerngWangfd89b102021-05-27 22:44:54 +08007851 @VisibleForTesting
7852 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7853 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7854 return;
7855 }
7856 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7857 RILConstants.PREFERRED_NETWORK_MODE);
7858 SubscriptionManager.setSubscriptionProperty(subId,
7859 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7860 "user=" + defaultNetworkType);
7861 phone.loadAllowedNetworksFromSubscriptionDatabase();
7862 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7863 defaultNetworkType, null);
7864 }
7865
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007866 private void cleanUpSmsRawTable(Context context) {
7867 ContentResolver resolver = context.getContentResolver();
7868 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7869 resolver.delete(uri, null, null);
7870 }
7871
Narayan Kamath1c496c22015-04-16 14:40:19 +01007872 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007873 public String getSimLocaleForSubscriber(int subId) {
7874 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7875 final Phone phone = getPhone(subId);
7876 if (phone == null) {
7877 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007878 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007880 final long identity = Binder.clearCallingIdentity();
7881 try {
chen xu5d3637b2019-01-21 23:31:38 -08007882 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007883 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007884 if (info == null) {
7885 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7886 return null;
7887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007888 // Try and fetch the locale from the carrier properties or from the SIM language
7889 // preferences (EF-PL and EF-LI)...
7890 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007892 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7893 if (localeFromDefaultSim != null) {
7894 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7895 if (DBG) log("Using locale from subId: " + subId + " locale: "
7896 + localeFromDefaultSim);
7897 return localeFromDefaultSim.toLanguageTag();
7898 } else {
7899 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 }
7901 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007903 // The SIM language preferences only store a language (e.g. fr = French), not an
7904 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7905 // the SIM and carrier preferences does not include a country we add the country
7906 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007907 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007908 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007909 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007910 return mccLocale.toLanguageTag();
7911 }
7912
7913 if (DBG) log("No locale found - returning null");
7914 return null;
7915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007918 }
7919
7920 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007921 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007922 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007923 }
7924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925 /**
7926 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7927 */
7928 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007929 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007930 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007931 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007932
Gary Jian3aa9a762022-01-24 16:41:19 +08007933 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7934 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007935
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007936 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007937 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7938 * representing the state of the modem.
7939 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007940 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7941 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007942 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007943 */
7944 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007945 public void requestModemActivityInfo(ResultReceiver result) {
7946 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007947 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948
7949 final long identity = Binder.clearCallingIdentity();
7950 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007951 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952 } finally {
7953 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007954 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007955 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007956
Siddharth Rayb8114062018-06-17 15:02:38 -07007957 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7958 // less than total activity duration.
7959 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7960 if (info == null) {
7961 return false;
7962 }
7963 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007964 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7965 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7966
Siddharth Rayb8114062018-06-17 15:02:38 -07007967 return (info.isValid()
7968 && (info.getSleepTimeMillis() <= activityDurationMs)
7969 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007970 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007971 && (totalTxTimeMs <= activityDurationMs));
7972 }
7973
Gary Jian3aa9a762022-01-24 16:41:19 +08007974 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7975 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7976 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7977 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7978
7979 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7980 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7981 }
7982
7983 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7984 mLastModemActivityInfo.setReceiveTimeMillis(
7985 rat,
7986 freq,
7987 info.getReceiveTimeMillis(rat, freq)
7988 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7989 }
7990
7991 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7992 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7993 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7994 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7995
7996 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7997 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7998 }
7999 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8000 mLastModemActivityInfo.setReceiveTimeMillis(
8001 rat,
8002 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8003 }
8004
8005 /**
8006 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8007 * @param info recent ModemActivityInfo
8008 */
8009 private void mergeModemActivityInfo(ModemActivityInfo info) {
8010 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
8011 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
8012 boolean matched;
8013 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8014 matched = false;
8015 int rat = info.getSpecificInfoRat(i);
8016 int freq = info.getSpecificInfoFrequencyRange(i);
8017 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8018 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8019 //if it already exists
8020 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8021 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8022 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8023 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8024 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8025 updateLastModemActivityInfo(info, rat, freq);
8026 matched = true;
8027 }
8028 } else {
8029 updateLastModemActivityInfo(info, rat);
8030 matched = true;
8031 }
8032 }
8033 }
8034
8035 if (!matched) {
8036 mDeltaSpecificInfo =
8037 new ActivityStatsTechSpecificInfo(
8038 rat,
8039 freq,
8040 info.getTransmitTimeMillis(rat, freq),
8041 (int) info.getReceiveTimeMillis(rat, freq));
8042 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
8043 }
8044 }
8045 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8046 mLastModemActivitySpecificInfo =
8047 new ActivityStatsTechSpecificInfo[merged.size()];
8048 merged.toArray(mLastModemActivitySpecificInfo);
8049
8050 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8051 mLastModemActivityInfo.setSleepTimeMillis(
8052 info.getSleepTimeMillis()
8053 + mLastModemActivityInfo.getSleepTimeMillis());
8054 mLastModemActivityInfo.setIdleTimeMillis(
8055 info.getIdleTimeMillis()
8056 + mLastModemActivityInfo.getIdleTimeMillis());
8057 }
8058
Jack Yu85bd38a2015-11-09 11:34:32 -08008059 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008060 * Returns the service state information on specified subscription.
8061 */
8062 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008063 public ServiceState getServiceStateForSubscriber(int subId,
8064 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8065 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008067 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008068 return null;
8069 }
8070
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008071 boolean hasFinePermission = false;
8072 boolean hasCoarsePermission = false;
8073 if (!renounceFineLocationAccess) {
8074 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8075 LocationAccessPolicy.checkLocationPermission(mApp,
8076 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8077 .setCallingPackage(callingPackage)
8078 .setCallingFeatureId(callingFeatureId)
8079 .setCallingPid(Binder.getCallingPid())
8080 .setCallingUid(Binder.getCallingUid())
8081 .setMethod("getServiceStateForSubscriber")
8082 .setLogAsInfo(true)
8083 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8084 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8085 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8086 .build());
8087 hasFinePermission =
8088 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8089 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008090
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008091 if (!renounceCoarseLocationAccess) {
8092 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8093 LocationAccessPolicy.checkLocationPermission(mApp,
8094 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8095 .setCallingPackage(callingPackage)
8096 .setCallingFeatureId(callingFeatureId)
8097 .setCallingPid(Binder.getCallingPid())
8098 .setCallingUid(Binder.getCallingUid())
8099 .setMethod("getServiceStateForSubscriber")
8100 .setLogAsInfo(true)
8101 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8102 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8103 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8104 .build());
8105 hasCoarsePermission =
8106 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8107 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008108
Jack Yu479f40e2020-10-27 21:29:25 -07008109 final Phone phone = getPhone(subId);
8110 if (phone == null) {
8111 return null;
8112 }
8113
Jordan Liu0f2bc442020-11-18 16:47:37 -08008114 final long identity = Binder.clearCallingIdentity();
8115
Jack Yu479f40e2020-10-27 21:29:25 -07008116 boolean isCallingPackageDataService = phone.getDataServicePackages()
8117 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008118 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008119 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8120 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8121 Rlog.d(LOG_TAG,
8122 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8123 return null;
8124 }
8125
Hall Liuf19c44f2018-11-27 14:38:17 -08008126 ServiceState ss = phone.getServiceState();
8127
8128 // Scrub out the location info in ServiceState depending on what level of access
8129 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008130 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008131 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8132 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133 } finally {
8134 Binder.restoreCallingIdentity(identity);
8135 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008136 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008137
8138 /**
8139 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8140 *
8141 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8142 * voicemail ringtone.
8143 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8144 * PhoneAccount.
8145 */
8146 @Override
8147 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008148 final long identity = Binder.clearCallingIdentity();
8149 try {
8150 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8151 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008152 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008155 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8156 } finally {
8157 Binder.restoreCallingIdentity(identity);
8158 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008159 }
8160
8161 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008162 * Sets the per-account voicemail ringtone.
8163 *
8164 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8165 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8166 *
8167 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8168 * voicemail ringtone.
8169 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8170 * PhoneAccount.
8171 */
8172 @Override
8173 public void setVoicemailRingtoneUri(String callingPackage,
8174 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008175 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008176 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008177 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8178 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8180 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8181 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008182 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008183
8184 final long identity = Binder.clearCallingIdentity();
8185 try {
8186 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8187 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008188 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189 }
8190 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8191 } finally {
8192 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008193 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008194 }
8195
8196 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008197 * Returns whether vibration is set for voicemail notification in Phone settings.
8198 *
8199 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8200 * voicemail vibration setting.
8201 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8202 */
8203 @Override
8204 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008205 final long identity = Binder.clearCallingIdentity();
8206 try {
8207 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8208 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008209 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008210 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008211
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008212 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8213 } finally {
8214 Binder.restoreCallingIdentity(identity);
8215 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008216 }
8217
Youhan Wange64578a2016-05-02 15:32:42 -07008218 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008219 * Sets the per-account voicemail vibration.
8220 *
8221 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8222 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8223 *
8224 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8225 * voicemail vibration setting.
8226 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8227 * specific PhoneAccount.
8228 */
8229 @Override
8230 public void setVoicemailVibrationEnabled(String callingPackage,
8231 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008232 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008233 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008234 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8235 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8237 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8238 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008239 }
8240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 final long identity = Binder.clearCallingIdentity();
8242 try {
8243 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8244 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008245 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008246 }
8247 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8248 } finally {
8249 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008250 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008251 }
8252
8253 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008254 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8255 *
8256 * @throws SecurityException if the caller does not have the required permission
8257 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008258 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008259 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008260 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008261 }
8262
8263 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008264 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8265 * permission.
8266 *
8267 * @throws SecurityException if the caller does not have the required permission
8268 */
8269 private void enforceSendSmsPermission() {
8270 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8271 }
8272
8273 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008274 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008275 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008276 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008277 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008278 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279 final long identity = Binder.clearCallingIdentity();
8280 try {
8281 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008282 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283 if (componentName == null) {
8284 throw new SecurityException(
8285 "Caller not current active visual voicemail package[null]");
8286 }
8287 String vvmPackage = componentName.getPackageName();
8288 if (!callingPackage.equals(vvmPackage)) {
8289 throw new SecurityException("Caller not current active visual voicemail package["
8290 + vvmPackage + "]");
8291 }
8292 } finally {
8293 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008294 }
8295 }
8296
8297 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008298 * Return the application ID for the app type.
8299 *
8300 * @param subId the subscription ID that this request applies to.
8301 * @param appType the uicc app type.
8302 * @return Application ID for specificied app type, or null if no uicc.
8303 */
8304 @Override
8305 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008306 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008307 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008308
8309 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008310 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008311 if (phone == null) {
8312 return null;
8313 }
8314 String aid = null;
8315 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008316 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008317 .getApplicationByType(appType).getAid();
8318 } catch (Exception e) {
8319 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8320 }
8321 return aid;
8322 } finally {
8323 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008324 }
Youhan Wange64578a2016-05-02 15:32:42 -07008325 }
8326
Youhan Wang4001d252016-05-11 10:29:41 -07008327 /**
8328 * Return the Electronic Serial Number.
8329 *
8330 * @param subId the subscription ID that this request applies to.
8331 * @return ESN or null if error.
8332 */
8333 @Override
8334 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008335 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008336 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008337
8338 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008339 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008340 if (phone == null) {
8341 return null;
8342 }
8343 String esn = null;
8344 try {
8345 esn = phone.getEsn();
8346 } catch (Exception e) {
8347 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8348 }
8349 return esn;
8350 } finally {
8351 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008352 }
Youhan Wang4001d252016-05-11 10:29:41 -07008353 }
8354
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008355 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008356 * Return the Preferred Roaming List Version.
8357 *
8358 * @param subId the subscription ID that this request applies to.
8359 * @return PRLVersion or null if error.
8360 */
8361 @Override
8362 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008363 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008364 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008365
8366 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008367 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368 if (phone == null) {
8369 return null;
8370 }
8371 String cdmaPrlVersion = null;
8372 try {
8373 cdmaPrlVersion = phone.getCdmaPrlVersion();
8374 } catch (Exception e) {
8375 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8376 }
8377 return cdmaPrlVersion;
8378 } finally {
8379 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008380 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008381 }
8382
8383 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008384 * Get snapshot of Telephony histograms
8385 * @return List of Telephony histograms
8386 * @hide
8387 */
8388 @Override
8389 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8391 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008392
8393 final long identity = Binder.clearCallingIdentity();
8394 try {
8395 return RIL.getTelephonyRILTimingHistograms();
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
8398 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008399 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008400
8401 /**
8402 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008403 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8404 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008405 * Require system privileges. In the future we may add this to carrier APIs.
8406 *
Michele Berionne482f8202018-11-27 18:57:59 -08008407 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008408 */
8409 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008410 @TelephonyManager.SetCarrierRestrictionResult
8411 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008412 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008413 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008414
Michele Berionne482f8202018-11-27 18:57:59 -08008415 if (carrierRestrictionRules == null) {
8416 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008417 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008419 final long identity = Binder.clearCallingIdentity();
8420 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008421 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008422 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008423 } finally {
8424 Binder.restoreCallingIdentity(identity);
8425 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008426 }
8427
8428 /**
8429 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008430 * Get the allowed carrier list and the excluded carrier list, including the priority between
8431 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008432 * Require system privileges. In the future we may add this to carrier APIs.
8433 *
Michele Berionne482f8202018-11-27 18:57:59 -08008434 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008435 */
8436 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008437 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008438 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008439 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008440
8441 final long identity = Binder.clearCallingIdentity();
8442 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008443 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8444 if (response instanceof CarrierRestrictionRules) {
8445 return (CarrierRestrictionRules) response;
8446 }
8447 // Response is an Exception of some kind,
8448 // which is signalled to the user as a NULL retval
8449 return null;
8450 } catch (Exception e) {
8451 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8452 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008453 } finally {
8454 Binder.restoreCallingIdentity(identity);
8455 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008456 }
8457
fionaxu59545b42016-05-25 15:53:37 -07008458 /**
fionaxu59545b42016-05-25 15:53:37 -07008459 * Action set from carrier signalling broadcast receivers to enable/disable radio
8460 * @param subId the subscription ID that this action applies to.
8461 * @param enabled control enable or disable radio.
8462 * {@hide}
8463 */
8464 @Override
8465 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8466 enforceModifyPermission();
8467 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008468
8469 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008470 if (phone == null) {
8471 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8472 return;
8473 }
8474 try {
8475 phone.carrierActionSetRadioEnabled(enabled);
8476 } catch (Exception e) {
8477 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008478 } finally {
8479 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008480 }
8481 }
8482
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008483 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008484 * Enable or disable Voice over NR (VoNR)
8485 * @param subId the subscription ID that this action applies to.
8486 * @param enabled enable or disable VoNR.
8487 * @return operation result.
8488 */
8489 @Override
8490 public int setVoNrEnabled(int subId, boolean enabled) {
8491 enforceModifyPermission();
8492 final Phone phone = getPhone(subId);
8493
8494 final long identity = Binder.clearCallingIdentity();
8495 if (phone == null) {
8496 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8497 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8498 }
8499
8500 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8501 try {
8502 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8503 workSource);
8504 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008505
8506 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8507 if (DBG) {
8508 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8509 }
8510 SubscriptionManager.setSubscriptionProperty(
8511 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8512 (enabled ? "1" : "0"));
8513 }
8514
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008515 return result;
8516 } finally {
8517 Binder.restoreCallingIdentity(identity);
8518 }
8519 }
8520
8521 /**
8522 * Is voice over NR enabled
8523 * @return true if VoNR is enabled else false
8524 */
8525 @Override
8526 public boolean isVoNrEnabled(int subId) {
8527 enforceReadPrivilegedPermission("isVoNrEnabled");
8528 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8529 final long identity = Binder.clearCallingIdentity();
8530 try {
8531 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8532 null, subId, workSource);
8533 if (DBG) log("isVoNrEnabled: " + isEnabled);
8534 return isEnabled;
8535 } finally {
8536 Binder.restoreCallingIdentity(identity);
8537 }
8538 }
8539
8540 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008541 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8542 * network status based on which carrier apps could apply actions accordingly,
8543 * enable/disable default url handler for example.
8544 *
8545 * @param subId the subscription ID that this action applies to.
8546 * @param report control start/stop reporting the default network status.
8547 * {@hide}
8548 */
8549 @Override
8550 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8551 enforceModifyPermission();
8552 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008553
8554 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008555 if (phone == null) {
8556 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8557 return;
8558 }
8559 try {
8560 phone.carrierActionReportDefaultNetworkStatus(report);
8561 } catch (Exception e) {
8562 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008563 } finally {
8564 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008565 }
8566 }
8567
8568 /**
fionaxud9622282017-07-17 17:51:30 -07008569 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8570 * @param subId the subscription ID that this action applies to.
8571 * {@hide}
8572 */
8573 @Override
8574 public void carrierActionResetAll(int subId) {
8575 enforceModifyPermission();
8576 final Phone phone = getPhone(subId);
8577 if (phone == null) {
8578 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8579 return;
8580 }
8581 try {
8582 phone.carrierActionResetAll();
8583 } catch (Exception e) {
8584 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8585 }
8586 }
8587
8588 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008589 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8590 * bug report is being generated.
8591 */
8592 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008593 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008594 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8595 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008596 writer.println("Permission Denial: can't dump Phone from pid="
8597 + Binder.getCallingPid()
8598 + ", uid=" + Binder.getCallingUid()
8599 + "without permission "
8600 + android.Manifest.permission.DUMP);
8601 return;
8602 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008603 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008604 }
Jack Yueb89b242016-06-22 13:27:47 -07008605
Brad Ebingerdac2f002018-04-03 15:17:52 -07008606 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008607 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8608 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8609 @NonNull String[] args) {
8610 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8611 this, in.getFileDescriptor(), out.getFileDescriptor(),
8612 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008613 }
8614
Jack Yueb89b242016-06-22 13:27:47 -07008615 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008616 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008617 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008618 * @param reason the reason the data enable change is taking place
8619 * @param enabled True if enabling the data, otherwise disabling.
8620 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008621 */
8622 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008623 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008624 boolean enabled) {
8625 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8626 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8627 try {
8628 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008629 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008630 } catch (SecurityException se) {
8631 enforceModifyPermission();
8632 }
8633 } else {
8634 enforceModifyPermission();
8635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008636
8637 final long identity = Binder.clearCallingIdentity();
8638 try {
8639 Phone phone = getPhone(subId);
8640 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008641 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8642 phone.carrierActionSetMeteredApnsEnabled(enabled);
8643 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008644 if (phone.isUsingNewDataStack()) {
8645 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8646 } else {
8647 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8648 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008649 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008650 }
8651 } finally {
8652 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008653 }
8654 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008655
8656 /**
8657 * Get Client request stats
8658 * @return List of Client Request Stats
8659 * @hide
8660 */
8661 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008662 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8663 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008664 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008665 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008666 return null;
8667 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008668 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008669
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008670 final long identity = Binder.clearCallingIdentity();
8671 try {
8672 if (phone != null) {
8673 return phone.getClientRequestStats();
8674 }
8675
8676 return null;
8677 } finally {
8678 Binder.restoreCallingIdentity(identity);
8679 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008680 }
8681
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008682 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008683 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008684 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008685 }
Jack Yueb4124c2017-02-16 15:32:43 -08008686
8687 /**
Grace Chen70990072017-03-24 17:21:30 -07008688 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008689 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008690 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008691 * @param state State of SIM (power down, power up, pass through)
8692 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8693 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8694 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008695 *
8696 **/
8697 @Override
Grace Chen70990072017-03-24 17:21:30 -07008698 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008699 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008700 Phone phone = PhoneFactory.getPhone(slotIndex);
8701
vagdeviaf9a5b92018-08-15 16:01:53 -07008702 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8703
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008704 final long identity = Binder.clearCallingIdentity();
8705 try {
8706 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008707 phone.setSimPowerState(state, null, workSource);
8708 }
8709 } finally {
8710 Binder.restoreCallingIdentity(identity);
8711 }
8712 }
8713
8714 /**
8715 * Set SIM card power state.
8716 *
8717 * @param slotIndex SIM slot id.
8718 * @param state State of SIM (power down, power up, pass through)
8719 * @param callback callback to trigger after success or failure
8720 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8721 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8722 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8723 *
8724 **/
8725 @Override
8726 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8727 IIntegerConsumer callback) {
8728 enforceModifyPermission();
8729 Phone phone = PhoneFactory.getPhone(slotIndex);
8730
8731 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8732
8733 final long identity = Binder.clearCallingIdentity();
8734 try {
8735 if (phone != null) {
8736 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8737 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008738 }
8739 } finally {
8740 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008741 }
8742 }
Shuo Qiandd210312017-04-12 22:11:33 +00008743
Tyler Gunn65d45c22017-06-05 11:22:26 -07008744 private boolean isUssdApiAllowed(int subId) {
8745 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008746 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008747 if (configManager == null) {
8748 return false;
8749 }
8750 PersistableBundle pb = configManager.getConfigForSubId(subId);
8751 if (pb == null) {
8752 return false;
8753 }
8754 return pb.getBoolean(
8755 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8756 }
8757
Shuo Qiandd210312017-04-12 22:11:33 +00008758 /**
8759 * Check if phone is in emergency callback mode
8760 * @return true if phone is in emergency callback mode
8761 * @param subId sub id
8762 */
goneil9c5f4872017-12-05 14:07:56 -08008763 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008764 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008765 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008766 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008767
8768 final long identity = Binder.clearCallingIdentity();
8769 try {
8770 if (phone != null) {
8771 return phone.isInEcm();
8772 } else {
8773 return false;
8774 }
8775 } finally {
8776 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008777 }
8778 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008779
8780 /**
8781 * Get the current signal strength information for the given subscription.
8782 * Because this information is not updated when the device is in a low power state
8783 * it should not be relied-upon to be current.
8784 * @param subId Subscription index
8785 * @return the most recent cached signal strength info from the modem
8786 */
8787 @Override
8788 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008789 final long identity = Binder.clearCallingIdentity();
8790 try {
8791 Phone p = getPhone(subId);
8792 if (p == null) {
8793 return null;
8794 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008796 return p.getSignalStrength();
8797 } finally {
8798 Binder.restoreCallingIdentity(identity);
8799 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008800 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008801
Pengquan Meng77b7f132018-08-22 14:49:57 -07008802 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008803 * Get the current modem radio state for the given slot.
8804 * @param slotIndex slot index.
8805 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008806 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008807 * @return the current radio power state from the modem
8808 */
8809 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008810 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008811 Phone phone = PhoneFactory.getPhone(slotIndex);
8812 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008813 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8814 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008815 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8816 }
8817
8818 final long identity = Binder.clearCallingIdentity();
8819 try {
8820 return phone.getRadioPowerState();
8821 } finally {
8822 Binder.restoreCallingIdentity(identity);
8823 }
8824 }
8825 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8826 }
8827
8828 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008829 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8830 *
8831 * <p>Requires one of the following permissions:
8832 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008833 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008834 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8835 * privileges.
8836 *
8837 * @param subId subscription id
8838 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8839 * {@code false}.
8840 */
8841 @Override
8842 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008843 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008844 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008845 try {
8846 mApp.enforceCallingOrSelfPermission(
8847 android.Manifest.permission.ACCESS_NETWORK_STATE,
8848 functionName);
8849 } catch (Exception e) {
8850 mApp.enforceCallingOrSelfPermission(
8851 permission.READ_BASIC_PHONE_STATE, functionName);
8852 }
Shuo Qian093013d2020-08-13 15:42:55 -07008853 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008854 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008855 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008856 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008857
Pengquan Menga1bb6272018-09-06 09:59:22 -07008858 boolean isEnabled = false;
8859 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008860 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008861 Phone phone = getPhone(subId);
8862 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008863 } finally {
8864 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008865 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008866 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008867 }
8868
8869
8870 /**
8871 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8872 *
8873 * <p> Requires permission:
8874 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8875 * privileges.
8876 *
8877 * @param subId subscription id
8878 * @param isEnabled {@code true} means enable, {@code false} means disable.
8879 */
8880 @Override
8881 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008882 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8883 mApp, subId, "setDataRoamingEnabled");
8884
Pengquan Menga1bb6272018-09-06 09:59:22 -07008885 final long identity = Binder.clearCallingIdentity();
8886 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008887 Phone phone = getPhone(subId);
8888 if (phone != null) {
8889 phone.setDataRoamingEnabled(isEnabled);
8890 }
8891 } finally {
8892 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008893 }
8894 }
8895
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008896 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008897 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008898 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008899 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008900 mApp, subId, "isManualNetworkSelectionAllowed");
8901
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008902 boolean isAllowed = true;
8903 final long identity = Binder.clearCallingIdentity();
8904 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008905 Phone phone = getPhone(subId);
8906 if (phone != null) {
8907 isAllowed = phone.isCspPlmnEnabled();
8908 }
8909 } finally {
8910 Binder.restoreCallingIdentity(identity);
8911 }
8912 return isAllowed;
8913 }
8914
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008915 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8916 UiccProfile profile = port.getUiccProfile();
8917 if (profile == null ||
8918 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8919 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8920 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008921 }
8922 return true;
8923 }
8924
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008925 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008926 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008927 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008928 mApp.getSystemService(AppOpsManager.class)
8929 .checkPackage(Binder.getCallingUid(), callingPackage);
8930
Jordan Liu1e142fc2019-04-22 15:10:43 -07008931 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008932 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008933 try {
8934 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008935 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008936 } catch (SecurityException e) {
8937 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8938 // has carrier privileges on an active UICC
8939 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8940 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008941 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008942 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008943 }
sandeepjsb6c87872021-09-27 15:34:44 +00008944 // checking compatibility, if calling app's target SDK is T and beyond.
8945 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8946 Binder.getCallingUid())) {
8947 isIccIdAccessRestricted = true;
8948 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008949 final long identity = Binder.clearCallingIdentity();
8950 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008951 UiccController uiccController = UiccController.getInstance();
8952 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008953 if (hasReadPermission) {
8954 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008955 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008956
8957 // Remove private info if the caller doesn't have access
8958 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8959 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008960 //setting the value after compatibility check
8961 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008962 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8963 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008964 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008965 if (card == null) {
8966 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008967 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008968 continue;
8969 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008970 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8971 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008972 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008973 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008974 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008975 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8976 for (UiccPortInfo portInfo : portInfos) {
8977 UiccPort port = uiccController.getUiccPortForSlot(
8978 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8979 if (port == null) {
8980 // assume no access if port is null
8981 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8982 continue;
8983 }
8984 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8985 uiccPortInfos.add(portInfo);
8986 } else {
8987 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8988 }
8989 }
8990 filteredInfos.add(new UiccCardInfo(
8991 cardInfo.isEuicc(),
8992 cardInfo.getCardId(),
8993 null,
8994 cardInfo.getPhysicalSlotIndex(),
8995 cardInfo.isRemovable(),
8996 cardInfo.isMultipleEnabledProfilesSupported(),
8997 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008998 }
8999 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009000 } finally {
9001 Binder.restoreCallingIdentity(identity);
9002 }
9003 }
9004
sandeepjsb6c87872021-09-27 15:34:44 +00009005 /**
9006 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9007 * generally private and require carrier privileges to view.
9008 *
9009 * @hide
9010 */
9011 @NonNull
9012 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9013 List<UiccPortInfo> portinfo = new ArrayList<>();
9014 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9015 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9016 }
9017 return new UiccCardInfo(
9018 cardInfo.isEuicc(),
9019 cardInfo.getCardId(),
9020 null,
9021 cardInfo.getPhysicalSlotIndex(),
9022 cardInfo.isRemovable(),
9023 cardInfo.isMultipleEnabledProfilesSupported(),
9024 portinfo
9025 );
9026 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009027
sandeepjsb6c87872021-09-27 15:34:44 +00009028 /**
9029 * @hide
9030 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9031 * These values are generally private and require carrier privileges to view.
9032 */
9033 @NonNull
9034 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9035 return new UiccPortInfo(
9036 UiccPortInfo.ICCID_REDACTED,
9037 portInfo.getPortIndex(),
9038 portInfo.getLogicalSlotIndex(),
9039 portInfo.isActive()
9040 );
9041 }
9042 @Override
9043 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009044 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009045 mApp.getSystemService(AppOpsManager.class)
9046 .checkPackage(Binder.getCallingUid(), callingPackage);
9047
9048 boolean hasReadPermission = false;
9049 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009050
9051 try {
9052 enforceReadPrivilegedPermission("getUiccSlotsInfo");
9053 hasReadPermission = true;
9054 } catch (SecurityException e) {
9055 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9056 // has carrier privileges on an active UICC
9057 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
9058 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
9059 hasReadPermission = true;
9060 }
9061 }
9062
9063 // checking compatibility, if calling app's target SDK is T and beyond.
9064 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9065 Binder.getCallingUid())) {
9066 isLogicalSlotAccessRestricted = true;
9067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009068 final long identity = Binder.clearCallingIdentity();
9069 try {
9070 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
9071 if (slots == null) {
9072 Rlog.i(LOG_TAG, "slots is null.");
9073 return null;
9074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009075 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9076 for (int i = 0; i < slots.length; i++) {
9077 UiccSlot slot = slots[i];
9078 if (slot == null) {
9079 continue;
9080 }
9081
Jordan Liu7be7e652019-05-06 18:55:02 +00009082 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009083 UiccCard card = slot.getUiccCard();
9084 if (card != null) {
9085 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009086 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009087 cardId = slot.getEid();
9088 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009089 // If cardId is null, use iccId of default port as cardId. Check if has
9090 // read permission otherwise set to null.(card is null which means no
9091 // carrier permission)
9092 cardId = hasReadPermission ? slot.getIccId(
9093 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07009094 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009095 }
9096
Jordan Liu857451f2019-05-09 16:35:35 -07009097 if (cardId != null) {
9098 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9099 // if cardId is an EID, it's all digits so this is fine
9100 cardId = IccUtils.stripTrailingFs(cardId);
9101 }
9102
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009103 int cardState = 0;
9104 switch (slot.getCardState()) {
9105 case CARDSTATE_ABSENT:
9106 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9107 break;
9108 case CARDSTATE_PRESENT:
9109 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9110 break;
9111 case CARDSTATE_ERROR:
9112 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9113 break;
9114 case CARDSTATE_RESTRICTED:
9115 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9116 break;
9117 default:
9118 break;
9119
9120 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009121 List<UiccPortInfo> portInfos = new ArrayList<>();
9122 int[] portIndexes = slot.getPortList();
9123 for (int portIdx : portIndexes) {
9124 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
9125 callingPackage, hasReadPermission));
9126 if (slot.isPortActive(portIdx)) {
9127 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
9128 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
9129 port.getPhoneId(), true));
9130 } else {
9131 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
9132 }
9133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009134 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009135 slot.isEuicc(),
9136 cardId,
9137 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009138 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009139 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009140 //setting the value after compatibility check
9141 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009142 }
9143 return infos;
9144 } finally {
9145 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009146 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009147 }
9148
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009149 /* Returns null if doesn't have read permission or carrier privilege access. */
9150 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9151 boolean hasReadPermission) {
9152 String iccId = slot.getIccId(portIndex);
9153 if (hasReadPermission) { // if has read permission
9154 return iccId;
9155 } else {
9156 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9157 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9158 // if no read permission, checking carrier privilege access
9159 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9160 return iccId;
9161 }
9162 }
9163 }
9164 // No read permission or carrier privilege access.
9165 return UiccPortInfo.ICCID_REDACTED;
9166 }
9167
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009168 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009169 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009170 public boolean switchSlots(int[] physicalSlots) {
9171 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009172
9173 final long identity = Binder.clearCallingIdentity();
9174 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009175 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9176 for (int i = 0; i < physicalSlots.length; i++) {
9177 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9178 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9179 physicalSlots[i], i));
9180 }
9181 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009182 } finally {
9183 Binder.restoreCallingIdentity(identity);
9184 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009185 }
Jack Yu4c988042018-02-27 15:30:01 -08009186
9187 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009188 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9189 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9190 enforceModifyPermission();
9191
9192 final long identity = Binder.clearCallingIdentity();
9193 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009194 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009195 } finally {
9196 Binder.restoreCallingIdentity(identity);
9197 }
9198 }
9199
9200 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009201 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009202 final long identity = Binder.clearCallingIdentity();
9203 try {
9204 return UiccController.getInstance().getCardIdForDefaultEuicc();
9205 } finally {
9206 Binder.restoreCallingIdentity(identity);
9207 }
9208 }
9209
Pengquan Meng85728fb2018-03-12 16:31:21 -07009210 /**
goneil47ffb6e2018-04-06 15:40:58 -07009211 * A test API to reload the UICC profile.
9212 *
9213 * <p>Requires that the calling app has permission
9214 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9215 * @hide
9216 */
9217 @Override
9218 public void refreshUiccProfile(int subId) {
9219 enforceModifyPermission();
9220
9221 final long identity = Binder.clearCallingIdentity();
9222 try {
9223 Phone phone = getPhone(subId);
9224 if (phone == null) {
9225 return;
9226 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009227 UiccPort uiccPort = phone.getUiccPort();
9228 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009229 return;
9230 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009231 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009232 if (uiccProfile == null) {
9233 return;
9234 }
9235 uiccProfile.refresh();
9236 } finally {
9237 Binder.restoreCallingIdentity(identity);
9238 }
9239 }
9240
9241 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009242 * Returns false if the mobile data is disabled by default, otherwise return true.
9243 */
9244 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009245 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009246 }
9247
9248 /**
9249 * Returns true if the data roaming is enabled by default, i.e the system property
9250 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9251 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9252 */
9253 private boolean getDefaultDataRoamingEnabled(int subId) {
9254 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009255 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009256 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009257 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9258 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9259 return isDataRoamingEnabled;
9260 }
9261
9262 /**
9263 * Returns the default network type for the given {@code subId}, if the default network type is
9264 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9265 */
9266 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009267 List<Integer> list = TelephonyProperties.default_network();
9268 int phoneId = mSubscriptionController.getPhoneId(subId);
9269 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9270 return list.get(phoneId);
9271 }
9272 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009273 }
fionaxua13278b2018-03-21 00:08:13 -07009274
9275 @Override
9276 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009277 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009278 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009279
9280 final long identity = Binder.clearCallingIdentity();
9281 try {
9282 final Phone phone = getPhone(subId);
9283 if (phone == null) {
9284 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9285 return;
9286 }
chen xueaba88a2019-03-15 13:15:10 -07009287 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9288 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009289 if (carrierPrivilegeRules == null) {
9290 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9291 } else {
9292 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009294 } finally {
9295 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009296 }
fionaxua13278b2018-03-21 00:08:13 -07009297 }
9298
9299 @Override
9300 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009301 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009302
9303 final long identity = Binder.clearCallingIdentity();
9304 try {
9305 final Phone phone = getPhone(subId);
9306 if (phone == null) {
9307 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9308 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9309 }
9310 return phone.getCarrierIdListVersion();
9311 } finally {
9312 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009313 }
fionaxua13278b2018-03-21 00:08:13 -07009314 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009315
9316 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009317 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9318 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009319 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009320 mApp, subId, callingPackage, callingFeatureId,
9321 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009322 return -1;
9323 }
9324
9325 final long identity = Binder.clearCallingIdentity();
9326 try {
9327 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9328 } finally {
9329 Binder.restoreCallingIdentity(identity);
9330 }
9331 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009332
9333 @Override
9334 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009335 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009336 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009337 mApp, subId, "getCdmaRoamingMode");
9338
9339 final long identity = Binder.clearCallingIdentity();
9340 try {
9341 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9342 } finally {
9343 Binder.restoreCallingIdentity(identity);
9344 }
9345 }
9346
9347 @Override
9348 public boolean setCdmaRoamingMode(int subId, int mode) {
9349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9350 mApp, subId, "setCdmaRoamingMode");
9351
9352 final long identity = Binder.clearCallingIdentity();
9353 try {
9354 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9355 } finally {
9356 Binder.restoreCallingIdentity(identity);
9357 }
9358 }
9359
9360 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009361 public int getCdmaSubscriptionMode(int subId) {
9362 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009363 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009364 mApp, subId, "getCdmaSubscriptionMode");
9365
9366 final long identity = Binder.clearCallingIdentity();
9367 try {
9368 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9369 } finally {
9370 Binder.restoreCallingIdentity(identity);
9371 }
9372 }
9373
9374 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009375 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9377 mApp, subId, "setCdmaSubscriptionMode");
9378
9379 final long identity = Binder.clearCallingIdentity();
9380 try {
9381 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9382 } finally {
9383 Binder.restoreCallingIdentity(identity);
9384 }
9385 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009386
sqianc5eccab2018-10-19 18:46:41 -07009387 @Override
sqian8c685422019-02-22 15:55:18 -08009388 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009389 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009391 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9392 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009393 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9394 }
9395 final long identity = Binder.clearCallingIdentity();
9396 try {
sqian854d44b2018-12-12 16:48:18 -08009397 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9398 for (Phone phone: PhoneFactory.getPhones()) {
9399 if (phone.getEmergencyNumberTracker() != null
9400 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9401 emergencyNumberListInternal.put(
9402 phone.getSubId(),
9403 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9404 }
sqian11b7a0e2018-12-05 18:48:28 -08009405 }
sqian854d44b2018-12-12 16:48:18 -08009406 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009407 } finally {
9408 Binder.restoreCallingIdentity(identity);
9409 }
sqianc5eccab2018-10-19 18:46:41 -07009410 }
9411
9412 @Override
sqian8c685422019-02-22 15:55:18 -08009413 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009414 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009415 if (!exactMatch) {
9416 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009417 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009418 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009419 }
9420 final long identity = Binder.clearCallingIdentity();
9421 try {
sqian854d44b2018-12-12 16:48:18 -08009422 for (Phone phone: PhoneFactory.getPhones()) {
9423 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009424 && phone.getEmergencyNumberTracker()
9425 .isEmergencyNumber(number, exactMatch)) {
9426 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009427 }
sqian11b7a0e2018-12-05 18:48:28 -08009428 }
9429 return false;
9430 } finally {
9431 Binder.restoreCallingIdentity(identity);
9432 }
9433 }
9434
sqianf4ca7ed2019-01-15 18:32:07 -08009435 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009436 * Start emergency callback mode for GsmCdmaPhone for testing.
9437 */
9438 @Override
9439 public void startEmergencyCallbackMode() {
9440 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9441 "startEmergencyCallbackMode");
9442 enforceModifyPermission();
9443 final long identity = Binder.clearCallingIdentity();
9444 try {
9445 for (Phone phone : PhoneFactory.getPhones()) {
9446 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9447 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9448 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9449 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9450 gsmCdmaPhone.obtainMessage(
9451 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9452 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9453 }
9454 }
9455 } finally {
9456 Binder.restoreCallingIdentity(identity);
9457 }
9458 }
9459
9460 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009461 * Update emergency number list for test mode.
9462 */
9463 @Override
9464 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9465 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9466 "updateEmergencyNumberListTestMode");
9467
9468 final long identity = Binder.clearCallingIdentity();
9469 try {
9470 for (Phone phone: PhoneFactory.getPhones()) {
9471 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9472 if (tracker != null) {
9473 tracker.executeEmergencyNumberTestModeCommand(action, num);
9474 }
9475 }
9476 } finally {
9477 Binder.restoreCallingIdentity(identity);
9478 }
9479 }
9480
9481 /**
9482 * Get the full emergency number list for test mode.
9483 */
9484 @Override
9485 public List<String> getEmergencyNumberListTestMode() {
9486 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9487 "getEmergencyNumberListTestMode");
9488
9489 final long identity = Binder.clearCallingIdentity();
9490 try {
9491 Set<String> emergencyNumbers = new HashSet<>();
9492 for (Phone phone: PhoneFactory.getPhones()) {
9493 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9494 if (tracker != null) {
9495 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9496 emergencyNumbers.add(num.getNumber());
9497 }
9498 }
9499 }
9500 return new ArrayList<>(emergencyNumbers);
9501 } finally {
9502 Binder.restoreCallingIdentity(identity);
9503 }
9504 }
9505
chen xud6b45bd2018-10-30 22:27:10 -07009506 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009507 public int getEmergencyNumberDbVersion(int subId) {
9508 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9509
9510 final long identity = Binder.clearCallingIdentity();
9511 try {
9512 final Phone phone = getPhone(subId);
9513 if (phone == null) {
9514 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9515 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9516 }
9517 return phone.getEmergencyNumberDbVersion();
9518 } finally {
9519 Binder.restoreCallingIdentity(identity);
9520 }
9521 }
9522
9523 @Override
9524 public void notifyOtaEmergencyNumberDbInstalled() {
9525 enforceModifyPermission();
9526
9527 final long identity = Binder.clearCallingIdentity();
9528 try {
9529 for (Phone phone: PhoneFactory.getPhones()) {
9530 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9531 if (tracker != null) {
9532 tracker.updateOtaEmergencyNumberDatabase();
9533 }
9534 }
9535 } finally {
9536 Binder.restoreCallingIdentity(identity);
9537 }
9538 }
9539
9540 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009541 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009542 enforceActiveEmergencySessionPermission();
9543
9544 final long identity = Binder.clearCallingIdentity();
9545 try {
9546 for (Phone phone: PhoneFactory.getPhones()) {
9547 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9548 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009549 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9550 }
9551 }
9552 } finally {
9553 Binder.restoreCallingIdentity(identity);
9554 }
9555 }
9556
9557 @Override
9558 public void resetOtaEmergencyNumberDbFilePath() {
9559 enforceActiveEmergencySessionPermission();
9560
9561 final long identity = Binder.clearCallingIdentity();
9562 try {
9563 for (Phone phone: PhoneFactory.getPhones()) {
9564 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9565 if (tracker != null) {
9566 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009567 }
9568 }
9569 } finally {
9570 Binder.restoreCallingIdentity(identity);
9571 }
9572 }
9573
9574 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009575 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9576 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9577 Phone phone = getPhone(subId);
9578 if (phone == null) {
9579 return null;
9580 }
9581 final long identity = Binder.clearCallingIdentity();
9582 try {
9583 UiccProfile profile = UiccController.getInstance()
9584 .getUiccProfileForPhone(phone.getPhoneId());
9585 if (profile != null) {
9586 return profile.getCertsFromCarrierPrivilegeAccessRules();
9587 }
9588 } finally {
9589 Binder.restoreCallingIdentity(identity);
9590 }
9591 return null;
9592 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009593
9594 /**
9595 * Enable or disable a modem stack.
9596 */
9597 @Override
9598 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9599 enforceModifyPermission();
9600
9601 final long identity = Binder.clearCallingIdentity();
9602 try {
9603 Phone phone = PhoneFactory.getPhone(slotIndex);
9604 if (phone == null) {
9605 return false;
9606 } else {
9607 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9608 }
9609 } finally {
9610 Binder.restoreCallingIdentity(identity);
9611 }
9612 }
Michelecea4cf22018-12-21 15:00:11 -08009613
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009614 /**
9615 * Whether a modem stack is enabled or not.
9616 */
9617 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009618 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9619 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009620 Phone phone = PhoneFactory.getPhone(slotIndex);
9621 if (phone == null) return false;
9622
9623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009624 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9625 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009626 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9627 }
9628
9629 final long identity = Binder.clearCallingIdentity();
9630 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009631 try {
9632 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9633 } catch (NoSuchElementException ex) {
9634 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9635 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009636 } finally {
9637 Binder.restoreCallingIdentity(identity);
9638 }
9639 }
9640
Michelecea4cf22018-12-21 15:00:11 -08009641 @Override
Michele0ea7d782019-03-19 14:58:42 -07009642 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009643 enforceModifyPermission();
9644
9645 final long identity = Binder.clearCallingIdentity();
9646 try {
9647 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009648 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009649 .commit();
9650 } finally {
9651 Binder.restoreCallingIdentity(identity);
9652 }
9653 }
9654
9655 @Override
Michele0ea7d782019-03-19 14:58:42 -07009656 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009657 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009658 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009659 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9660 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009661 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009662 }
Michelecea4cf22018-12-21 15:00:11 -08009663
9664 final long identity = Binder.clearCallingIdentity();
9665 try {
Michele0ea7d782019-03-19 14:58:42 -07009666 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009667 } finally {
9668 Binder.restoreCallingIdentity(identity);
9669 }
9670 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009671
Michele0ea7d782019-03-19 14:58:42 -07009672 @TelephonyManager.IsMultiSimSupportedResult
9673 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009674 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9675 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9676 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009677 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9678 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009679 }
9680 // Check if the hardware supports multisim functionality. If usage of multisim is not
9681 // supported by the modem, indicate that it is restricted.
9682 PhoneCapability staticCapability =
9683 mPhoneConfigurationManager.getStaticPhoneCapability();
9684 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009685 loge("isMultiSimSupportedInternal: no static configuration available");
9686 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009687 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009688 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009689 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9690 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009691 }
9692 // Check if support of multiple SIMs is restricted by carrier
9693 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009694 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009695 }
9696
Michele0ea7d782019-03-19 14:58:42 -07009697 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009698 }
9699
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009700 /**
9701 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009702 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9703 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9704 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009705 * @param numOfSims number of active sims we want to switch to
9706 */
9707 @Override
9708 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009709 if (numOfSims == 1) {
9710 enforceModifyPermission();
9711 } else {
9712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9713 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9714 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009715 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009716
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009717 try {
Michele30b57b22019-03-01 12:01:14 -08009718 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009719 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009720 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9721 return;
9722 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009723 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9724 } finally {
9725 Binder.restoreCallingIdentity(identity);
9726 }
9727 }
9728
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009729 @Override
9730 public boolean isApplicationOnUicc(int subId, int appType) {
9731 enforceReadPrivilegedPermission("isApplicationOnUicc");
9732 Phone phone = getPhone(subId);
9733 if (phone == null) {
9734 return false;
9735 }
9736 final long identity = Binder.clearCallingIdentity();
9737 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009738 UiccPort uiccPort = phone.getUiccPort();
9739 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009740 return false;
9741 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009742 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009743 if (uiccProfile == null) {
9744 return false;
9745 }
9746 if (TelephonyManager.APPTYPE_SIM <= appType
9747 && appType <= TelephonyManager.APPTYPE_ISIM) {
9748 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9749 }
9750 return false;
9751 } finally {
9752 Binder.restoreCallingIdentity(identity);
9753 }
9754 }
9755
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009756 /**
chen xub4baa772019-04-03 10:23:41 -07009757 * Get whether making changes to modem configurations will trigger reboot.
9758 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009759 */
9760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009761 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9762 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009764 mApp, subId, callingPackage, callingFeatureId,
9765 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009766 return false;
9767 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009768 final long identity = Binder.clearCallingIdentity();
9769 try {
9770 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9771 } finally {
9772 Binder.restoreCallingIdentity(identity);
9773 }
9774 }
9775
Nathan Harold29f5f052019-02-15 13:41:57 -08009776 private void updateModemStateMetrics() {
9777 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9778 // TODO: check the state for each modem if the api is ready.
9779 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9780 }
9781
Pengquan Meng3889a572019-01-23 11:16:29 -08009782 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009783 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009784 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009785 // Verify that the callingPackage belongs to the calling UID
9786 mApp.getSystemService(AppOpsManager.class)
9787 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009788 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009789 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009790 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009791 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9792 if (slotInfos != null) {
9793 for (int i = 0; i < slotInfos.length; i++) {
9794 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9795 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9796 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9797 portInfo.getLogicalSlotIndex()));
9798 }
9799 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009800 }
9801 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009802 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009803 } finally {
9804 Binder.restoreCallingIdentity(identity);
9805 }
9806 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009807
9808 /**
9809 * Get the IRadio HAL Version
9810 */
9811 @Override
9812 public int getRadioHalVersion() {
9813 Phone phone = getDefaultPhone();
9814 if (phone == null) return -1;
9815 HalVersion hv = phone.getHalVersion();
9816 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9817 return hv.major * 100 + hv.minor;
9818 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009819
9820 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009821 * Get the current calling package name.
9822 * @return the current calling package name
9823 */
9824 @Override
9825 public String getCurrentPackageName() {
9826 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9827 }
9828
9829 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009830 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9831 * corresponding network requests on a subId.
9832 *
9833 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009834 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009835 * 2) APN is un-metered for this subscription, or
9836 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009837 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009838 *
9839 * @return whether data is allowed for a apn type.
9840 *
9841 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009842 */
9843 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009844 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009845 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9846 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009847
9848 // Now that all security checks passes, perform the operation as ourselves.
9849 final long identity = Binder.clearCallingIdentity();
9850 try {
9851 Phone phone = getPhone(subId);
9852 if (phone == null) return false;
9853
Jack Yu41407ee2019-05-13 16:54:09 -07009854 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009855 boolean isDataEnabled;
9856 if (phone.isUsingNewDataStack()) {
9857 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9858 } else {
9859 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9860 }
9861 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009862 } finally {
9863 Binder.restoreCallingIdentity(identity);
9864 }
9865 }
9866
9867 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009868 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009869 enforceReadPrivilegedPermission("isApnMetered");
9870
9871 // Now that all security checks passes, perform the operation as ourselves.
9872 final long identity = Binder.clearCallingIdentity();
9873 try {
9874 Phone phone = getPhone(subId);
9875 if (phone == null) return true; // By default return true.
9876
Jack Yu41407ee2019-05-13 16:54:09 -07009877 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009878 } finally {
9879 Binder.restoreCallingIdentity(identity);
9880 }
9881 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009882
9883 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009884 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9885 int subscriptionId, IBooleanConsumer resultCallback) {
9886 enforceModifyPermission();
9887 long token = Binder.clearCallingIdentity();
9888 try {
9889 Phone phone = getPhone(subscriptionId);
9890 if (phone == null) {
9891 try {
9892 if (resultCallback != null) {
9893 resultCallback.accept(false);
9894 }
9895 } catch (RemoteException e) {
9896 // ignore
9897 }
9898 return;
9899 }
9900 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9901 Pair.create(specifiers, (x) -> {
9902 try {
9903 if (resultCallback != null) {
9904 resultCallback.accept(x);
9905 }
9906 } catch (RemoteException e) {
9907 // ignore
9908 }
9909 });
9910 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9911 } finally {
9912 Binder.restoreCallingIdentity(token);
9913 }
9914 }
9915
9916 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009917 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9918 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009919 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009920 mApp, subId, "getSystemSelectionChannels");
9921 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9922 final long identity = Binder.clearCallingIdentity();
9923 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009924 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9925 if (result instanceof IllegalStateException) {
9926 throw (IllegalStateException) result;
9927 }
9928 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009929 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9930 return specifiers;
9931 } finally {
9932 Binder.restoreCallingIdentity(identity);
9933 }
9934 }
9935
9936 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009937 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009938 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009939 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9940 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9941 if (iccRecords == null) {
9942 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9943 return false;
9944 }
9945 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9946 }
9947
9948 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009949 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9950 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009951 if (callingPackage == null) {
9952 callingPackage = getCurrentPackageName();
9953 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009954 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9955 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009956 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9957 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009958 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9959 }
9960 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9961 Intent intent = new Intent();
9962 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9963 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9964 // Bring up choose default SMS subscription dialog right now
9965 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9966 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9967 mApp.startActivity(intent);
9968 }
chen xud5ca2d52019-05-28 15:20:57 -07009969
9970 @Override
9971 public String getMmsUAProfUrl(int subId) {
9972 //TODO investigate if this API should require proper permission check in R b/133791609
9973 final long identity = Binder.clearCallingIdentity();
9974 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009975 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9976 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9977 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9978 return carrierUAProfUrl;
9979 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009980 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9981 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009982 } finally {
9983 Binder.restoreCallingIdentity(identity);
9984 }
9985 }
9986
9987 @Override
9988 public String getMmsUserAgent(int subId) {
9989 //TODO investigate if this API should require proper permission check in R b/133791609
9990 final long identity = Binder.clearCallingIdentity();
9991 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009992 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9993 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9994 if (!TextUtils.isEmpty(carrierUserAgent)) {
9995 return carrierUserAgent;
9996 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009997 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9998 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009999 } finally {
10000 Binder.restoreCallingIdentity(identity);
10001 }
10002 }
Jack Yub07d4972019-05-28 16:12:25 -070010003
10004 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010005 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10006 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010007
Jack Yub07d4972019-05-28 16:12:25 -070010008 final long identity = Binder.clearCallingIdentity();
10009 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010010 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010011 if (phone == null) return false;
10012
Hall Liua62f5da2020-09-25 10:42:19 -070010013 switch (policy) {
10014 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -080010015 if (phone.isUsingNewDataStack()) {
10016 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
10017 } else {
10018 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
10019 }
Hall Liua62f5da2020-09-25 10:42:19 -070010020 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -080010021 if (phone.isUsingNewDataStack()) {
10022 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
10023 } else {
10024 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
10025 }
Hall Liua62f5da2020-09-25 10:42:19 -070010026 default:
10027 throw new IllegalArgumentException(policy + " is not a valid policy");
10028 }
Jack Yub07d4972019-05-28 16:12:25 -070010029 } finally {
10030 Binder.restoreCallingIdentity(identity);
10031 }
10032 }
10033
10034 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010035 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010036 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010037 enforceModifyPermission();
10038
changbettyd5c246e2019-12-24 15:40:37 +080010039 final long identity = Binder.clearCallingIdentity();
10040 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010041 Phone phone = getPhone(subscriptionId);
10042 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010043
Hall Liua62f5da2020-09-25 10:42:19 -070010044 switch (policy) {
10045 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -080010046 if (phone.isUsingNewDataStack()) {
10047 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
10048 } else {
10049 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
10050 }
Hall Liua62f5da2020-09-25 10:42:19 -070010051 break;
10052 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -080010053 if (phone.isUsingNewDataStack()) {
10054 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
10055 } else {
10056 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
10057 }
Hall Liua62f5da2020-09-25 10:42:19 -070010058 break;
10059 default:
10060 throw new IllegalArgumentException(policy + " is not a valid policy");
10061 }
changbettyd5c246e2019-12-24 15:40:37 +080010062 } finally {
10063 Binder.restoreCallingIdentity(identity);
10064 }
10065 }
10066
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010067 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010068 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010069 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10070 * otherwise.
10071 */
10072 @Override
10073 public void setCepEnabled(boolean isCepEnabled) {
10074 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10075
10076 final long identity = Binder.clearCallingIdentity();
10077 try {
10078 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10079 for (Phone phone : PhoneFactory.getPhones()) {
10080 Phone defaultPhone = phone.getImsPhone();
10081 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10082 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10083 ImsPhoneCallTracker imsPhoneCallTracker =
10084 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10085 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10086 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10087 + imsPhone.getMsisdn());
10088 }
10089 }
10090 } finally {
10091 Binder.restoreCallingIdentity(identity);
10092 }
10093 }
allenwtsu46dcc572020-01-08 18:24:03 +080010094
10095 /**
10096 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10097 *
10098 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10099 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10100 * before being read.
10101 */
10102 @Override
10103 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10104 isCompressed) {
10105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10106 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010107 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10108 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10109 }
10110 if (!isImsAvailableOnDevice()) {
10111 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10112 "IMS not available on device.");
10113 }
10114
10115 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010116 try {
Hui Wang761a6682020-10-31 05:12:53 +000010117 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10118 } finally {
10119 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010120 }
10121 }
zoey chene02881a2019-12-30 16:11:23 +080010122
10123 @Override
10124 public boolean isIccLockEnabled(int subId) {
10125 enforceReadPrivilegedPermission("isIccLockEnabled");
10126
10127 // Now that all security checks passes, perform the operation as ourselves.
10128 final long identity = Binder.clearCallingIdentity();
10129 try {
10130 Phone phone = getPhone(subId);
10131 if (phone != null && phone.getIccCard() != null) {
10132 return phone.getIccCard().getIccLockEnabled();
10133 } else {
10134 return false;
10135 }
10136 } finally {
10137 Binder.restoreCallingIdentity(identity);
10138 }
10139 }
10140
10141 /**
10142 * Set the ICC pin lock enabled or disabled.
10143 *
10144 * @return an integer representing the status of IccLock enabled or disabled in the following
10145 * three cases:
10146 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10147 * successfully.
10148 * - Positive number and zero for remaining password attempts.
10149 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10150 *
10151 */
10152 @Override
10153 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10154 enforceModifyPermission();
10155
10156 Phone phone = getPhone(subId);
10157 if (phone == null) {
10158 return 0;
10159 }
10160 // Now that all security checks passes, perform the operation as ourselves.
10161 final long identity = Binder.clearCallingIdentity();
10162 try {
10163 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10164 new Pair<Boolean, String>(enabled, password), phone, null);
10165 return attemptsRemaining;
10166
10167 } catch (Exception e) {
10168 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10169 } finally {
10170 Binder.restoreCallingIdentity(identity);
10171 }
10172 return 0;
10173 }
10174
10175 /**
10176 * Change the ICC password used in ICC pin lock.
10177 *
10178 * @return an integer representing the status of IccLock changed in the following three cases:
10179 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10180 * - Positive number and zero for remaining password attempts.
10181 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10182 *
10183 */
10184 @Override
10185 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10186 enforceModifyPermission();
10187
10188 Phone phone = getPhone(subId);
10189 if (phone == null) {
10190 return 0;
10191 }
10192 // Now that all security checks passes, perform the operation as ourselves.
10193 final long identity = Binder.clearCallingIdentity();
10194 try {
10195 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10196 new Pair<String, String>(oldPassword, newPassword), phone, null);
10197 return attemptsRemaining;
10198
10199 } catch (Exception e) {
10200 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10201 } finally {
10202 Binder.restoreCallingIdentity(identity);
10203 }
10204 return 0;
10205 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010206
10207 /**
10208 * Request for receiving user activity notification
10209 */
10210 @Override
10211 public void requestUserActivityNotification() {
10212 if (!mNotifyUserActivity.get()
10213 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10214 mNotifyUserActivity.set(true);
10215 }
10216 }
10217
10218 /**
10219 * Called when userActivity is signalled in the power manager.
10220 * This is safe to call from any thread, with any window manager locks held or not.
10221 */
10222 @Override
10223 public void userActivity() {
10224 // ***************************************
10225 // * Inherited from PhoneWindowManager *
10226 // ***************************************
10227 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10228 // WITH ITS LOCKS HELD.
10229 //
10230 // This code must be VERY careful about the locks
10231 // it acquires.
10232 // In fact, the current code acquires way too many,
10233 // and probably has lurking deadlocks.
10234
10235 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10236 throw new SecurityException("Only the OS may call notifyUserActivity()");
10237 }
10238
10239 if (mNotifyUserActivity.getAndSet(false)) {
10240 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10241 USER_ACTIVITY_NOTIFICATION_DELAY);
10242 }
10243 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010244
10245 @Override
10246 public boolean canConnectTo5GInDsdsMode() {
10247 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10248 }
Jack Yud10cdd42020-09-28 20:28:01 -070010249
10250 @Override
10251 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10252 String callingFeatureId) {
10253 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10254 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10255 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10256 }
10257
10258 Phone phone = getPhone(subId);
10259 if (phone == null) {
10260 throw new RuntimeException("phone is not available");
10261 }
10262 // Now that all security checks passes, perform the operation as ourselves.
10263 final long identity = Binder.clearCallingIdentity();
10264 try {
10265 return phone.getEquivalentHomePlmns();
10266 } finally {
10267 Binder.restoreCallingIdentity(identity);
10268 }
10269 }
Daniel Bright59e67312020-11-13 11:49:37 -080010270
10271 @Override
10272 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010273 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10274 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010275 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010276 if (radioInterfaceCapabilities == null) {
10277 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010278 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010279 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010280 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010281
Hui Wang641e81c2020-10-12 12:14:23 -070010282 @Override
10283 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10284 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010285 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10286 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10287 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10288 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10289 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010290 if (DBG) {
10291 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10292 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10293 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10294 }
10295
10296 if (!SubscriptionManager.isValidSubscriptionId(subId)
10297 || appType < TelephonyManager.APPTYPE_UNKNOWN
10298 || appType > TelephonyManager.APPTYPE_ISIM
10299 || nafUrl == null || securityProtocol == null || callback == null) {
10300 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10301 if (callback != null) {
10302 try {
10303 callback.onAuthenticationFailure(
10304 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10305 } catch (RemoteException exception) {
10306 log("Fail to notify onAuthenticationFailure due to " + exception);
10307 }
10308 return;
10309 }
10310 }
10311
10312 final long token = Binder.clearCallingIdentity();
10313 try {
10314 getGbaManager(subId).bootstrapAuthenticationRequest(
10315 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10316 forceBootStrapping, callback));
10317 } finally {
10318 Binder.restoreCallingIdentity(token);
10319 }
10320 }
10321
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010322 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010323 * Attempts to set the radio power state for all phones for thermal reason.
10324 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010325 * requested radio power state will actually be set. See {@link
10326 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10327 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010328 * @param enable {@code true} if trying to turn radio on.
10329 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10330 * false}.
10331 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010332 private boolean setRadioPowerForThermal(boolean enable) {
10333 boolean isPhoneAvailable = false;
10334 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10335 Phone phone = PhoneFactory.getPhone(i);
10336 if (phone != null) {
10337 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10338 isPhoneAvailable = true;
10339 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010340 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010341
10342 // return true if successfully informed the phone object about the thermal radio power
10343 // request.
10344 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010345 }
10346
10347 private int handleDataThrottlingRequest(int subId,
10348 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010349 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10350 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10351 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10352 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10353 throw new IllegalArgumentException("modem does not support data throttling");
10354 }
10355
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010356 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10357 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010358 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010359 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10360 }
10361
10362 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10363
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010364 if (isDataThrottlingSupported) {
10365 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010366 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010367 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10368 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10369 } else if (thermalMitigationResult
10370 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010371 log("Modem likely does not support data throttling on secondary carrier. Data " +
10372 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10373 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010374 }
10375 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010376 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010377
10378 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010379 }
10380
Jack Nudelman644b91a2021-03-12 14:09:48 -080010381 private static List<String> getThermalMitigationAllowlist(Context context) {
10382 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10383 for (String pckg : context.getResources()
10384 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10385 sThermalMitigationAllowlistedPackages.add(pckg);
10386 }
10387 }
10388
10389 return sThermalMitigationAllowlistedPackages;
10390 }
10391
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010392 private boolean isAnyPhoneInEmergencyState() {
10393 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10394 if (tm.isInEmergencyCall()) {
10395 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10396 return true;
10397 }
10398 for (Phone phone : PhoneFactory.getPhones()) {
10399 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10400 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10401 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10402 + phone.isInEcm());
10403 return true;
10404 }
10405 }
10406
10407 return false;
10408 }
10409
Jack Nudelman644b91a2021-03-12 14:09:48 -080010410 /**
10411 * Used by shell commands to add an authorized package name for thermal mitigation.
10412 * @param packageName name of package to be allowlisted
10413 * @param context
10414 */
10415 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10416 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10417 sThermalMitigationAllowlistedPackages.add(packageName);
10418 }
10419
10420 /**
10421 * Used by shell commands to remove an authorized package name for thermal mitigation.
10422 * @param packageName name of package to remove from allowlist
10423 * @param context
10424 */
10425 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10426 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10427 sThermalMitigationAllowlistedPackages.remove(packageName);
10428 }
10429
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010430 /**
10431 * Thermal mitigation request to control functionalities at modem.
10432 *
10433 * @param subId the id of the subscription.
10434 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010435 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010436 *
10437 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10438 */
10439 @Override
10440 @ThermalMitigationResult
10441 public int sendThermalMitigationRequest(
10442 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010443 ThermalMitigationRequest thermalMitigationRequest,
10444 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010445 enforceModifyPermission();
10446
Jack Nudelman644b91a2021-03-12 14:09:48 -080010447 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10448 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10449 .contains(callingPackage)) {
10450 throw new SecurityException("Calling package must be configured in the device config. "
10451 + "calling package: " + callingPackage);
10452 }
10453
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010454 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10455 final long identity = Binder.clearCallingIdentity();
10456
10457 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10458 try {
10459 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10460 switch (thermalMitigationAction) {
10461 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10462 thermalMitigationResult =
10463 handleDataThrottlingRequest(subId,
10464 thermalMitigationRequest.getDataThrottlingRequest());
10465 break;
10466 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10467 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10468 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10469 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10470 }
10471
10472 // Ensure that radio is on. If not able to power on due to phone being
10473 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010474 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010475 thermalMitigationResult =
10476 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10477 break;
10478 }
10479
10480 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10481 false);
10482 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10483 break;
10484 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10485 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10486 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10487 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10488 }
10489
10490 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10491 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010492 Phone phone = getPhone(subId);
10493 if (phone == null) {
10494 thermalMitigationResult =
10495 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10496 break;
10497 }
10498
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010499 TelephonyConnectionService service =
10500 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010501 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010502 Log.e(LOG_TAG, "An emergency call is pending");
10503 thermalMitigationResult =
10504 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10505 break;
10506 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010507 thermalMitigationResult =
10508 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10509 break;
10510 }
10511 } else {
10512 thermalMitigationResult =
10513 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10514 break;
10515 }
10516
10517 // Turn radio off. If not able to power off due to phone being unavailable,
10518 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010519 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010520 thermalMitigationResult =
10521 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10522 break;
10523 }
10524 thermalMitigationResult =
10525 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10526 break;
10527 default:
10528 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10529 + "not exist. Requested action: " + thermalMitigationAction);
10530 }
10531 } catch (IllegalArgumentException e) {
10532 throw e;
10533 } catch (Exception e) {
10534 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10535 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10536 } finally {
10537 Binder.restoreCallingIdentity(identity);
10538 }
10539
10540 if (DBG) {
10541 log("thermalMitigationRequest returning with thermalMitigationResult: "
10542 + thermalMitigationResult);
10543 }
10544
10545 return thermalMitigationResult;
10546 }
Hui Wang641e81c2020-10-12 12:14:23 -070010547
10548 /**
10549 * Set the GbaService Package Name that Telephony will bind to.
10550 *
10551 * @param subId The sim that the GbaService is associated with.
10552 * @param packageName The name of the package to be replaced with.
10553 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10554 */
10555 @Override
10556 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10557 enforceModifyPermission();
10558
10559 final long identity = Binder.clearCallingIdentity();
10560 try {
10561 return getGbaManager(subId).overrideServicePackage(packageName);
10562 } finally {
10563 Binder.restoreCallingIdentity(identity);
10564 }
10565 }
10566
10567 /**
10568 * Return the package name of the currently bound GbaService.
10569 *
10570 * @param subId The sim that the GbaService is associated with.
10571 * @return the package name of the GbaService configuration, null if GBA is not supported.
10572 */
10573 @Override
10574 public String getBoundGbaService(int subId) {
10575 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10576
10577 final long identity = Binder.clearCallingIdentity();
10578 try {
10579 return getGbaManager(subId).getServicePackage();
10580 } finally {
10581 Binder.restoreCallingIdentity(identity);
10582 }
10583 }
10584
10585 /**
10586 * Set the release time for telephony to unbind GbaService.
10587 *
10588 * @param subId The sim that the GbaService is associated with.
10589 * @param interval The release time to unbind GbaService by millisecond.
10590 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10591 */
10592 @Override
10593 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10594 enforceModifyPermission();
10595
10596 final long identity = Binder.clearCallingIdentity();
10597 try {
10598 return getGbaManager(subId).overrideReleaseTime(interval);
10599 } finally {
10600 Binder.restoreCallingIdentity(identity);
10601 }
10602 }
10603
10604 /**
10605 * Return the release time for telephony to unbind GbaService.
10606 *
10607 * @param subId The sim that the GbaService is associated with.
10608 * @return The release time to unbind GbaService by millisecond.
10609 */
10610 @Override
10611 public int getGbaReleaseTime(int subId) {
10612 enforceReadPrivilegedPermission("getGbaReleaseTime");
10613
10614 final long identity = Binder.clearCallingIdentity();
10615 try {
10616 return getGbaManager(subId).getReleaseTime();
10617 } finally {
10618 Binder.restoreCallingIdentity(identity);
10619 }
10620 }
10621
10622 private GbaManager getGbaManager(int subId) {
10623 GbaManager instance = GbaManager.getInstance(subId);
10624 if (instance == null) {
10625 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10626 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10627 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10628 }
10629 return instance;
10630 }
Hui Wang761a6682020-10-31 05:12:53 +000010631
10632 /**
10633 * indicate whether the device and the carrier can support
10634 * RCS VoLTE single registration.
10635 */
10636 @Override
10637 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010638 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10639 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10640 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10641 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010642
10643 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10644 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10645 }
10646
10647 final long identity = Binder.clearCallingIdentity();
10648 try {
10649 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10650 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010651 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10652 if (isCapable != null) {
10653 return isCapable;
10654 }
Hui Wang761a6682020-10-31 05:12:53 +000010655 }
Hui Wang67af90e2021-06-04 16:57:15 -070010656 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10657 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010658 } finally {
10659 Binder.restoreCallingIdentity(identity);
10660 }
10661 }
10662
10663 /**
10664 * Register RCS provisioning callback.
10665 */
10666 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010667 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010668 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010669 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010670 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010671 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10672 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010673
10674 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10675 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10676 }
10677 if (!isImsAvailableOnDevice()) {
10678 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10679 "IMS not available on device.");
10680 }
10681
10682 final long identity = Binder.clearCallingIdentity();
10683 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010684 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010685 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010686 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10687 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010688 }
Hui Wang761a6682020-10-31 05:12:53 +000010689 } finally {
10690 Binder.restoreCallingIdentity(identity);
10691 }
10692 }
10693
10694 /**
10695 * Unregister RCS provisioning callback.
10696 */
10697 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010698 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010699 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010700 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010701 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010702 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10703 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010704
10705 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10706 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10707 }
10708 if (!isImsAvailableOnDevice()) {
10709 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10710 "IMS not available on device.");
10711 }
10712
10713 final long identity = Binder.clearCallingIdentity();
10714 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010715 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010716 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010717 } finally {
10718 Binder.restoreCallingIdentity(identity);
10719 }
10720 }
10721
10722 /**
10723 * trigger RCS reconfiguration.
10724 */
10725 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010726 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10727 "triggerRcsReconfiguration",
10728 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010729
10730 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10731 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10732 }
10733 if (!isImsAvailableOnDevice()) {
10734 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10735 "IMS not available on device.");
10736 }
10737
10738 final long identity = Binder.clearCallingIdentity();
10739 try {
10740 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10741 } finally {
10742 Binder.restoreCallingIdentity(identity);
10743 }
10744 }
10745
10746 /**
10747 * Provide the client configuration parameters of the RCS application.
10748 */
10749 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010750 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10751 "setRcsClientConfiguration",
10752 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010753
10754 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10755 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10756 }
10757 if (!isImsAvailableOnDevice()) {
10758 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10759 "IMS not available on device.");
10760 }
10761
10762 final long identity = Binder.clearCallingIdentity();
10763
10764 try {
10765 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10766 if (configBinder == null) {
10767 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010768 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10769 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010770 } else {
10771 configBinder.setRcsClientConfiguration(rcc);
10772 }
joonhunshin3e154242021-09-17 06:33:39 +000010773
10774 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10775 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010776 } catch (RemoteException e) {
10777 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010778 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10779 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010780 } finally {
10781 Binder.restoreCallingIdentity(identity);
10782 }
10783 }
10784
10785 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010786 * Enables or disables the test mode for RCS VoLTE single registration.
10787 */
10788 @Override
10789 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10790 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10791 "setRcsSingleRegistrationTestModeEnabled");
10792
10793 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10794 }
10795
10796 /**
10797 * Gets the test mode for RCS VoLTE single registration.
10798 */
10799 @Override
10800 public boolean getRcsSingleRegistrationTestModeEnabled() {
10801 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10802 "getRcsSingleRegistrationTestModeEnabled");
10803
10804 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10805 }
10806
10807 /**
Hui Wang761a6682020-10-31 05:12:53 +000010808 * Overrides the config of RCS VoLTE single registration enabled for the device.
10809 */
10810 @Override
10811 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10812 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10813 "setDeviceSingleRegistrationEnabledOverride");
10814 enforceModifyPermission();
10815
10816 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10817 : Boolean.parseBoolean(enabledStr);
10818 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010819 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010820 }
10821
10822 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010823 * Sends a device to device communication message. Only usable via shell.
10824 * @param message message to send.
10825 * @param value message value.
10826 */
10827 @Override
10828 public void sendDeviceToDeviceMessage(int message, int value) {
10829 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010830 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010831 enforceModifyPermission();
10832
10833 final long identity = Binder.clearCallingIdentity();
10834 try {
10835 TelephonyConnectionService service =
10836 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10837 if (service == null) {
10838 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10839 return;
10840 }
10841 service.sendTestDeviceToDeviceMessage(message, value);
10842 } finally {
10843 Binder.restoreCallingIdentity(identity);
10844 }
10845 }
10846
Tyler Gunnbabbda02021-02-10 11:05:02 -080010847 /**
10848 * Sets the specified device to device transport active.
10849 * @param transport The transport to set active.
10850 */
10851 @Override
10852 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10853 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10854 "setActiveDeviceToDeviceTransport");
10855 enforceModifyPermission();
10856
10857 final long identity = Binder.clearCallingIdentity();
10858 try {
10859 TelephonyConnectionService service =
10860 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10861 if (service == null) {
10862 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10863 return;
10864 }
10865 service.setActiveDeviceToDeviceTransport(transport);
10866 } finally {
10867 Binder.restoreCallingIdentity(identity);
10868 }
10869 }
Tyler Gunn92479152021-01-20 16:30:10 -080010870
Tyler Gunnd4339262021-05-03 14:46:49 -070010871 @Override
10872 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10873 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10874 "setDeviceToDeviceForceEnabled");
10875
10876 final long identity = Binder.clearCallingIdentity();
10877 try {
10878 Arrays.stream(PhoneFactory.getPhones()).forEach(
10879 p -> {
10880 Phone thePhone = p.getImsPhone();
10881 if (thePhone != null && thePhone instanceof ImsPhone) {
10882 ImsPhone imsPhone = (ImsPhone) thePhone;
10883 CallTracker tracker = imsPhone.getCallTracker();
10884 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10885 ImsPhoneCallTracker imsPhoneCallTracker =
10886 (ImsPhoneCallTracker) tracker;
10887 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10888 }
10889 }
10890 }
10891 );
10892 } finally {
10893 Binder.restoreCallingIdentity(identity);
10894 }
10895 }
10896
Tyler Gunn92479152021-01-20 16:30:10 -080010897 /**
Hui Wang761a6682020-10-31 05:12:53 +000010898 * Gets the config of RCS VoLTE single registration enabled for the device.
10899 */
10900 @Override
10901 public boolean getDeviceSingleRegistrationEnabled() {
10902 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10903 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10904 }
10905
10906 /**
10907 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10908 */
10909 @Override
10910 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10911 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10912 "setCarrierSingleRegistrationEnabledOverride");
10913 enforceModifyPermission();
10914
10915 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10916 : Boolean.parseBoolean(enabledStr);
10917 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10918 subId, enabled);
10919 }
10920
10921 /**
10922 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10923 */
10924 @Override
10925 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10926 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10927 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10928 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010929
10930 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010931 * Overrides the ims feature validation result
10932 */
10933 @Override
10934 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10935 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10936 "setImsFeatureValidationOverride");
10937
10938 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10939 : Boolean.parseBoolean(enabledStr);
10940 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10941 subId, enabled);
10942 }
10943
10944 /**
10945 * Gets the ims feature validation override value
10946 */
10947 @Override
10948 public boolean getImsFeatureValidationOverride(int subId) {
10949 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10950 "getImsFeatureValidationOverride");
10951 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10952 }
10953
10954 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010955 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10956 * their mobile plan.
10957 */
10958 @Override
10959 public String getMobileProvisioningUrl() {
10960 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10961 final long identity = Binder.clearCallingIdentity();
10962 try {
10963 return getDefaultPhone().getMobileProvisioningUrl();
10964 } finally {
10965 Binder.restoreCallingIdentity(identity);
10966 }
10967 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010968
James.cf Linbcdf8b32021-01-14 16:44:13 +080010969 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010970 * Get the EAB contact from the EAB database.
10971 */
10972 @Override
10973 public String getContactFromEab(String contact) {
10974 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10975 enforceModifyPermission();
10976 final long identity = Binder.clearCallingIdentity();
10977 try {
10978 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10979 } finally {
10980 Binder.restoreCallingIdentity(identity);
10981 }
10982 }
10983
10984 /**
Calvin Pana1434322021-07-01 19:27:01 +080010985 * Get the EAB capability from the EAB database.
10986 */
10987 @Override
10988 public String getCapabilityFromEab(String contact) {
10989 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10990 enforceModifyPermission();
10991 final long identity = Binder.clearCallingIdentity();
10992 try {
10993 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10994 } finally {
10995 Binder.restoreCallingIdentity(identity);
10996 }
10997 }
10998
10999 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011000 * Remove the EAB contacts from the EAB database.
11001 */
11002 @Override
11003 public int removeContactFromEab(int subId, String contacts) {
11004 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11005 enforceModifyPermission();
11006 final long identity = Binder.clearCallingIdentity();
11007 try {
11008 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11009 } finally {
11010 Binder.restoreCallingIdentity(identity);
11011 }
11012 }
11013
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011014 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011015 public boolean getDeviceUceEnabled() {
11016 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11017 final long identity = Binder.clearCallingIdentity();
11018 try {
11019 return mApp.getDeviceUceEnabled();
11020 } finally {
11021 Binder.restoreCallingIdentity(identity);
11022 }
11023 }
11024
11025 @Override
11026 public void setDeviceUceEnabled(boolean isEnabled) {
11027 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11028 final long identity = Binder.clearCallingIdentity();
11029 try {
11030 mApp.setDeviceUceEnabled(isEnabled);
11031 } finally {
11032 Binder.restoreCallingIdentity(identity);
11033 }
11034 }
11035
Brad Ebinger14d467f2021-02-12 06:18:28 +000011036 /**
11037 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11038 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11039 */
11040 // Used for SHELL command only right now.
11041 @Override
11042 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11043 List<String> featureTags) {
11044 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11045 "addUceRegistrationOverrideShell");
11046 final long identity = Binder.clearCallingIdentity();
11047 try {
11048 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11049 new ArraySet<>(featureTags));
11050 } catch (ImsException e) {
11051 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11052 } finally {
11053 Binder.restoreCallingIdentity(identity);
11054 }
11055 }
11056
11057 /**
11058 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11059 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11060 */
11061 // Used for SHELL command only right now.
11062 @Override
11063 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11064 List<String> featureTags) {
11065 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11066 "removeUceRegistrationOverrideShell");
11067 final long identity = Binder.clearCallingIdentity();
11068 try {
11069 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11070 new ArraySet<>(featureTags));
11071 } catch (ImsException e) {
11072 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11073 } finally {
11074 Binder.restoreCallingIdentity(identity);
11075 }
11076 }
11077
11078 /**
11079 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11080 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11081 */
11082 // Used for SHELL command only right now.
11083 @Override
11084 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11085 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11086 "clearUceRegistrationOverrideShell");
11087 final long identity = Binder.clearCallingIdentity();
11088 try {
11089 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11090 } catch (ImsException e) {
11091 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11092 } finally {
11093 Binder.restoreCallingIdentity(identity);
11094 }
11095 }
11096
11097 /**
11098 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11099 */
11100 // Used for SHELL command only right now.
11101 @Override
11102 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11104 "getLatestRcsContactUceCapabilityShell");
11105 final long identity = Binder.clearCallingIdentity();
11106 try {
11107 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11108 } catch (ImsException e) {
11109 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11110 } finally {
11111 Binder.restoreCallingIdentity(identity);
11112 }
11113 }
11114
11115 /**
11116 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11117 * device does not have an active PUBLISH.
11118 */
11119 // Used for SHELL command only right now.
11120 @Override
11121 public String getLastUcePidfXmlShell(int subId) {
11122 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11123 final long identity = Binder.clearCallingIdentity();
11124 try {
11125 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11126 } catch (ImsException e) {
11127 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11128 } finally {
11129 Binder.restoreCallingIdentity(identity);
11130 }
11131 }
11132
James.cf Line8713a42021-04-29 16:04:26 +080011133 /**
11134 * Remove UCE requests cannot be sent to the network status.
11135 */
11136 // Used for SHELL command only right now.
11137 @Override
11138 public boolean removeUceRequestDisallowedStatus(int subId) {
11139 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11140 final long identity = Binder.clearCallingIdentity();
11141 try {
11142 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11143 } catch (ImsException e) {
11144 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11145 } finally {
11146 Binder.restoreCallingIdentity(identity);
11147 }
11148 }
11149
James.cf Lin18bb9002021-05-25 01:37:38 +080011150 /**
11151 * Remove UCE requests cannot be sent to the network status.
11152 */
11153 // Used for SHELL command only.
11154 @Override
11155 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11156 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11157 final long identity = Binder.clearCallingIdentity();
11158 try {
11159 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11160 } catch (ImsException e) {
11161 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11162 } finally {
11163 Binder.restoreCallingIdentity(identity);
11164 }
11165 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011166
James.cf Lin4b784aa2021-01-31 03:25:15 +080011167 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011168 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11169 String callingPackage) {
11170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11171 mApp, subId, "setSignalStrengthUpdateRequest");
11172
11173 final int callingUid = Binder.getCallingUid();
11174 // Verify that tha callingPackage belongs to the calling UID
11175 mApp.getSystemService(AppOpsManager.class)
11176 .checkPackage(callingUid, callingPackage);
11177
Rambo Wang3607f502021-02-01 21:51:40 -080011178 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011179
11180 final long identity = Binder.clearCallingIdentity();
11181 try {
11182 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11183 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11184
11185 if (result instanceof IllegalStateException) {
11186 throw (IllegalStateException) result;
11187 }
11188 } finally {
11189 Binder.restoreCallingIdentity(identity);
11190 }
11191 }
11192
11193 @Override
11194 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11195 String callingPackage) {
11196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11197 mApp, subId, "clearSignalStrengthUpdateRequest");
11198
11199 final int callingUid = Binder.getCallingUid();
11200 // Verify that tha callingPackage belongs to the calling UID
11201 mApp.getSystemService(AppOpsManager.class)
11202 .checkPackage(callingUid, callingPackage);
11203
11204 final long identity = Binder.clearCallingIdentity();
11205 try {
11206 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11207 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11208
11209 if (result instanceof IllegalStateException) {
11210 throw (IllegalStateException) result;
11211 }
11212 } finally {
11213 Binder.restoreCallingIdentity(identity);
11214 }
11215 }
11216
Rambo Wang3607f502021-02-01 21:51:40 -080011217 private static void validateSignalStrengthUpdateRequest(Context context,
11218 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011219 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11220 // phone/system process do not have further restriction on request
11221 return;
11222 }
11223
11224 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011225 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011226 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011227 context.enforceCallingOrSelfPermission(
11228 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11229 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011230 }
11231
11232 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11233 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11234 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11235 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11236 || info.isEnabled()) {
11237 throw new IllegalArgumentException(
11238 "Only system can set hide fields in SignalThresholdInfo");
11239 }
11240
11241 // Thresholds length for each RAN need in range. This has been validated in
11242 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11243 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11244 final int[] thresholds = info.getThresholds();
11245 Objects.requireNonNull(thresholds);
11246 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11247 || thresholds.length
11248 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11249 throw new IllegalArgumentException(
11250 "thresholds length is out of range: " + thresholds.length);
11251 }
11252 }
11253 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011254
11255 /**
11256 * Gets the current phone capability.
11257 *
11258 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11259 * @return the PhoneCapability which describes the data connection capability of modem.
11260 * It's used to evaluate possible phone config change, for example from single
11261 * SIM device to multi-SIM device.
11262 */
11263 @Override
11264 public PhoneCapability getPhoneCapability() {
11265 enforceReadPrivilegedPermission("getPhoneCapability");
11266 final long identity = Binder.clearCallingIdentity();
11267 try {
11268 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11269 } finally {
11270 Binder.restoreCallingIdentity(identity);
11271 }
11272 }
Michele Berionne5e411512020-11-13 02:36:59 +000011273
11274 /**
11275 * Prepare TelephonyManager for an unattended reboot. The reboot is
11276 * required to be done shortly after the API is invoked.
11277 */
11278 @Override
11279 @TelephonyManager.PrepareUnattendedRebootResult
11280 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011281 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011282 enforceRebootPermission();
11283
11284 final long identity = Binder.clearCallingIdentity();
11285 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011286 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011287 } finally {
11288 Binder.restoreCallingIdentity(identity);
11289 }
11290 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011291
11292 /**
11293 * Request to get the current slicing configuration including URSP rules and
11294 * NSSAIs (configured, allowed and rejected).
11295 *
11296 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11297 */
11298 @Override
11299 public void getSlicingConfig(ResultReceiver callback) {
11300 enforceReadPrivilegedPermission("getSlicingConfig");
11301
11302 final long identity = Binder.clearCallingIdentity();
11303 try {
11304 Phone phone = getDefaultPhone();
11305 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11306 } finally {
11307 Binder.restoreCallingIdentity(identity);
11308 }
11309 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011310
11311 /**
11312 * Register an IMS connection state callback
11313 */
11314 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011315 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11316 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011317 if (feature == ImsFeature.FEATURE_MMTEL) {
11318 // ImsMmTelManager
11319 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11320 TelephonyPermissions
11321 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11322 mApp, subId, "registerImsStateCallback");
11323 } else if (feature == ImsFeature.FEATURE_RCS) {
11324 // ImsRcsManager or SipDelegateManager
11325 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11326 Binder.getCallingUid(), "registerImsStateCallback",
11327 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11328 Manifest.permission.READ_PRECISE_PHONE_STATE,
11329 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11330 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11331 }
11332
11333 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11334 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11335 "IMS not available on device.");
11336 }
11337
11338 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11339 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11340 }
11341
11342 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11343 if (controller == null) {
11344 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11345 "IMS not available on device.");
11346 }
11347
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011348 if (callingPackage == null) {
11349 callingPackage = getCurrentPackageName();
11350 }
11351
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011352 final long token = Binder.clearCallingIdentity();
11353 try {
11354 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011355 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011356 } catch (ImsException e) {
11357 throw new ServiceSpecificException(e.getCode());
11358 } finally {
11359 Binder.restoreCallingIdentity(token);
11360 }
11361 }
11362
11363 /**
11364 * Unregister an IMS connection state callback
11365 */
11366 @Override
11367 public void unregisterImsStateCallback(IImsStateCallback cb) {
11368 final long token = Binder.clearCallingIdentity();
11369 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11370 if (controller == null) {
11371 return;
11372 }
11373 try {
11374 controller.unregisterImsStateCallback(cb);
11375 } finally {
11376 Binder.restoreCallingIdentity(token);
11377 }
11378 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011379
11380 /**
11381 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11382 *
11383 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11384 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11385 * SecurityException.
11386 * If there is current registered network this value will be same as the registered cell
11387 * identity. If the device goes out of service the previous cell identity is cached and
11388 * will be returned. If the cache age of the Cell identity is more than 24 hours
11389 * it will be cleared and null will be returned.
11390 *
11391 */
11392 @Override
11393 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11394 String callingFeatureId) {
11395 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11396 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11397 LocationAccessPolicy.checkLocationPermission(mApp,
11398 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11399 .setCallingPackage(callingPackage)
11400 .setCallingFeatureId(callingFeatureId)
11401 .setCallingPid(Binder.getCallingPid())
11402 .setCallingUid(Binder.getCallingUid())
11403 .setMethod("getLastKnownCellIdentity")
11404 .setLogAsInfo(true)
11405 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11406 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11407 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11408 .build());
11409
11410 boolean hasFinePermission =
11411 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11412 if (!hasFinePermission
11413 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11414 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11415 + "and BIND_CONNECTION_SERVICE permission.");
11416 }
11417
11418 final long identity = Binder.clearCallingIdentity();
11419 try {
11420 Phone phone = getPhone(subId);
11421 if (phone == null) return null;
11422 ServiceStateTracker sst = phone.getServiceStateTracker();
11423 if (sst == null) return null;
11424 return sst.getLastKnownCellIdentity();
11425 } finally {
11426 Binder.restoreCallingIdentity(identity);
11427 }
11428 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011429
11430 @Override
11431 public boolean isUsingNewDataStack() {
11432 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11433 return getDefaultPhone().isUsingNewDataStack();
11434 }
jimsun3b9ccac2021-10-26 15:01:23 +080011435
11436 /**
11437 * Sets the modem service class Name that Telephony will bind to.
11438 *
11439 * @param serviceName The class name of the modem service.
11440 * @return true if the operation is succeed, otherwise false.
11441 */
11442 public boolean setModemService(String serviceName) {
11443 Log.d(LOG_TAG, "setModemService - " + serviceName);
11444 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11446 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11447 "setModemService");
11448 return mPhoneConfigurationManager.setModemService(serviceName);
11449 }
11450
11451 /**
11452 * Return the class name of the currently bounded modem service.
11453 *
11454 * @return the class name of the modem service.
11455 */
11456 public String getModemService() {
11457 String result;
11458 Log.d(LOG_TAG, "getModemService");
11459 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11460 TelephonyPermissions
11461 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11462 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11463 "getModemService");
11464 result = mPhoneConfigurationManager.getModemService();
11465 Log.d(LOG_TAG, "result = " + result);
11466 return result;
11467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011468}