blob: a47701c503fef086140afd581b4f77605294da9f [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;
Tyler Gunn64144d92022-03-17 14:16:41 -070034import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000035import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080036import android.app.role.RoleManager;
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;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080053import android.os.LocaleList;
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 Yu0eda6842022-04-18 00:34:46 -070079import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080080import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080081import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070082import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080083import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070084import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080085import android.telephony.CellIdentityCdma;
86import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070088import android.telephony.CellInfoGsm;
89import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070090import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080091import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070092import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070093import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070094import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080095import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070096import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080097import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070098import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080099import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800100import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700101import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800102import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800104import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800105import android.telephony.SignalStrengthUpdateRequest;
106import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800107import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800109import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700110import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700111import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800112import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800113import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800114import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000115import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000116import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000117import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700118import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700119import android.telephony.VisualVoicemailSmsFilterSettings;
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;
joonhunshincffb7fc2021-11-28 07:32:01 +0000129import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700130import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800131import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700132import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800133import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700134import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000135import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700136import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800137import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800138import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800140import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700141import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800143import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800144
Andrew Lee312e8172014-10-23 17:01:36 -0700145import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800146import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800147import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800148import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800149import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700150import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700151import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700152import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800153import com.android.internal.telephony.CarrierPrivilegesTracker;
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;
Hui Wang641e81c2020-10-12 12:14:23 -0700158import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800159import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800160import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800161import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700162import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000163import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800165import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800167import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800168import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700170import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700171import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700173import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800174import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700175import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700176import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700177import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700178import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800179import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800180import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700181import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700182import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700183import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800184import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800185import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800186import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700187import com.android.internal.telephony.data.DataUtils;
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;
198import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700200import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000203import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800204import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000205import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800206import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700207import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700208import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800209import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800210import com.android.phone.callcomposer.CallComposerPictureManager;
211import com.android.phone.callcomposer.CallComposerPictureTransfer;
212import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700213import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700214import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800215import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700216import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700217import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800218import com.android.services.telephony.TelecomAccountRegistry;
219import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800220import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800221
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700223import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.io.IOException;
225import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700226import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800228import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000229import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800230import java.util.Collections;
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;
Chen Xue9d737e2022-01-01 23:41:31 -0800548 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 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");
Chen Xue9d737e2022-01-01 23:41:31 -0800592 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,
Chen Xue9d737e2022-01-01 23:41:31 -0800596 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000597 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800598 iccArgument.channel, iccArgument.cla, iccArgument.command,
599 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
600 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 {
Chen Xue9d737e2022-01-01 23:41:31 -0800610 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 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");
Chen Xue9d737e2022-01-01 23:41:31 -0800629 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,
Chen Xue9d737e2022-01-01 23:41:31 -0800633 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000634 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800635 iccArgument.cla, iccArgument.command, iccArgument.p1,
636 iccArgument.p2,
637 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 }
639 break;
640
641 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
642 ar = (AsyncResult) msg.obj;
643 request = (MainThreadRequest) ar.userObj;
644 if (ar.exception == null && ar.result != null) {
645 request.result = ar.result;
646 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800647 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 if (ar.result == null) {
649 loge("iccTransmitApduBasicChannel: Empty response");
650 } else if (ar.exception instanceof CommandException) {
651 loge("iccTransmitApduBasicChannel: CommandException: " +
652 ar.exception);
653 } else {
654 loge("iccTransmitApduBasicChannel: Unknown exception");
655 }
656 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 break;
659
660 case CMD_EXCHANGE_SIM_IO:
661 request = (MainThreadRequest) msg.obj;
662 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000663 uiccPort = getUiccPortFromRequest(request);
664 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800666 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 } else {
669 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
670 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000671 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
673 iccArgument.data, onCompleted);
674 }
675 break;
676
677 case EVENT_EXCHANGE_SIM_IO_DONE:
678 ar = (AsyncResult) msg.obj;
679 request = (MainThreadRequest) ar.userObj;
680 if (ar.exception == null && ar.result != null) {
681 request.result = ar.result;
682 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800683 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 break;
687
Derek Tan4d5e5c12014-02-04 11:54:58 -0800688 case CMD_SEND_ENVELOPE:
689 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000690 uiccPort = getUiccPortFromRequest(request);
691 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800693 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700694 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 } else {
696 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800697 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700698 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800699 break;
700
701 case EVENT_SEND_ENVELOPE_DONE:
702 ar = (AsyncResult) msg.obj;
703 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700704 if (ar.exception == null && ar.result != null) {
705 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800706 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800707 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700708 if (ar.result == null) {
709 loge("sendEnvelopeWithStatus: Empty response");
710 } else if (ar.exception instanceof CommandException) {
711 loge("sendEnvelopeWithStatus: CommandException: " +
712 ar.exception);
713 } else {
714 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
715 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800718 break;
719
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 case CMD_OPEN_CHANNEL:
721 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000722 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800723 IccLogicalChannelRequest openChannelRequest =
724 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000725 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700726 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800727 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800728 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700729 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700730 } else {
731 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800732 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
733 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700734 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700735 break;
736
737 case EVENT_OPEN_CHANNEL_DONE:
738 ar = (AsyncResult) msg.obj;
739 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700740 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 int[] result = (int[]) ar.result;
743 int channelId = result[0];
744 byte[] selectResponse = null;
745 if (result.length > 1) {
746 selectResponse = new byte[result.length - 1];
747 for (int i = 1; i < result.length; ++i) {
748 selectResponse[i - 1] = (byte) result[i];
749 }
750 }
751 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800752 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800753
754 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700755 if (uiccPort == null) {
756 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
757 } else {
758 IccLogicalChannelRequest channelRequest =
759 (IccLogicalChannelRequest) request.argument;
760 channelRequest.channel = channelId;
761 uiccPort.onLogicalChannelOpened(channelRequest);
762 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 if (ar.result == null) {
765 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700766 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700767 if (ar.exception != null) {
768 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
769 }
770
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700771 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700772 if (ar.exception instanceof CommandException) {
773 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800774 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700775 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700776 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700777 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700778 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700779 }
780 }
781 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800782 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700783 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700784 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700785 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700786 break;
787
788 case CMD_CLOSE_CHANNEL:
789 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000790 uiccPort = getUiccPortFromRequest(request);
791 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700792 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800793 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800794 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800795 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700796 } else {
797 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000798 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700799 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 break;
801
802 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
805 if (ar.exception == null) {
806 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800807 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700808 if (uiccPort == null) {
809 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
810 } else {
811 final int channelId = (Integer) request.argument;
812 uiccPort.onLogicalChannelClosed(channelId);
813 }
Chen Xu540470b2021-12-14 17:15:47 -0800814 } else {
815 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800816 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800817 if (ar.exception instanceof CommandException) {
818 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
819 CommandException.Error error =
820 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800821 if (error == CommandException.Error.INVALID_ARGUMENTS) {
822 // should only throw exceptions from the binder threads.
823 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800824 "iccCloseLogicalChannel: invalid argument ");
825 }
826 } else {
827 loge("iccCloseLogicalChannel: Unknown exception");
828 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800829 request.result = (exception != null) ? exception :
830 new IllegalStateException(
831 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800832 }
833 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800834 break;
835
836 case CMD_NV_READ_ITEM:
837 request = (MainThreadRequest) msg.obj;
838 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800839 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
840 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800841 break;
842
843 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700844 ar = (AsyncResult) msg.obj;
845 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800846 if (ar.exception == null && ar.result != null) {
847 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800849 request.result = "";
850 if (ar.result == null) {
851 loge("nvReadItem: Empty response");
852 } else if (ar.exception instanceof CommandException) {
853 loge("nvReadItem: CommandException: " +
854 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700855 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800856 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700857 }
858 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700859 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700860 break;
861
Jake Hambye994d462014-02-03 13:10:13 -0800862 case CMD_NV_WRITE_ITEM:
863 request = (MainThreadRequest) msg.obj;
864 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
865 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800866 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700867 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800868 break;
869
870 case EVENT_NV_WRITE_ITEM_DONE:
871 handleNullReturnEvent(msg, "nvWriteItem");
872 break;
873
874 case CMD_NV_WRITE_CDMA_PRL:
875 request = (MainThreadRequest) msg.obj;
876 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800877 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800878 break;
879
880 case EVENT_NV_WRITE_CDMA_PRL_DONE:
881 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
882 break;
883
chen xu6dac5ab2018-10-26 17:39:23 -0700884 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800885 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700886 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800887 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800888 break;
889
chen xu6dac5ab2018-10-26 17:39:23 -0700890 case EVENT_RESET_MODEM_CONFIG_DONE:
891 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800892 break;
893
Sooraj Sasindran37444802020-08-11 10:40:43 -0700894 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
895 request = (MainThreadRequest) msg.obj;
896 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
897 request);
898 Phone phone = getPhoneFromRequest(request);
899 if (phone != null) {
900 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
901 } else {
902 loge("isNRDualConnectivityEnabled: No phone object");
903 request.result = false;
904 notifyRequester(request);
905 }
906 break;
907 }
908
909 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result;
914 } else {
915 // request.result must be set to something non-null
916 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700917 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700918 request.result = ar.result;
919 } else {
920 request.result = false;
921 }
922 if (ar.result == null) {
923 loge("isNRDualConnectivityEnabled: Empty response");
924 } else if (ar.exception instanceof CommandException) {
925 loge("isNRDualConnectivityEnabled: CommandException: "
926 + ar.exception);
927 } else {
928 loge("isNRDualConnectivityEnabled: Unknown exception");
929 }
930 }
931 notifyRequester(request);
932 break;
933
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700934 case CMD_IS_VONR_ENABLED: {
935 request = (MainThreadRequest) msg.obj;
936 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
937 request);
938 Phone phone = getPhoneFromRequest(request);
939 if (phone != null) {
940 phone.isVoNrEnabled(onCompleted, request.workSource);
941 } else {
942 loge("isVoNrEnabled: No phone object");
943 request.result = false;
944 notifyRequester(request);
945 }
946 break;
947 }
948
949 case EVENT_IS_VONR_ENABLED_DONE:
950 ar = (AsyncResult) msg.obj;
951 request = (MainThreadRequest) ar.userObj;
952 if (ar.exception == null && ar.result != null) {
953 request.result = ar.result;
954 } else {
955 // request.result must be set to something non-null
956 // for the calling thread to unblock
957 if (ar.result != null) {
958 request.result = ar.result;
959 } else {
960 request.result = false;
961 }
962 if (ar.result == null) {
963 loge("isVoNrEnabled: Empty response");
964 } else if (ar.exception instanceof CommandException) {
965 loge("isVoNrEnabled: CommandException: "
966 + ar.exception);
967 } else {
968 loge("isVoNrEnabled: Unknown exception");
969 }
970 }
971 notifyRequester(request);
972 break;
973
Sooraj Sasindran37444802020-08-11 10:40:43 -0700974 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
975 request = (MainThreadRequest) msg.obj;
976 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
977 Phone phone = getPhoneFromRequest(request);
978 if (phone != null) {
979 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
980 request.workSource);
981 } else {
982 loge("enableNrDualConnectivity: No phone object");
983 request.result =
984 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
985 notifyRequester(request);
986 }
987 break;
988 }
989
990 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
991 ar = (AsyncResult) msg.obj;
992 request = (MainThreadRequest) ar.userObj;
993 if (ar.exception == null) {
994 request.result =
995 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
996 } else {
997 request.result =
998 TelephonyManager
999 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1000 if (ar.exception instanceof CommandException) {
1001 CommandException.Error error =
1002 ((CommandException) (ar.exception)).getCommandError();
1003 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1004 request.result =
1005 TelephonyManager
1006 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001007 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1008 request.result =
1009 TelephonyManager
1010 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001011 }
1012 loge("enableNrDualConnectivity" + ": CommandException: "
1013 + ar.exception);
1014 } else {
1015 loge("enableNrDualConnectivity" + ": Unknown exception");
1016 }
1017 }
1018 notifyRequester(request);
1019 break;
1020 }
1021
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001022 case CMD_ENABLE_VONR: {
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1025 Phone phone = getPhoneFromRequest(request);
1026 if (phone != null) {
1027 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1028 request.workSource);
1029 } else {
1030 loge("setVoNrEnabled: No phone object");
1031 request.result =
1032 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1033 notifyRequester(request);
1034 }
1035 break;
1036 }
1037
1038 case EVENT_ENABLE_VONR_DONE: {
1039 ar = (AsyncResult) msg.obj;
1040 request = (MainThreadRequest) ar.userObj;
1041 if (ar.exception == null) {
1042 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1043 } else {
1044 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1045 if (ar.exception instanceof CommandException) {
1046 CommandException.Error error =
1047 ((CommandException) (ar.exception)).getCommandError();
1048 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1049 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1050 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1051 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1052 } else {
1053 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1054 }
1055 loge("setVoNrEnabled" + ": CommandException: "
1056 + ar.exception);
1057 } else {
1058 loge("setVoNrEnabled" + ": Unknown exception");
1059 }
1060 }
1061 notifyRequester(request);
1062 break;
1063 }
1064
SongFerngWang3ef3e072020-12-21 16:41:52 +08001065 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001066 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001067 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1068 request);
1069 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001070 break;
1071
SongFerngWang3ef3e072020-12-21 16:41:52 +08001072 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001073 ar = (AsyncResult) msg.obj;
1074 request = (MainThreadRequest) ar.userObj;
1075 if (ar.exception == null && ar.result != null) {
1076 request.result = ar.result; // Integer
1077 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301078 // request.result must be set to something non-null
1079 // for the calling thread to unblock
1080 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001081 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001082 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001083 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001084 loge("getAllowedNetworkTypesBitmask: CommandException: "
1085 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001086 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001087 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001088 }
1089 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001090 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001091 break;
1092
SongFerngWang3ef3e072020-12-21 16:41:52 +08001093 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001094 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001095 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1096 request);
1097 Pair<Integer, Long> reasonWithNetworkTypes =
1098 (Pair<Integer, Long>) request.argument;
1099 getPhoneFromRequest(request).setAllowedNetworkTypes(
1100 reasonWithNetworkTypes.first,
1101 reasonWithNetworkTypes.second,
1102 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001103 break;
1104
SongFerngWang3ef3e072020-12-21 16:41:52 +08001105 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1106 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001107 break;
1108
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001109 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1110 request = (MainThreadRequest)msg.obj;
1111 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001112 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001113 break;
1114
1115 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1116 ar = (AsyncResult)msg.obj;
1117 request = (MainThreadRequest)ar.userObj;
1118 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001119 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001120 break;
1121
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001122 case CMD_SET_VOICEMAIL_NUMBER:
1123 request = (MainThreadRequest) msg.obj;
1124 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1125 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001126 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1127 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001128 break;
1129
1130 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1131 handleNullReturnEvent(msg, "setVoicemailNumber");
1132 break;
1133
Stuart Scott54788802015-03-30 13:18:01 -07001134 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1135 request = (MainThreadRequest) msg.obj;
1136 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1137 request);
1138 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1139 break;
1140
1141 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1142 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1143 break;
1144
Shishir Agrawal302c8692015-06-19 13:49:39 -07001145 case CMD_PERFORM_NETWORK_SCAN:
1146 request = (MainThreadRequest) msg.obj;
1147 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1148 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1149 break;
1150
Hall Liu27d24262020-09-18 19:04:59 -07001151 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001152 request = (MainThreadRequest) msg.obj;
1153 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001154 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1155 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1156 request.argument;
1157 int callForwardingReason = args.first;
1158 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001159 break;
Hall Liu27d24262020-09-18 19:04:59 -07001160 }
1161 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001162 ar = (AsyncResult) msg.obj;
1163 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001164 TelephonyManager.CallForwardingInfoCallback callback =
1165 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1166 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001167 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001168 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001169 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1170 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1171 // Service Class is a bit mask per 3gpp 27.007. Search for
1172 // any service for voice call.
1173 if ((callForwardInfo.serviceClass
1174 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001175 callForwardingInfo = new CallForwardingInfo(
1176 callForwardInfo.status
1177 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001178 callForwardInfo.reason,
1179 callForwardInfo.number,
1180 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001181 break;
1182 }
1183 }
1184 // Didn't find a call forward info for voice call.
1185 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001186 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1187 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001188 }
Hall Liu27d24262020-09-18 19:04:59 -07001189 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001190 } else {
1191 if (ar.result == null) {
1192 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1193 }
1194 if (ar.exception != null) {
1195 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1196 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001197 int errorCode = TelephonyManager
1198 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001199 if (ar.exception instanceof CommandException) {
1200 CommandException.Error error =
1201 ((CommandException) (ar.exception)).getCommandError();
1202 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001203 errorCode = TelephonyManager
1204 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001205 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001206 errorCode = TelephonyManager
1207 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001208 }
1209 }
Hall Liu27d24262020-09-18 19:04:59 -07001210 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001211 }
Shuo Qian4a594052020-01-23 11:59:30 -08001212 break;
Hall Liu27d24262020-09-18 19:04:59 -07001213 }
Shuo Qian4a594052020-01-23 11:59:30 -08001214
Hall Liu27d24262020-09-18 19:04:59 -07001215 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001216 request = (MainThreadRequest) msg.obj;
1217 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001218 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001219 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001220 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1221 request.argument).first;
1222 request.phone.setCallForwardingOption(
1223 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001224 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001225 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001226 callForwardingInfoToSet.getReason(),
1227 callForwardingInfoToSet.getNumber(),
1228 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1229 break;
Hall Liu27d24262020-09-18 19:04:59 -07001230 }
Shuo Qian4a594052020-01-23 11:59:30 -08001231
Hall Liu27d24262020-09-18 19:04:59 -07001232 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001233 ar = (AsyncResult) msg.obj;
1234 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001235 Consumer<Integer> callback =
1236 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1237 request.argument).second;
1238 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001239 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001240 int errorCode = TelephonyManager.CallForwardingInfoCallback
1241 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001242 if (ar.exception instanceof CommandException) {
1243 CommandException.Error error =
1244 ((CommandException) (ar.exception)).getCommandError();
1245 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001246 errorCode = TelephonyManager.CallForwardingInfoCallback
1247 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001248 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001249 errorCode = TelephonyManager.CallForwardingInfoCallback
1250 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001251 }
1252 }
1253 callback.accept(errorCode);
1254 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001255 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001256 }
Shuo Qian4a594052020-01-23 11:59:30 -08001257 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 CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001261 request = (MainThreadRequest) msg.obj;
1262 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1263 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1264 break;
Hall Liu27d24262020-09-18 19:04:59 -07001265 }
Shuo Qian4a594052020-01-23 11:59:30 -08001266
Hall Liu27d24262020-09-18 19:04:59 -07001267 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001268 ar = (AsyncResult) msg.obj;
1269 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001270 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001271 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001272 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001273 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001274 // Service Class is a bit mask per 3gpp 27.007.
1275 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001276 if (callForwardResults.length > 1
1277 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001278 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001279 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001280 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1281 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001282 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001283 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001284 }
1285 } else {
1286 if (ar.result == null) {
1287 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1288 }
1289 if (ar.exception != null) {
1290 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1291 }
1292 if (ar.exception instanceof CommandException) {
1293 CommandException.Error error =
1294 ((CommandException) (ar.exception)).getCommandError();
1295 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001296 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001297 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001298 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1299 callWaitingStatus =
1300 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001301 }
1302 }
1303 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001304 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001305 break;
Hall Liu27d24262020-09-18 19:04:59 -07001306 }
Shuo Qian4a594052020-01-23 11:59:30 -08001307
Hall Liu27d24262020-09-18 19:04:59 -07001308 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001309 request = (MainThreadRequest) msg.obj;
1310 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001311 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1312 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001313 break;
Hall Liu27d24262020-09-18 19:04:59 -07001314 }
Shuo Qian4a594052020-01-23 11:59:30 -08001315
Hall Liu27d24262020-09-18 19:04:59 -07001316 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001317 ar = (AsyncResult) msg.obj;
1318 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001319 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1320 Consumer<Integer> callback =
1321 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1322 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001323 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001324 if (ar.exception instanceof CommandException) {
1325 CommandException.Error error =
1326 ((CommandException) (ar.exception)).getCommandError();
1327 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1328 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001329 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1330 callback.accept(
1331 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001332 } else {
1333 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1334 }
1335 } else {
1336 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1337 }
1338 } else {
1339 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1340 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001341 }
Shuo Qian4a594052020-01-23 11:59:30 -08001342 break;
Hall Liu27d24262020-09-18 19:04:59 -07001343 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001344 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1345 ar = (AsyncResult) msg.obj;
1346 request = (MainThreadRequest) ar.userObj;
1347 CellNetworkScanResult cellScanResult;
1348 if (ar.exception == null && ar.result != null) {
1349 cellScanResult = new CellNetworkScanResult(
1350 CellNetworkScanResult.STATUS_SUCCESS,
1351 (List<OperatorInfo>) ar.result);
1352 } else {
1353 if (ar.result == null) {
1354 loge("getCellNetworkScanResults: Empty response");
1355 }
1356 if (ar.exception != null) {
1357 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1358 }
1359 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1360 if (ar.exception instanceof CommandException) {
1361 CommandException.Error error =
1362 ((CommandException) (ar.exception)).getCommandError();
1363 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1364 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1365 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1366 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1367 }
1368 }
1369 cellScanResult = new CellNetworkScanResult(errorCode, null);
1370 }
1371 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001372 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001373 break;
1374
1375 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1376 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001377 ManualNetworkSelectionArgument selArg =
1378 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001379 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1380 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001381 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1382 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001383 break;
1384
1385 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001386 ar = (AsyncResult) msg.obj;
1387 request = (MainThreadRequest) ar.userObj;
1388 if (ar.exception == null) {
1389 request.result = true;
1390 } else {
1391 request.result = false;
1392 loge("setNetworkSelectionModeManual " + ar.exception);
1393 }
1394 notifyRequester(request);
1395 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001396 break;
1397
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001398 case CMD_GET_MODEM_ACTIVITY_INFO:
1399 request = (MainThreadRequest) msg.obj;
1400 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001401 if (defaultPhone != null) {
1402 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001403 } else {
1404 ResultReceiver result = (ResultReceiver) request.argument;
1405 Bundle bundle = new Bundle();
1406 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001407 new ModemActivityInfo(0, 0, 0,
1408 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001409 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001410 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001411 break;
1412
Hall Liud0f208c2020-10-14 16:54:44 -07001413 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001414 ar = (AsyncResult) msg.obj;
1415 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001416 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001417 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001418 if (mLastModemActivityInfo == null) {
1419 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1420 mLastModemActivitySpecificInfo[0] =
1421 new ActivityStatsTechSpecificInfo(
1422 0,
1423 0,
1424 new int[ModemActivityInfo.getNumTxPowerLevels()],
1425 0);
1426 mLastModemActivityInfo =
1427 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1428 }
1429
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001430 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001431 // Update the last modem activity info and the result of the request.
1432 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1433 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001434 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001435 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001436 mLastModemActivityInfo =
1437 new ModemActivityInfo(
1438 mLastModemActivityInfo.getTimestampMillis(),
1439 mLastModemActivityInfo.getSleepTimeMillis(),
1440 mLastModemActivityInfo.getIdleTimeMillis(),
1441 mLastModemActivitySpecificInfo);
1442
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001443 } else {
1444 if (ar.result == null) {
1445 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001446 error = TelephonyManager.ModemActivityInfoException
1447 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001448 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001449 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001450 error = TelephonyManager.ModemActivityInfoException
1451 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001452 } else {
1453 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001454 error = TelephonyManager.ModemActivityInfoException
1455 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001456 }
1457 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001458 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001459 if (mLastModemActivityInfo != null) {
1460 bundle.putParcelable(
1461 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1462 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001463 } else {
1464 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1465 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001466 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001467 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001468 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001469 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001470
Meng Wang1a7c35a2016-05-05 20:56:15 -07001471 case CMD_SET_ALLOWED_CARRIERS:
1472 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001473 CarrierRestrictionRules argument =
1474 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001475 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001476 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001477 break;
1478
1479 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1480 ar = (AsyncResult) msg.obj;
1481 request = (MainThreadRequest) ar.userObj;
1482 if (ar.exception == null && ar.result != null) {
1483 request.result = ar.result;
1484 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001485 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1486 if (ar.exception instanceof CommandException) {
1487 loge("setAllowedCarriers: CommandException: " + ar.exception);
1488 CommandException.Error error =
1489 ((CommandException) (ar.exception)).getCommandError();
1490 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1491 request.result =
1492 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1493 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001494 } else {
1495 loge("setAllowedCarriers: Unknown exception");
1496 }
1497 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001498 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001499 break;
1500
1501 case CMD_GET_ALLOWED_CARRIERS:
1502 request = (MainThreadRequest) msg.obj;
1503 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001504 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001505 break;
1506
1507 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1508 ar = (AsyncResult) msg.obj;
1509 request = (MainThreadRequest) ar.userObj;
1510 if (ar.exception == null && ar.result != null) {
1511 request.result = ar.result;
1512 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001513 request.result = new IllegalStateException(
1514 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001515 if (ar.result == null) {
1516 loge("getAllowedCarriers: Empty response");
1517 } else if (ar.exception instanceof CommandException) {
1518 loge("getAllowedCarriers: CommandException: " +
1519 ar.exception);
1520 } else {
1521 loge("getAllowedCarriers: Unknown exception");
1522 }
1523 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001524 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001525 break;
1526
Nathan Haroldb3014052017-01-25 15:57:32 -08001527 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1528 ar = (AsyncResult) msg.obj;
1529 request = (MainThreadRequest) ar.userObj;
1530 if (ar.exception == null && ar.result != null) {
1531 request.result = ar.result;
1532 } else {
1533 request.result = new IllegalArgumentException(
1534 "Failed to retrieve Forbidden Plmns");
1535 if (ar.result == null) {
1536 loge("getForbiddenPlmns: Empty response");
1537 } else {
1538 loge("getForbiddenPlmns: Unknown exception");
1539 }
1540 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001541 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001542 break;
1543
1544 case CMD_GET_FORBIDDEN_PLMNS:
1545 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001546 uiccPort = getUiccPortFromRequest(request);
1547 if (uiccPort == null) {
1548 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001549 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001550 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001551 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001552 break;
1553 }
1554 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001555 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001556 if (uiccApp == null) {
1557 loge("getForbiddenPlmns() no app with specified type -- "
1558 + appType);
1559 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001560 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001561 break;
1562 } else {
1563 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1564 + " specified type -- " + appType);
1565 }
1566 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1567 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1568 onCompleted);
1569 break;
1570
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001571 case CMD_SWITCH_SLOTS:
1572 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001573 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001574 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001575 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001576 break;
1577
1578 case EVENT_SWITCH_SLOTS_DONE:
1579 ar = (AsyncResult) msg.obj;
1580 request = (MainThreadRequest) ar.userObj;
1581 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001582 notifyRequester(request);
1583 break;
1584 case CMD_GET_NETWORK_SELECTION_MODE:
1585 request = (MainThreadRequest) msg.obj;
1586 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1587 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1588 break;
1589
1590 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1591 ar = (AsyncResult) msg.obj;
1592 request = (MainThreadRequest) ar.userObj;
1593 if (ar.exception != null) {
1594 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1595 } else {
1596 int mode = ((int[]) ar.result)[0];
1597 if (mode == 0) {
1598 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1599 } else {
1600 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1601 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001602 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001603 notifyRequester(request);
1604 break;
1605 case CMD_GET_CDMA_ROAMING_MODE:
1606 request = (MainThreadRequest) msg.obj;
1607 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1608 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1609 break;
1610 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1611 ar = (AsyncResult) msg.obj;
1612 request = (MainThreadRequest) ar.userObj;
1613 if (ar.exception != null) {
1614 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1615 } else {
1616 request.result = ((int[]) ar.result)[0];
1617 }
1618 notifyRequester(request);
1619 break;
1620 case CMD_SET_CDMA_ROAMING_MODE:
1621 request = (MainThreadRequest) msg.obj;
1622 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1623 int mode = (int) request.argument;
1624 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1625 break;
1626 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1627 ar = (AsyncResult) msg.obj;
1628 request = (MainThreadRequest) ar.userObj;
1629 request.result = ar.exception == null;
1630 notifyRequester(request);
1631 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001632 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1633 request = (MainThreadRequest) msg.obj;
1634 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1635 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1636 break;
1637 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1638 ar = (AsyncResult) msg.obj;
1639 request = (MainThreadRequest) ar.userObj;
1640 if (ar.exception != null) {
1641 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1642 } else {
1643 request.result = ((int[]) ar.result)[0];
1644 }
1645 notifyRequester(request);
1646 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001647 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1648 request = (MainThreadRequest) msg.obj;
1649 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1650 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001651 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1652 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001653 break;
1654 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1655 ar = (AsyncResult) msg.obj;
1656 request = (MainThreadRequest) ar.userObj;
1657 request.result = ar.exception == null;
1658 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001659 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001660 case CMD_GET_ALL_CELL_INFO:
1661 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001662 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001663 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001664 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001665 case EVENT_GET_ALL_CELL_INFO_DONE:
1666 ar = (AsyncResult) msg.obj;
1667 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001668 // If a timeout occurs, the response will be null
1669 request.result = (ar.exception == null && ar.result != null)
1670 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001671 synchronized (request) {
1672 request.notifyAll();
1673 }
1674 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001675 case CMD_REQUEST_CELL_INFO_UPDATE:
1676 request = (MainThreadRequest) msg.obj;
1677 request.phone.requestCellInfoUpdate(request.workSource,
1678 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1679 break;
1680 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1681 ar = (AsyncResult) msg.obj;
1682 request = (MainThreadRequest) ar.userObj;
1683 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1684 try {
1685 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001686 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001687 cb.onError(
1688 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1689 ar.exception.getClass().getName(),
1690 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001691 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001692 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001693 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001694 } else {
1695 // use the result as returned
1696 cb.onCellInfo((List<CellInfo>) ar.result);
1697 }
1698 } catch (RemoteException re) {
1699 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1700 }
1701 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001702 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001703 request = (MainThreadRequest) msg.obj;
1704 WorkSource ws = (WorkSource) request.argument;
1705 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001706 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001707 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001708 }
1709 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001710 ar = (AsyncResult) msg.obj;
1711 request = (MainThreadRequest) ar.userObj;
1712 if (ar.exception == null) {
1713 request.result = ar.result;
1714 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001715 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001716 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001717 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001718 }
1719
1720 synchronized (request) {
1721 request.notifyAll();
1722 }
1723 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001724 }
chen xu6dac5ab2018-10-26 17:39:23 -07001725 case CMD_MODEM_REBOOT:
1726 request = (MainThreadRequest) msg.obj;
1727 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001728 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001729 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001730 case EVENT_CMD_MODEM_REBOOT_DONE:
1731 handleNullReturnEvent(msg, "rebootModem");
1732 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001733 case CMD_REQUEST_ENABLE_MODEM:
1734 request = (MainThreadRequest) msg.obj;
1735 boolean enable = (boolean) request.argument;
1736 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001737 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001738 PhoneConfigurationManager.getInstance()
1739 .enablePhone(request.phone, enable, onCompleted);
1740 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001741 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001742 ar = (AsyncResult) msg.obj;
1743 request = (MainThreadRequest) ar.userObj;
1744 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001745 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001746 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001747 if ((boolean) request.result) {
1748 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1749 updateModemStateMetrics();
1750 } else {
1751 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1752 + ar.exception);
1753 }
1754 notifyRequester(request);
1755 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001756 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001757 case CMD_GET_MODEM_STATUS:
1758 request = (MainThreadRequest) msg.obj;
1759 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1760 PhoneConfigurationManager.getInstance()
1761 .getPhoneStatusFromModem(request.phone, onCompleted);
1762 break;
1763 case EVENT_GET_MODEM_STATUS_DONE:
1764 ar = (AsyncResult) msg.obj;
1765 request = (MainThreadRequest) ar.userObj;
1766 int id = request.phone.getPhoneId();
1767 if (ar.exception == null && ar.result != null) {
1768 request.result = ar.result;
1769 //update the cache as modem status has changed
1770 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1771 (boolean) request.result);
1772 } else {
1773 // Return true if modem status cannot be retrieved. For most cases,
1774 // modem status is on. And for older version modems, GET_MODEM_STATUS
1775 // and disable modem are not supported. Modem is always on.
1776 // TODO: this should be fixed in R to support a third
1777 // status UNKNOWN b/131631629
1778 request.result = true;
1779 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1780 + ar.exception);
1781 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001782 notifyRequester(request);
1783 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001784 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1785 request = (MainThreadRequest) msg.obj;
1786 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1787 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1788 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1789 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1790 break;
1791 }
1792 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1793 ar = (AsyncResult) msg.obj;
1794 request = (MainThreadRequest) ar.userObj;
1795 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1796 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1797 args.second.accept(ar.exception == null);
1798 notifyRequester(request);
1799 break;
1800 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001801 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1802 request = (MainThreadRequest) msg.obj;
1803 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1804 Phone phone = getPhoneFromRequest(request);
1805 if (phone != null) {
1806 phone.getSystemSelectionChannels(onCompleted);
1807 } else {
1808 loge("getSystemSelectionChannels: No phone object");
1809 request.result = new ArrayList<RadioAccessSpecifier>();
1810 notifyRequester(request);
1811 }
1812 break;
1813 }
1814 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1815 ar = (AsyncResult) msg.obj;
1816 request = (MainThreadRequest) ar.userObj;
1817 if (ar.exception == null && ar.result != null) {
1818 request.result = ar.result;
1819 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001820 request.result = new IllegalStateException(
1821 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001822 if (ar.result == null) {
1823 loge("getSystemSelectionChannels: Empty response");
1824 } else {
1825 loge("getSystemSelectionChannels: Unknown exception");
1826 }
1827 }
1828 notifyRequester(request);
1829 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001830 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1831 ar = (AsyncResult) msg.obj;
1832 request = (MainThreadRequest) ar.userObj;
1833 if (ar.exception == null && ar.result != null) {
1834 request.result = ar.result;
1835 } else {
1836 request.result = -1;
1837 loge("Failed to set Forbidden Plmns");
1838 if (ar.result == null) {
1839 loge("setForbidenPlmns: Empty response");
1840 } else if (ar.exception != null) {
1841 loge("setForbiddenPlmns: Exception: " + ar.exception);
1842 request.result = -1;
1843 } else {
1844 loge("setForbiddenPlmns: Unknown exception");
1845 }
1846 }
1847 notifyRequester(request);
1848 break;
1849 case CMD_SET_FORBIDDEN_PLMNS:
1850 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001851 uiccPort = getUiccPortFromRequest(request);
1852 if (uiccPort == null) {
1853 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001854 request.result = -1;
1855 notifyRequester(request);
1856 break;
1857 }
1858 Pair<Integer, List<String>> setFplmnsArgs =
1859 (Pair<Integer, List<String>>) request.argument;
1860 appType = setFplmnsArgs.first;
1861 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001862 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001863 if (uiccApp == null) {
1864 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1865 request.result = -1;
1866 loge("Failed to get UICC App");
1867 notifyRequester(request);
1868 } else {
1869 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1870 ((SIMRecords) uiccApp.getIccRecords())
1871 .setForbiddenPlmns(onCompleted, fplmns);
1872 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001873 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001874 case CMD_ERASE_MODEM_CONFIG:
1875 request = (MainThreadRequest) msg.obj;
1876 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1877 defaultPhone.eraseModemConfig(onCompleted);
1878 break;
1879 case EVENT_ERASE_MODEM_CONFIG_DONE:
1880 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001881 break;
zoey chene02881a2019-12-30 16:11:23 +08001882
Kai Shif70f46f2021-03-03 13:59:46 -08001883 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1884 request = (MainThreadRequest) msg.obj;
1885 request.result = defaultPhone.eraseDataInSharedPreferences();
1886 notifyRequester(request);
1887 break;
1888
zoey chene02881a2019-12-30 16:11:23 +08001889 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1890 request = (MainThreadRequest) msg.obj;
1891 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1892 Pair<String, String> changed = (Pair<String, String>) request.argument;
1893 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1894 changed.first, changed.second, onCompleted);
1895 break;
1896 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1897 ar = (AsyncResult) msg.obj;
1898 request = (MainThreadRequest) ar.userObj;
1899 if (ar.exception == null) {
1900 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001901 // If the operation is successful, update the PIN storage
1902 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1903 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001904 UiccController.getInstance().getPinStorage()
1905 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001906 } else {
1907 request.result = msg.arg1;
1908 }
1909 notifyRequester(request);
1910 break;
1911
Michele Berionne5e411512020-11-13 02:36:59 +00001912 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001913 request = (MainThreadRequest) msg.obj;
1914 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1915 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1916 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1917 enabled.first, enabled.second, onCompleted);
1918 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001919 }
zoey chene02881a2019-12-30 16:11:23 +08001920 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1921 ar = (AsyncResult) msg.obj;
1922 request = (MainThreadRequest) ar.userObj;
1923 if (ar.exception == null) {
1924 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001925 // If the operation is successful, update the PIN storage
1926 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1927 int phoneId = getPhoneFromRequest(request).getPhoneId();
1928 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001929 UiccController.getInstance().getPinStorage()
1930 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001931 } else {
1932 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1933 }
zoey chene02881a2019-12-30 16:11:23 +08001934 } else {
1935 request.result = msg.arg1;
1936 }
Michele Berionne5e411512020-11-13 02:36:59 +00001937
1938
zoey chene02881a2019-12-30 16:11:23 +08001939 notifyRequester(request);
1940 break;
1941
Peter Wangdafb9ac2020-01-15 14:13:38 -08001942 case MSG_NOTIFY_USER_ACTIVITY:
1943 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001944 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001945 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1946 getDefaultPhone().getContext().sendBroadcastAsUser(
1947 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1948 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001949
1950 case CMD_SET_DATA_THROTTLING: {
1951 request = (MainThreadRequest) msg.obj;
1952 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1953 DataThrottlingRequest dataThrottlingRequest =
1954 (DataThrottlingRequest) request.argument;
1955 Phone phone = getPhoneFromRequest(request);
1956 if (phone != null) {
1957 phone.setDataThrottling(onCompleted,
1958 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1959 dataThrottlingRequest.getCompletionDurationMillis());
1960 } else {
1961 loge("setDataThrottling: No phone object");
1962 request.result =
1963 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1964 notifyRequester(request);
1965 }
1966
1967 break;
1968 }
1969 case EVENT_SET_DATA_THROTTLING_DONE:
1970 ar = (AsyncResult) msg.obj;
1971 request = (MainThreadRequest) ar.userObj;
1972
1973 if (ar.exception == null) {
1974 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1975 } else if (ar.exception instanceof CommandException) {
1976 loge("setDataThrottling: CommandException: " + ar.exception);
1977 CommandException.Error error =
1978 ((CommandException) (ar.exception)).getCommandError();
1979
1980 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1981 request.result = TelephonyManager
1982 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1983 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1984 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001985 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1986 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001987 } else {
1988 request.result =
1989 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1990 }
1991 } else {
1992 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1993 }
1994 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1995 notifyRequester(request);
1996 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001997
1998 case CMD_SET_SIM_POWER: {
1999 request = (MainThreadRequest) msg.obj;
2000 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2001 request = (MainThreadRequest) msg.obj;
2002 int stateToSet =
2003 ((Pair<Integer, IIntegerConsumer>)
2004 request.argument).first;
2005 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2006 break;
2007 }
2008 case EVENT_SET_SIM_POWER_DONE: {
2009 ar = (AsyncResult) msg.obj;
2010 request = (MainThreadRequest) ar.userObj;
2011 IIntegerConsumer callback =
2012 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2013 if (ar.exception != null) {
2014 loge("setSimPower exception: " + ar.exception);
2015 int errorCode = TelephonyManager.CallForwardingInfoCallback
2016 .RESULT_ERROR_UNKNOWN;
2017 if (ar.exception instanceof CommandException) {
2018 CommandException.Error error =
2019 ((CommandException) (ar.exception)).getCommandError();
2020 if (error == CommandException.Error.SIM_ERR) {
2021 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2022 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2023 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2024 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2025 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2026 } else {
2027 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2028 }
2029 }
2030 try {
2031 callback.accept(errorCode);
2032 } catch (RemoteException e) {
2033 // Ignore if the remote process is no longer available to call back.
2034 Log.w(LOG_TAG, "setSimPower: callback not available.");
2035 }
2036 } else {
2037 try {
2038 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2039 } catch (RemoteException e) {
2040 // Ignore if the remote process is no longer available to call back.
2041 Log.w(LOG_TAG, "setSimPower: callback not available.");
2042 }
2043 }
2044 break;
2045 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002046 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2047 request = (MainThreadRequest) msg.obj;
2048
2049 final Phone phone = getPhoneFromRequest(request);
2050 if (phone == null || phone.getServiceStateTracker() == null) {
2051 request.result = new IllegalStateException("Phone or SST is null");
2052 notifyRequester(request);
2053 break;
2054 }
2055
2056 Pair<Integer, SignalStrengthUpdateRequest> pair =
2057 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2058 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2059 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002060 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002061 request.subId, pair.first /*callingUid*/,
2062 pair.second /*request*/, onCompleted);
2063 break;
2064 }
2065 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2066 ar = (AsyncResult) msg.obj;
2067 request = (MainThreadRequest) ar.userObj;
2068 // request.result will be the exception of ar if present, true otherwise.
2069 // Be cautious not to leave result null which will wait() forever
2070 request.result = ar.exception != null ? ar.exception : true;
2071 notifyRequester(request);
2072 break;
2073 }
2074 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2075 request = (MainThreadRequest) msg.obj;
2076
2077 Phone phone = getPhoneFromRequest(request);
2078 if (phone == null || phone.getServiceStateTracker() == null) {
2079 request.result = new IllegalStateException("Phone or SST is null");
2080 notifyRequester(request);
2081 break;
2082 }
2083
2084 Pair<Integer, SignalStrengthUpdateRequest> pair =
2085 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2086 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2087 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002088 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002089 request.subId, pair.first /*callingUid*/,
2090 pair.second /*request*/, onCompleted);
2091 break;
2092 }
2093 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2094 ar = (AsyncResult) msg.obj;
2095 request = (MainThreadRequest) ar.userObj;
2096 request.result = ar.exception != null ? ar.exception : true;
2097 notifyRequester(request);
2098 break;
2099 }
Jordan Liu109698e2020-11-24 14:50:34 -08002100
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002101 case CMD_GET_SLICING_CONFIG: {
2102 request = (MainThreadRequest) msg.obj;
2103 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2104 request.phone.getSlicingConfig(onCompleted);
2105 break;
2106 }
2107 case EVENT_GET_SLICING_CONFIG_DONE: {
2108 ar = (AsyncResult) msg.obj;
2109 request = (MainThreadRequest) ar.userObj;
2110 ResultReceiver result = (ResultReceiver) request.argument;
2111
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002112 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002113 Bundle bundle = new Bundle();
2114 int resultCode = 0;
2115 if (ar.exception != null) {
2116 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2117 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002118 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002119 } else if (ar.result == null) {
2120 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002121 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002122 } else {
2123 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002124 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2125 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002126 }
2127
2128 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002129 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002130 }
2131 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2132 result.send(resultCode, bundle);
2133 notifyRequester(request);
2134 break;
2135 }
2136
Michele Berionne5e411512020-11-13 02:36:59 +00002137 case CMD_PREPARE_UNATTENDED_REBOOT:
2138 request = (MainThreadRequest) msg.obj;
2139 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002140 UiccController.getInstance().getPinStorage()
2141 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002142 notifyRequester(request);
2143 break;
2144
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002145 default:
2146 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2147 break;
2148 }
2149 }
Jake Hambye994d462014-02-03 13:10:13 -08002150
Pengquan Menga1bb6272018-09-06 09:59:22 -07002151 private void notifyRequester(MainThreadRequest request) {
2152 synchronized (request) {
2153 request.notifyAll();
2154 }
2155 }
2156
Jake Hambye994d462014-02-03 13:10:13 -08002157 private void handleNullReturnEvent(Message msg, String command) {
2158 AsyncResult ar = (AsyncResult) msg.obj;
2159 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2160 if (ar.exception == null) {
2161 request.result = true;
2162 } else {
2163 request.result = false;
2164 if (ar.exception instanceof CommandException) {
2165 loge(command + ": CommandException: " + ar.exception);
2166 } else {
2167 loge(command + ": Unknown exception");
2168 }
2169 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002170 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 }
2173
2174 /**
2175 * Posts the specified command to be executed on the main thread,
2176 * waits for the request to complete, and returns the result.
2177 * @see #sendRequestAsync
2178 */
2179 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002180 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2181 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002182 }
2183
2184 /**
2185 * Posts the specified command to be executed on the main thread,
2186 * waits for the request to complete, and returns the result.
2187 * @see #sendRequestAsync
2188 */
2189 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2190 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002191 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002192 }
2193
2194 /**
2195 * Posts the specified command to be executed on the main thread,
2196 * waits for the request to complete, and returns the result.
2197 * @see #sendRequestAsync
2198 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002199 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002200 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2201 }
2202
2203 /**
2204 * Posts the specified command to be executed on the main thread,
2205 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2206 * if not timeout or null otherwise.
2207 * @see #sendRequestAsync
2208 */
2209 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2210 long timeoutInMs) {
2211 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002212 }
2213
2214 /**
2215 * Posts the specified command to be executed on the main thread,
2216 * waits for the request to complete, and returns the result.
2217 * @see #sendRequestAsync
2218 */
Nathan Harold92bed182018-10-12 18:16:49 -07002219 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002220 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002221 }
2222
2223 /**
2224 * Posts the specified command to be executed on the main thread,
2225 * waits for the request to complete, and returns the result.
2226 * @see #sendRequestAsync
2227 */
2228 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002229 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2230 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002231 }
2232
2233 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002234 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2235 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2236 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002237 * @see #sendRequestAsync
2238 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002239 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2240 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2242 throw new RuntimeException("This method will deadlock if called from the main thread.");
2243 }
2244
Nathan Harold92bed182018-10-12 18:16:49 -07002245 MainThreadRequest request = null;
2246 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2247 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2248 } else if (phone != null) {
2249 request = new MainThreadRequest(argument, phone, workSource);
2250 } else {
2251 request = new MainThreadRequest(argument, subId, workSource);
2252 }
2253
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 Message msg = mMainThreadHandler.obtainMessage(command, request);
2255 msg.sendToTarget();
2256
Rambo Wang0f050d82021-02-12 11:43:36 -08002257
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002259 if (timeoutInMs >= 0) {
2260 // Wait for at least timeoutInMs before returning null request result
2261 long now = SystemClock.elapsedRealtime();
2262 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002263 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002264 try {
2265 request.wait(deadline - now);
2266 } catch (InterruptedException e) {
2267 // Do nothing, go back and check if request is completed or timeout
2268 } finally {
2269 now = SystemClock.elapsedRealtime();
2270 }
2271 }
2272 } else {
2273 // Wait for the request to complete
2274 while (request.result == null) {
2275 try {
2276 request.wait();
2277 } catch (InterruptedException e) {
2278 // Do nothing, go back and wait until the request is complete
2279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 }
2281 }
2282 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002283 if (request.result == null) {
2284 Log.wtf(LOG_TAG,
2285 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 return request.result;
2288 }
2289
2290 /**
2291 * Asynchronous ("fire and forget") version of sendRequest():
2292 * Posts the specified command to be executed on the main thread, and
2293 * returns immediately.
2294 * @see #sendRequest
2295 */
2296 private void sendRequestAsync(int command) {
2297 mMainThreadHandler.sendEmptyMessage(command);
2298 }
2299
2300 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002301 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002302 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002303 */
2304 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002305 sendRequestAsync(command, argument, null, null);
2306 }
2307
2308 /**
2309 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2310 * @see {@link #sendRequest(int,Object)}
2311 */
2312 private void sendRequestAsync(
2313 int command, Object argument, Phone phone, WorkSource workSource) {
2314 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002315 Message msg = mMainThreadHandler.obtainMessage(command, request);
2316 msg.sendToTarget();
2317 }
2318
2319 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 * Initialize the singleton PhoneInterfaceManager instance.
2321 * This is only done once, at startup, from PhoneApp.onCreate().
2322 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002323 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 synchronized (PhoneInterfaceManager.class) {
2325 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002326 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 } else {
2328 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2329 }
2330 return sInstance;
2331 }
2332 }
2333
2334 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002335 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002338 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002339 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002341 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002343 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002344 mTelephonySharedPreferences =
2345 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002346 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002347 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002348 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002349 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002350 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 publish();
2352 }
2353
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002354 private Phone getDefaultPhone() {
2355 Phone thePhone = getPhone(getDefaultSubscription());
2356 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2357 }
2358
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 private void publish() {
2360 if (DBG) log("publish: " + this);
2361
Peter Wangc035ce42020-01-08 21:00:22 -08002362 TelephonyFrameworkInitializer
2363 .getTelephonyServiceManager()
2364 .getTelephonyServiceRegisterer()
2365 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 }
2367
Stuart Scott584921c2015-01-15 17:10:34 -08002368 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002369 if (request.phone != null) {
2370 return request.phone;
2371 } else {
2372 return getPhoneFromSubId(request.subId);
2373 }
2374 }
2375
2376 private Phone getPhoneFromSubId(int subId) {
2377 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2378 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002379 }
2380
Rambo Wange53e07d2022-05-10 13:01:13 -07002381 @Nullable
2382 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002383 Phone phone = getPhoneFromRequest(request);
2384 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002385 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002386 }
2387
Wink Saville36469e72014-06-11 15:17:00 -07002388 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002389 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002390 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002391 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392
Kai Shif70f46f2021-03-03 13:59:46 -08002393 private void sendEraseModemConfig(@NonNull Phone phone) {
2394 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2395 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2396 }
2397
2398 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2399 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2400 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002401 }
2402
Peter Wang44b186e2020-01-13 23:33:09 -08002403 private boolean isImsAvailableOnDevice() {
2404 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2405 if (pm == null) {
2406 // For some reason package manger is not available.. This will fail internally anyway,
2407 // so do not throw error and allow.
2408 return true;
2409 }
2410 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2411 }
2412
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002414 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002415 }
2416
Wink Savilleb564aae2014-10-23 10:18:09 -07002417 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 if (DBG) log("dial: " + number);
2419 // No permission check needed here: This is just a wrapper around the
2420 // ACTION_DIAL intent, which is available to any app since it puts up
2421 // the UI before it does anything.
2422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002423 final long identity = Binder.clearCallingIdentity();
2424 try {
2425 String url = createTelUrl(number);
2426 if (url == null) {
2427 return;
2428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002430 // PENDING: should we just silently fail if phone is offhook or ringing?
2431 PhoneConstants.State state = mCM.getState(subId);
2432 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2433 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2434 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2435 mApp.startActivity(intent);
2436 }
2437 } finally {
2438 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 }
2440 }
2441
2442 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002443 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002444 }
2445
Wink Savilleb564aae2014-10-23 10:18:09 -07002446 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 if (DBG) log("call: " + number);
2448
2449 // This is just a wrapper around the ACTION_CALL intent, but we still
2450 // need to do a permission check since we're calling startActivity()
2451 // from the context of the phone app.
2452 enforceCallPermission();
2453
Jordan Liu1617b712019-07-10 15:06:26 -07002454 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 != AppOpsManager.MODE_ALLOWED) {
2456 return;
2457 }
2458
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 final long identity = Binder.clearCallingIdentity();
2460 try {
2461 String url = createTelUrl(number);
2462 if (url == null) {
2463 return;
2464 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002466 boolean isValid = false;
2467 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2468 if (slist != null) {
2469 for (SubscriptionInfo subInfoRecord : slist) {
2470 if (subInfoRecord.getSubscriptionId() == subId) {
2471 isValid = true;
2472 break;
2473 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002474 }
Wink Saville08874612014-08-31 19:19:58 -07002475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002476 if (!isValid) {
2477 return;
2478 }
Wink Saville08874612014-08-31 19:19:58 -07002479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2481 intent.putExtra(SUBSCRIPTION_KEY, subId);
2482 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2483 mApp.startActivity(intent);
2484 } finally {
2485 Binder.restoreCallingIdentity(identity);
2486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 }
2488
Wink Savilleb564aae2014-10-23 10:18:09 -07002489 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002490 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002491 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2492 }
2493
Wink Savilleb564aae2014-10-23 10:18:09 -07002494 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002495 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002496 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2497 }
2498
Wink Savilleb564aae2014-10-23 10:18:09 -07002499 public int[] supplyPinReportResultForSubscriber(int subId, 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 checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 checkSimPin.start();
2507 return checkSimPin.unlockSim(null, pin);
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
2510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 }
2512
Wink Savilleb564aae2014-10-23 10:18:09 -07002513 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002514 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002515
2516 final long identity = Binder.clearCallingIdentity();
2517 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002518 Phone phone = getPhone(subId);
2519 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002520 checkSimPuk.start();
2521 return checkSimPuk.unlockSim(puk, pin);
2522 } finally {
2523 Binder.restoreCallingIdentity(identity);
2524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525 }
2526
2527 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002528 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529 * a synchronous one.
2530 */
2531 private static class UnlockSim extends Thread {
2532
2533 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002534 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002535
2536 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002537 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2538 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539
2540 // For replies from SimCard interface
2541 private Handler mHandler;
2542
2543 // For async handler to identify request type
2544 private static final int SUPPLY_PIN_COMPLETE = 100;
2545
Michele Berionne5e411512020-11-13 02:36:59 +00002546 UnlockSim(int phoneId, IccCard simCard) {
2547 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002548 mSimCard = simCard;
2549 }
2550
2551 @Override
2552 public void run() {
2553 Looper.prepare();
2554 synchronized (UnlockSim.this) {
2555 mHandler = new Handler() {
2556 @Override
2557 public void handleMessage(Message msg) {
2558 AsyncResult ar = (AsyncResult) msg.obj;
2559 switch (msg.what) {
2560 case SUPPLY_PIN_COMPLETE:
2561 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2562 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002563 mRetryCount = msg.arg1;
2564 if (ar.exception != null) {
2565 if (ar.exception instanceof CommandException &&
2566 ((CommandException)(ar.exception)).getCommandError()
2567 == CommandException.Error.PASSWORD_INCORRECT) {
2568 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002569 } //When UiccCardApp dispose,handle message and return exception
2570 else if (ar.exception instanceof CommandException &&
2571 ((CommandException) (ar.exception)).getCommandError()
2572 == CommandException.Error.ABORTED) {
2573 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002574 } else {
2575 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2576 }
2577 } else {
2578 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2579 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002580 mDone = true;
2581 UnlockSim.this.notifyAll();
2582 }
2583 break;
2584 }
2585 }
2586 };
2587 UnlockSim.this.notifyAll();
2588 }
2589 Looper.loop();
2590 }
2591
2592 /*
2593 * Use PIN or PUK to unlock SIM card
2594 *
2595 * If PUK is null, unlock SIM card with PIN
2596 *
2597 * If PUK is not null, unlock SIM card with PUK and set PIN code
2598 */
Wink Saville9de0f752013-10-22 19:04:03 -07002599 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002600
2601 while (mHandler == null) {
2602 try {
2603 wait();
2604 } catch (InterruptedException e) {
2605 Thread.currentThread().interrupt();
2606 }
2607 }
2608 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2609
2610 if (puk == null) {
2611 mSimCard.supplyPin(pin, callback);
2612 } else {
2613 mSimCard.supplyPuk(puk, pin, callback);
2614 }
2615
2616 while (!mDone) {
2617 try {
2618 Log.d(LOG_TAG, "wait for done");
2619 wait();
2620 } catch (InterruptedException e) {
2621 // Restore the interrupted status
2622 Thread.currentThread().interrupt();
2623 }
2624 }
2625 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002626 int[] resultArray = new int[2];
2627 resultArray[0] = mResult;
2628 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002629
2630 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002631 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002632 }
2633
Wink Saville9de0f752013-10-22 19:04:03 -07002634 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002635 }
2636 }
2637
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002638 /**
2639 * This method has been removed due to privacy and stability concerns.
2640 */
2641 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002642 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002643 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2644 return;
Wink Saville36469e72014-06-11 15:17:00 -07002645 }
2646
Nathan Harold1f889d82020-06-04 17:05:26 -07002647 @Override
2648 public void updateServiceLocationWithPackageName(String callingPackage) {
2649 mApp.getSystemService(AppOpsManager.class)
2650 .checkPackage(Binder.getCallingUid(), callingPackage);
2651
Nathan Haroldf096d982020-11-18 17:18:06 -08002652 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002653 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2654 // Callers targeting S have no business invoking this method.
2655 return;
2656 }
2657
2658 LocationAccessPolicy.LocationPermissionResult locationResult =
2659 LocationAccessPolicy.checkLocationPermission(mApp,
2660 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2661 .setCallingPackage(callingPackage)
2662 .setCallingFeatureId(null)
2663 .setCallingPid(Binder.getCallingPid())
2664 .setCallingUid(Binder.getCallingUid())
2665 .setMethod("updateServiceLocation")
2666 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2667 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2668 .build());
2669 // Apps that lack location permission have no business calling this method;
2670 // however, because no permission was declared in the public API, denials must
2671 // all be "soft".
2672 switch (locationResult) {
2673 case DENIED_HARD: /* fall through */
2674 case DENIED_SOFT:
2675 return;
2676 }
2677
2678 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679 final long identity = Binder.clearCallingIdentity();
2680 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002681 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002683 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684 }
2685 } finally {
2686 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002687 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 }
2689
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002690 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002691 @Override
2692 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002693 return isRadioOnWithFeature(callingPackage, null);
2694 }
2695
2696
2697 @Override
2698 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2699 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2700 callingFeatureId);
2701 }
2702
2703 @Deprecated
2704 @Override
2705 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2706 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002707 }
2708
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002709 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002710 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2711 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002713 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002714 return false;
2715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716
2717 final long identity = Binder.clearCallingIdentity();
2718 try {
2719 return isRadioOnForSubscriber(subId);
2720 } finally {
2721 Binder.restoreCallingIdentity(identity);
2722 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002723 }
2724
2725 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 final long identity = Binder.clearCallingIdentity();
2727 try {
2728 final Phone phone = getPhone(subId);
2729 if (phone != null) {
2730 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2731 } else {
2732 return false;
2733 }
2734 } finally {
2735 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737 }
2738
2739 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002740 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 }
Wink Saville36469e72014-06-11 15:17:00 -07002742
Wink Savilleb564aae2014-10-23 10:18:09 -07002743 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002745
2746 final long identity = Binder.clearCallingIdentity();
2747 try {
2748 final Phone phone = getPhone(subId);
2749 if (phone != null) {
2750 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2751 }
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002754 }
Wink Saville36469e72014-06-11 15:17:00 -07002755 }
2756
2757 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002758 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002759 }
2760
Wink Savilleb564aae2014-10-23 10:18:09 -07002761 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763
2764 final long identity = Binder.clearCallingIdentity();
2765 try {
2766 final Phone phone = getPhone(subId);
2767 if (phone == null) {
2768 return false;
2769 }
2770 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2771 toggleRadioOnOffForSubscriber(subId);
2772 }
2773 return true;
2774 } finally {
2775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 }
Wink Saville36469e72014-06-11 15:17:00 -07002778
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002779 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002780 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002781 /*
2782 * If any of the Radios are available, it will need to be
2783 * shutdown. So return true if any Radio is available.
2784 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 final long identity = Binder.clearCallingIdentity();
2786 try {
2787 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2788 Phone phone = PhoneFactory.getPhone(i);
2789 if (phone != null && phone.isRadioAvailable()) return true;
2790 }
2791 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2792 return false;
2793 } finally {
2794 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002795 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002796 }
2797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002799 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002800 enforceModifyPermission();
2801
2802 final long identity = Binder.clearCallingIdentity();
2803 try {
2804 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2805 logv("Shutting down Phone " + i);
2806 shutdownRadioUsingPhoneId(i);
2807 }
2808 } finally {
2809 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002810 }
2811 }
2812
2813 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002814 Phone phone = PhoneFactory.getPhone(phoneId);
2815 if (phone != null && phone.isRadioAvailable()) {
2816 phone.shutdownRadio();
2817 }
2818 }
2819
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002821 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822
2823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2826 if (defaultPhone != null) {
2827 defaultPhone.setRadioPower(turnOn);
2828 return true;
2829 } else {
2830 loge("There's no default phone.");
2831 return false;
2832 }
2833 } finally {
2834 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002835 }
Wink Saville36469e72014-06-11 15:17:00 -07002836 }
2837
Wink Savilleb564aae2014-10-23 10:18:09 -07002838 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 final Phone phone = getPhone(subId);
2844 if (phone != null) {
2845 phone.setRadioPower(turnOn);
2846 return true;
2847 } else {
2848 return false;
2849 }
2850 } finally {
2851 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002852 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002853 }
2854
Wink Saville36469e72014-06-11 15:17:00 -07002855 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002856 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002857 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002858 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859
2860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 int subId = mSubscriptionController.getDefaultDataSubId();
2863 final Phone phone = getPhone(subId);
2864 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002865 if (phone.isUsingNewDataStack()) {
2866 phone.getDataSettingsManager().setDataEnabled(
Sarah Chinecc78c42022-03-31 21:16:48 -07002867 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Jack Yu99e87332021-12-17 23:14:15 -08002868 } else {
2869 phone.getDataEnabledSettings().setDataEnabled(
2870 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2871 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872 return true;
2873 } else {
2874 return false;
2875 }
2876 } finally {
2877 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002878 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002879 }
2880
Wink Saville36469e72014-06-11 15:17:00 -07002881 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002882 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002883 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885
2886 final long identity = Binder.clearCallingIdentity();
2887 try {
2888 int subId = mSubscriptionController.getDefaultDataSubId();
2889 final Phone phone = getPhone(subId);
2890 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002891 if (phone.isUsingNewDataStack()) {
2892 phone.getDataSettingsManager().setDataEnabled(
Sarah Chinecc78c42022-03-31 21:16:48 -07002893 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Jack Yu99e87332021-12-17 23:14:15 -08002894 } else {
2895 phone.getDataEnabledSettings().setDataEnabled(
2896 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2897 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002898 return true;
2899 } else {
2900 return false;
2901 }
2902 } finally {
2903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002905 }
2906
Sanket Padawe356d7632015-06-22 14:03:32 -07002907 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002908 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909 final long identity = Binder.clearCallingIdentity();
2910 try {
2911 final Phone phone = getPhone(subId);
2912 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07002913 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002914 } else {
2915 return false;
2916 }
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 }
2921
2922 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002923 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002924 }
2925
pkanwarae03a6b2016-11-06 20:37:09 -08002926 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927 enforceCallPermission();
2928
2929 final long identity = Binder.clearCallingIdentity();
2930 try {
2931 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2932 return;
2933 }
2934 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2935 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2936 } finally {
2937 Binder.restoreCallingIdentity(identity);
2938 }
pkanwar32d516d2016-10-14 19:37:38 -07002939 };
2940
Wink Savilleb564aae2014-10-23 10:18:09 -07002941 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002942 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943
2944 final long identity = Binder.clearCallingIdentity();
2945 try {
2946 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2947 return false;
2948 }
2949 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 }
2954
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002955 /**
2956 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2957 * tag on getCallState Binder call.
2958 */
2959 @Deprecated
2960 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002961 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002962 if (CompatChanges.isChangeEnabled(
2963 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2964 Binder.getCallingUid())) {
2965 // Do not allow this API to be called on API version 31+, it should only be
2966 // called on old apps using this Binder call directly.
2967 throw new SecurityException("This method can only be used for applications "
2968 + "targeting API version 30 or less.");
2969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002970 final long identity = Binder.clearCallingIdentity();
2971 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002972 Phone phone = getPhone(getDefaultSubscription());
2973 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2974 PhoneConstantConversions.convertCallState(phone.getState());
2975 } finally {
2976 Binder.restoreCallingIdentity(identity);
2977 }
2978 }
2979
2980 @Override
2981 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2982 if (CompatChanges.isChangeEnabled(
2983 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2984 Binder.getCallingUid())) {
2985 // Check READ_PHONE_STATE for API version 31+
2986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2987 featureId, "getCallStateForSubscription")) {
2988 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2989 + "targeting API level 31+.");
2990 }
2991 }
2992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2996 PhoneConstantConversions.convertCallState(phone.getState());
2997 } finally {
2998 Binder.restoreCallingIdentity(identity);
2999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003000 }
3001
Sanket Padawe356d7632015-06-22 14:03:32 -07003002 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003003 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003004 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3005 }
3006
3007 @Override
3008 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003009 final long identity = Binder.clearCallingIdentity();
3010 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003011 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003012 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08003013 if (phone.isUsingNewDataStack()) {
3014 return phone.getDataNetworkController().getInternetDataNetworkState();
3015 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
3017 } else {
3018 return PhoneConstantConversions.convertDataState(
3019 PhoneConstants.DataState.DISCONNECTED);
3020 }
3021 } finally {
3022 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003023 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003024 }
3025
Sanket Padawe356d7632015-06-22 14:03:32 -07003026 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003027 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003028 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3029 }
3030
3031 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003032 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003033 final long identity = Binder.clearCallingIdentity();
3034 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003035 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003036 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003037 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038 } else {
3039 return TelephonyManager.DATA_ACTIVITY_NONE;
3040 }
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003043 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003044 }
3045
3046 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003047 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003048 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003049 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003050
3051 LocationAccessPolicy.LocationPermissionResult locationResult =
3052 LocationAccessPolicy.checkLocationPermission(mApp,
3053 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3054 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003055 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003056 .setCallingPid(Binder.getCallingPid())
3057 .setCallingUid(Binder.getCallingUid())
3058 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003059 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003060 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3061 .build());
3062 switch (locationResult) {
3063 case DENIED_HARD:
3064 throw new SecurityException("Not allowed to access cell location");
3065 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003066 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3067 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003068 }
3069
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003070 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003074 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003075 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
Svetoslav64fad262015-04-14 14:35:21 -07003079 }
3080
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003082 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003083 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3084 // registered cell info, so return a NULL country instead.
3085 final long identity = Binder.clearCallingIdentity();
3086 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003087 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3088 // Get default phone in this case.
3089 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3090 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003091 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003092 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003093 if (phone == null) return "";
3094 ServiceStateTracker sst = phone.getServiceStateTracker();
3095 if (sst == null) return "";
3096 LocaleTracker lt = sst.getLocaleTracker();
3097 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003098 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003099 } finally {
3100 Binder.restoreCallingIdentity(identity);
3101 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003102 }
3103
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003104 /**
3105 * This method was removed due to potential issues caused by performing partial
3106 * updates of service state, and lack of a credible use case.
3107 *
3108 * This has the ability to break the telephony implementation by disabling notification of
3109 * changes in device connectivity. DO NOT USE THIS!
3110 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003111 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003112 public void enableLocationUpdates() {
3113 mApp.enforceCallingOrSelfPermission(
3114 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003115 }
3116
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003117 /**
3118 * This method was removed due to potential issues caused by performing partial
3119 * updates of service state, and lack of a credible use case.
3120 *
3121 * This has the ability to break the telephony implementation by disabling notification of
3122 * changes in device connectivity. DO NOT USE THIS!
3123 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003124 @Override
3125 public void disableLocationUpdates() {
3126 mApp.enforceCallingOrSelfPermission(
3127 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003128 }
3129
3130 @Override
3131 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003132 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3133 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003134 try {
3135 mApp.getSystemService(AppOpsManager.class)
3136 .checkPackage(Binder.getCallingUid(), callingPackage);
3137 } catch (SecurityException e) {
3138 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3139 throw e;
3140 }
3141
Nathan Haroldf096d982020-11-18 17:18:06 -08003142 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003143 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3144 throw new SecurityException(
3145 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3146 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003147
Jordan Liu1617b712019-07-10 15:06:26 -07003148 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003149 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3150 return null;
3151 }
Svetoslav64fad262015-04-14 14:35:21 -07003152
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003153 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003154
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003155 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003156 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157
Nathan Haroldf180aac2018-06-01 18:43:55 -07003158 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3159 for (CellInfo ci : info) {
3160 if (ci instanceof CellInfoGsm) {
3161 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3162 } else if (ci instanceof CellInfoWcdma) {
3163 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003165 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003166 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003167 }
3168
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003169 private List<CellInfo> getCachedCellInfo() {
3170 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3171 for (Phone phone : PhoneFactory.getPhones()) {
3172 List<CellInfo> info = phone.getAllCellInfo();
3173 if (info != null) cellInfos.addAll(info);
3174 }
3175 return cellInfos;
3176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003177
3178 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003179 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003180 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003181 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003182
3183 LocationAccessPolicy.LocationPermissionResult locationResult =
3184 LocationAccessPolicy.checkLocationPermission(mApp,
3185 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3186 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003187 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003188 .setCallingPid(Binder.getCallingPid())
3189 .setCallingUid(Binder.getCallingUid())
3190 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003191 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003192 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3193 .build());
3194 switch (locationResult) {
3195 case DENIED_HARD:
3196 throw new SecurityException("Not allowed to access cell info");
3197 case DENIED_SOFT:
3198 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003199 }
3200
Nathan Haroldf096d982020-11-18 17:18:06 -08003201 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003202 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3203 return getCachedCellInfo();
3204 }
3205
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003206 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003207 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3211 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003212 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003213 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214 if (info != null) cellInfos.addAll(info);
3215 }
3216 return cellInfos;
3217 } finally {
3218 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003219 }
3220 }
3221
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003222 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003223 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3224 String callingFeatureId) {
3225 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3226 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003227 }
3228
3229 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003230 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3231 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003232 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003233 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003234 }
3235
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003236 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3237 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003238 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003239 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003240
3241 LocationAccessPolicy.LocationPermissionResult locationResult =
3242 LocationAccessPolicy.checkLocationPermission(mApp,
3243 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3244 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003245 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003246 .setCallingPid(Binder.getCallingPid())
3247 .setCallingUid(Binder.getCallingUid())
3248 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003249 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3250 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003251 .build());
3252 switch (locationResult) {
3253 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003254 if (TelephonyPermissions
3255 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003256 // Safetynet logging for b/154934934
3257 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3258 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003259 throw new SecurityException("Not allowed to access cell info");
3260 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003261 if (TelephonyPermissions
3262 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003263 // Safetynet logging for b/154934934
3264 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3265 }
Nathan Harold5320c422019-05-09 10:26:08 -07003266 try {
3267 cb.onCellInfo(new ArrayList<CellInfo>());
3268 } catch (RemoteException re) {
3269 // Drop without consequences
3270 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003271 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003272 }
3273
Nathan Harolda939a962019-05-09 10:13:47 -07003274
3275 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003276 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3277
3278 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3279 }
3280
3281 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003282 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003283 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003284 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003285
3286 final long identity = Binder.clearCallingIdentity();
3287 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003288 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003289 } finally {
3290 Binder.restoreCallingIdentity(identity);
3291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003292 }
3293
Shishir Agrawala9f32182016-04-12 12:00:16 -07003294 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003295 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003296 Phone phone = PhoneFactory.getPhone(slotIndex);
3297 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003298 return null;
3299 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003300 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003301 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003302 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003303 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003304 return null;
3305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003306
3307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 return phone.getImei();
3310 } finally {
3311 Binder.restoreCallingIdentity(identity);
3312 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003313 }
3314
3315 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003316 public String getTypeAllocationCodeForSlot(int slotIndex) {
3317 Phone phone = PhoneFactory.getPhone(slotIndex);
3318 String tac = null;
3319 if (phone != null) {
3320 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003321 try {
3322 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3323 } catch (IndexOutOfBoundsException e) {
3324 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3325 return null;
3326 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003327 }
3328 return tac;
3329 }
3330
3331 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003332 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003333 try {
3334 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3335 } catch (SecurityException se) {
3336 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3337 throw new SecurityException("Package " + callingPackage + " does not belong to "
3338 + Binder.getCallingUid());
3339 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003340 Phone phone = PhoneFactory.getPhone(slotIndex);
3341 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003342 return null;
3343 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003344
Jeff Davidson913390f2018-02-23 17:11:49 -08003345 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003346 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003347 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003348 return null;
3349 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003350
3351 final long identity = Binder.clearCallingIdentity();
3352 try {
3353 return phone.getMeid();
3354 } finally {
3355 Binder.restoreCallingIdentity(identity);
3356 }
Jack Yu2af8d712017-03-15 17:14:14 -07003357 }
3358
3359 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003360 public String getManufacturerCodeForSlot(int slotIndex) {
3361 Phone phone = PhoneFactory.getPhone(slotIndex);
3362 String manufacturerCode = null;
3363 if (phone != null) {
3364 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003365 try {
3366 manufacturerCode =
3367 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3368 } catch (IndexOutOfBoundsException e) {
3369 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3370 return null;
3371 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003372 }
3373 return manufacturerCode;
3374 }
3375
3376 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003377 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3378 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003379 Phone phone = PhoneFactory.getPhone(slotIndex);
3380 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003381 return null;
3382 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003383 int subId = phone.getSubId();
3384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003385 mApp, subId, callingPackage, callingFeatureId,
3386 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003387 return null;
3388 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389
3390 final long identity = Binder.clearCallingIdentity();
3391 try {
3392 return phone.getDeviceSvn();
3393 } finally {
3394 Binder.restoreCallingIdentity(identity);
3395 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003396 }
3397
fionaxu43304da2017-11-27 22:51:16 -08003398 @Override
3399 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003400 final long identity = Binder.clearCallingIdentity();
3401 try {
3402 final Phone phone = getPhone(subId);
3403 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3404 } finally {
3405 Binder.restoreCallingIdentity(identity);
3406 }
fionaxu43304da2017-11-27 22:51:16 -08003407 }
3408
3409 @Override
3410 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003411 final long identity = Binder.clearCallingIdentity();
3412 try {
3413 final Phone phone = getPhone(subId);
3414 return phone == null ? null : phone.getCarrierName();
3415 } finally {
3416 Binder.restoreCallingIdentity(identity);
3417 }
fionaxu43304da2017-11-27 22:51:16 -08003418 }
3419
calvinpanffe225e2018-11-01 19:43:06 +08003420 @Override
chen xu0026ca62019-03-06 15:28:50 -08003421 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 final Phone phone = getPhone(subId);
3425 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003426 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
3430 }
3431
3432 @Override
chen xu0026ca62019-03-06 15:28:50 -08003433 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003434 final long identity = Binder.clearCallingIdentity();
3435 try {
3436 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003437 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003438 } finally {
3439 Binder.restoreCallingIdentity(identity);
3440 }
3441 }
3442
chen xu651eec72018-11-11 19:03:44 -08003443 @Override
chen xu864e11c2018-12-06 22:10:03 -08003444 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3445 if (!isSubscriptionMccMnc) {
3446 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3447 }
chen xu651eec72018-11-11 19:03:44 -08003448 final Phone phone = PhoneFactory.getPhone(slotIndex);
3449 if (phone == null) {
3450 return TelephonyManager.UNKNOWN_CARRIER_ID;
3451 }
3452 final long identity = Binder.clearCallingIdentity();
3453 try {
3454 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3455 } finally {
3456 Binder.restoreCallingIdentity(identity);
3457 }
3458 }
3459
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003460 //
3461 // Internal helper methods.
3462 //
3463
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003464 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003465 * Make sure the caller is the calling package itself
3466 *
3467 * @throws SecurityException if the caller is not the calling package
3468 */
3469 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3470 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003471 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3472 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003473 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003474 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003475 } catch (PackageManager.NameNotFoundException e) {
3476 // packageUid is -1
3477 }
3478 if (packageUid != callingUid) {
3479 throw new SecurityException(message + ": Package " + callingPackage
3480 + " does not belong to " + callingUid);
3481 }
3482 }
3483
3484 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003485 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3486 *
3487 * @throws SecurityException if the caller does not have the required permission
3488 */
3489 private void enforceModifyPermission() {
3490 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3491 }
3492
Shuo Qian3b6ee772019-11-13 17:43:31 -08003493 private void enforceActiveEmergencySessionPermission() {
3494 mApp.enforceCallingOrSelfPermission(
3495 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3496 }
3497
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003498 /**
3499 * Make sure the caller has the CALL_PHONE permission.
3500 *
3501 * @throws SecurityException if the caller does not have the required permission
3502 */
3503 private void enforceCallPermission() {
3504 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3505 }
3506
paulhu5a773602019-08-23 19:17:33 +08003507 private void enforceSettingsPermission() {
3508 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003509 }
3510
Michele Berionne5e411512020-11-13 02:36:59 +00003511 private void enforceRebootPermission() {
3512 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3513 }
3514
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003515 private String createTelUrl(String number) {
3516 if (TextUtils.isEmpty(number)) {
3517 return null;
3518 }
3519
Jake Hambye994d462014-02-03 13:10:13 -08003520 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003521 }
3522
Ihab Awadf9e92732013-12-05 18:02:52 -08003523 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003524 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3525 }
3526
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003527 private static void logv(String msg) {
3528 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3529 }
3530
Ihab Awadf9e92732013-12-05 18:02:52 -08003531 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003532 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3533 }
3534
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003535 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003536 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003537 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003538 }
3539
Sanket Padawe356d7632015-06-22 14:03:32 -07003540 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003541 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003542 final long identity = Binder.clearCallingIdentity();
3543 try {
3544 final Phone phone = PhoneFactory.getPhone(slotIndex);
3545 if (phone == null) {
3546 return PhoneConstants.PHONE_TYPE_NONE;
3547 } else {
3548 return phone.getPhoneType();
3549 }
3550 } finally {
3551 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003553 }
3554
3555 /**
3556 * Returns the CDMA ERI icon index to display
3557 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003558 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003559 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3560 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3561 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003562 }
3563
Sanket Padawe356d7632015-06-22 14:03:32 -07003564 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003565 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3566 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003567 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003568 mApp, subId, callingPackage, callingFeatureId,
3569 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003570 return -1;
3571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572
3573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 final Phone phone = getPhone(subId);
3576 if (phone != null) {
3577 return phone.getCdmaEriIconIndex();
3578 } else {
3579 return -1;
3580 }
3581 } finally {
3582 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003584 }
3585
3586 /**
3587 * Returns the CDMA ERI icon mode,
3588 * 0 - ON
3589 * 1 - FLASHING
3590 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003592 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3593 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3594 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003595 }
3596
Sanket Padawe356d7632015-06-22 14:03:32 -07003597 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003598 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3599 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003600 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003601 mApp, subId, callingPackage, callingFeatureId,
3602 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003603 return -1;
3604 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003605
3606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 final Phone phone = getPhone(subId);
3609 if (phone != null) {
3610 return phone.getCdmaEriIconMode();
3611 } else {
3612 return -1;
3613 }
3614 } finally {
3615 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003617 }
3618
3619 /**
3620 * Returns the CDMA ERI text,
3621 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003622 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003623 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3624 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3625 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003626 }
3627
Sanket Padawe356d7632015-06-22 14:03:32 -07003628 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003629 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3630 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003632 mApp, subId, callingPackage, callingFeatureId,
3633 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003634 return null;
3635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003636
3637 final long identity = Binder.clearCallingIdentity();
3638 try {
3639 final Phone phone = getPhone(subId);
3640 if (phone != null) {
3641 return phone.getCdmaEriText();
3642 } else {
3643 return null;
3644 }
3645 } finally {
3646 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003648 }
3649
3650 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003651 * Returns the CDMA MDN.
3652 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003653 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003654 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3656 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657
3658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003661 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662 return phone.getLine1Number();
3663 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003664 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665 return null;
3666 }
3667 } finally {
3668 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003669 }
3670 }
3671
3672 /**
3673 * Returns the CDMA MIN.
3674 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003675 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003676 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3678 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003679
3680 final long identity = Binder.clearCallingIdentity();
3681 try {
3682 final Phone phone = getPhone(subId);
3683 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3684 return phone.getCdmaMin();
3685 } else {
3686 return null;
3687 }
3688 } finally {
3689 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003690 }
3691 }
3692
Hall Liud892bec2018-11-30 14:51:45 -08003693 @Override
3694 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3695 INumberVerificationCallback callback, String callingPackage) {
3696 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3697 != PERMISSION_GRANTED) {
3698 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3699 }
3700 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3701
3702 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3703 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003704 throw new SecurityException("Calling package must be configured in the device config: "
3705 + "calling package: " + callingPackage
3706 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003707 }
3708
3709 if (range == null) {
3710 throw new NullPointerException("Range must be non-null");
3711 }
3712
3713 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003714 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003715
3716 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3717 }
3718
Junda Liuca05d5d2014-08-14 22:36:34 -07003719 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003720 * Returns true if CDMA provisioning needs to run.
3721 */
3722 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723 final long identity = Binder.clearCallingIdentity();
3724 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003725 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003729 }
3730
3731 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003732 * Sets the voice mail number of a given subId.
3733 */
3734 @Override
3735 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003736 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3737 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003738
3739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3742 new Pair<String, String>(alphaTag, number), new Integer(subId));
3743 return success;
3744 } finally {
3745 Binder.restoreCallingIdentity(identity);
3746 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003747 }
3748
Ta-wei Yen87c49842016-05-13 21:19:52 -07003749 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003750 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3751 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003752 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3753 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003754 if (!TextUtils.equals(callingPackage, systemDialer)) {
3755 throw new SecurityException("caller must be system dialer");
3756 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003757
3758 final long identity = Binder.clearCallingIdentity();
3759 try {
3760 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3761 if (phoneAccountHandle == null) {
3762 return null;
3763 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003764 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003765 } finally {
3766 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003767 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003768 }
3769
3770 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003771 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3772 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003773 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003774 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003775 mApp, subId, callingPackage, callingFeatureId,
3776 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003777 return null;
3778 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003779
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003780 final long identity = Binder.clearCallingIdentity();
3781 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003782 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003783 } finally {
3784 Binder.restoreCallingIdentity(identity);
3785 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003786 }
3787
3788 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003789 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3790 VisualVoicemailSmsFilterSettings settings) {
3791 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792
3793 final long identity = Binder.clearCallingIdentity();
3794 try {
3795 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003796 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797 } finally {
3798 Binder.restoreCallingIdentity(identity);
3799 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003800 }
3801
3802 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003803 public void disableVisualVoicemailSmsFilter(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 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
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 Yenb6929602016-05-24 15:48:27 -07003816 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3817 String callingPackage, int subId) {
3818 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003819
3820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003823 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003824 } finally {
3825 Binder.restoreCallingIdentity(identity);
3826 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003827 }
3828
3829 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003830 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003832
3833 final long identity = Binder.clearCallingIdentity();
3834 try {
3835 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003836 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003837 } finally {
3838 Binder.restoreCallingIdentity(identity);
3839 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003840 }
3841
3842 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003843 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3844 String callingAttributionTag, int subId, String number, int port, String text,
3845 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003846 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003847 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003848 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003849 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003850 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3851 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003852 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003853
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003854 /**
fionaxu0152e512016-11-14 13:36:14 -08003855 * Sets the voice activation state of a given subId.
3856 */
3857 @Override
3858 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3860 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003861
3862 final long identity = Binder.clearCallingIdentity();
3863 try {
3864 final Phone phone = getPhone(subId);
3865 if (phone != null) {
3866 phone.setVoiceActivationState(activationState);
3867 } else {
3868 loge("setVoiceActivationState fails with invalid subId: " + subId);
3869 }
3870 } finally {
3871 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003872 }
3873 }
3874
3875 /**
3876 * Sets the data activation state of a given subId.
3877 */
3878 @Override
3879 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3881 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003882
3883 final long identity = Binder.clearCallingIdentity();
3884 try {
3885 final Phone phone = getPhone(subId);
3886 if (phone != null) {
3887 phone.setDataActivationState(activationState);
3888 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003889 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003890 }
3891 } finally {
3892 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003893 }
3894 }
3895
3896 /**
3897 * Returns the voice activation state of a given subId.
3898 */
3899 @Override
3900 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003901 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003902
fionaxu0152e512016-11-14 13:36:14 -08003903 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904 final long identity = Binder.clearCallingIdentity();
3905 try {
3906 if (phone != null) {
3907 return phone.getVoiceActivationState();
3908 } else {
3909 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3910 }
3911 } finally {
3912 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003913 }
3914 }
3915
3916 /**
3917 * Returns the data activation state of a given subId.
3918 */
3919 @Override
3920 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003921 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003922
fionaxu0152e512016-11-14 13:36:14 -08003923 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003924 final long identity = Binder.clearCallingIdentity();
3925 try {
3926 if (phone != null) {
3927 return phone.getDataActivationState();
3928 } else {
3929 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3930 }
3931 } finally {
3932 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003933 }
3934 }
3935
3936 /**
Wink Saville36469e72014-06-11 15:17:00 -07003937 * Returns the unread count of voicemails for a subId
3938 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003939 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003940 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3941 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003942 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003943 mApp, subId, callingPackage, callingFeatureId,
3944 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003945 return 0;
3946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003947 final long identity = Binder.clearCallingIdentity();
3948 try {
3949 final Phone phone = getPhone(subId);
3950 if (phone != null) {
3951 return phone.getVoiceMessageCount();
3952 } else {
3953 return 0;
3954 }
3955 } finally {
3956 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003957 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003958 }
3959
3960 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003961 * returns true, if the device is in a state where both voice and data
3962 * are supported simultaneously. This can change based on location or network condition.
3963 */
3964 @Override
3965 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003966 final long identity = Binder.clearCallingIdentity();
3967 try {
3968 final Phone phone = getPhone(subId);
3969 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3970 } finally {
3971 Binder.restoreCallingIdentity(identity);
3972 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003973 }
3974
3975 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003976 * Send the dialer code if called from the current default dialer or the caller has
3977 * carrier privilege.
3978 * @param inputCode The dialer code to send
3979 */
3980 @Override
3981 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003982 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003983 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003984 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3985 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003986 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003987 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003988 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003990
3991 final long identity = Binder.clearCallingIdentity();
3992 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003993 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003994 } finally {
3995 Binder.restoreCallingIdentity(identity);
3996 }
fionaxu235cc5e2017-03-06 22:25:57 -08003997 }
3998
Pengquan Menga1bb6272018-09-06 09:59:22 -07003999 @Override
4000 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004001 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004002 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004003 mApp, subId, "getNetworkSelectionMode");
4004 final long identity = Binder.clearCallingIdentity();
4005 try {
4006 if (!isActiveSubscription(subId)) {
4007 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4008 }
4009 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4010 } finally {
4011 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004012 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004013 }
4014
Brad Ebinger35c841c2018-10-01 10:40:55 -07004015 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004016 public boolean isInEmergencySmsMode() {
4017 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4018 final long identity = Binder.clearCallingIdentity();
4019 try {
4020 for (Phone phone : PhoneFactory.getPhones()) {
4021 if (phone.isInEmergencySmsMode()) {
4022 return true;
4023 }
4024 }
4025 } finally {
4026 Binder.restoreCallingIdentity(identity);
4027 }
4028 return false;
4029 }
4030
shilu366312e2019-12-17 09:28:10 -08004031 /**
4032 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4033 * @param subId The subscription to use to check the configuration.
4034 * @param c The callback that will be used to send the result.
4035 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004036 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004037 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4038 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004039 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004040 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004041
4042 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4043 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4044 "IMS not available on device.");
4045 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004046 final long token = Binder.clearCallingIdentity();
4047 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004048 int slotId = getSlotIndexOrException(subId);
4049 verifyImsMmTelConfiguredOrThrow(slotId);
4050 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004051 } catch (ImsException e) {
4052 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004053 } finally {
4054 Binder.restoreCallingIdentity(token);
4055 }
4056 }
4057
shilu366312e2019-12-17 09:28:10 -08004058 /**
4059 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4060 * @param subId The subscription to use to check the configuration.
4061 * @param c The callback that will be used to send the result.
4062 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004063 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004064 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004065 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004066 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004067 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4068 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4069 }
Meng Wangafbc5852019-09-19 17:37:13 -07004070 final long token = Binder.clearCallingIdentity();
4071 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004072 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4073 .removeRegistrationCallbackForSubscription(c, subId);
4074 } catch (ImsException e) {
4075 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4076 + "is inactive, ignoring unregister.");
4077 // If the subscription is no longer active, just return, since the callback
4078 // will already have been removed internally.
4079 } finally {
4080 Binder.restoreCallingIdentity(token);
4081 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 }
4083
Brad Ebingera34a6c22019-10-22 17:36:18 -07004084 /**
4085 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4086 */
4087 @Override
4088 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4089 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4090 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4091 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4092 "IMS not available on device.");
4093 }
4094 final long token = Binder.clearCallingIdentity();
4095 try {
4096 Phone phone = getPhone(subId);
4097 if (phone == null) {
4098 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4099 + subId + "'");
4100 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4101 }
4102 phone.getImsRegistrationState(regState -> {
4103 try {
4104 consumer.accept((regState == null)
4105 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4106 } catch (RemoteException e) {
4107 // Ignore if the remote process is no longer available to call back.
4108 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4109 }
4110 });
4111 } finally {
4112 Binder.restoreCallingIdentity(token);
4113 }
4114 }
4115
4116 /**
4117 * Get the transport type for the IMS service registration state.
4118 */
4119 @Override
4120 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004121 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004122 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004123 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4124 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4125 "IMS not available on device.");
4126 }
4127 final long token = Binder.clearCallingIdentity();
4128 try {
4129 Phone phone = getPhone(subId);
4130 if (phone == null) {
4131 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4132 + subId + "'");
4133 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4134 }
4135 phone.getImsRegistrationTech(regTech -> {
4136 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4137 int regTechConverted = (regTech == null)
4138 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4139 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4140 regTechConverted);
4141 try {
4142 consumer.accept(regTechConverted);
4143 } catch (RemoteException e) {
4144 // Ignore if the remote process is no longer available to call back.
4145 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4146 }
4147 });
4148 } finally {
4149 Binder.restoreCallingIdentity(token);
4150 }
4151 }
4152
shilu366312e2019-12-17 09:28:10 -08004153 /**
4154 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4155 * @param subId The subscription to use to check the configuration.
4156 * @param c The callback that will be used to send the result.
4157 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004159 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4160 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004161 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004162 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004163 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4164 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4165 "IMS not available on device.");
4166 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004167 final long token = Binder.clearCallingIdentity();
4168 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004169 int slotId = getSlotIndexOrException(subId);
4170 verifyImsMmTelConfiguredOrThrow(slotId);
4171 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004172 } catch (ImsException e) {
4173 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004174 } finally {
4175 Binder.restoreCallingIdentity(token);
4176 }
4177 }
4178
shilu366312e2019-12-17 09:28:10 -08004179 /**
4180 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4181 * @param subId The subscription to use to check the configuration.
4182 * @param c The callback that will be used to send the result.
4183 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004184 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004185 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004186 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004187 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004188 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4189 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4190 }
Meng Wangafbc5852019-09-19 17:37:13 -07004191
4192 final long token = Binder.clearCallingIdentity();
4193 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004194 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004195 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004196 } catch (ImsException e) {
4197 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4198 + "is inactive, ignoring unregister.");
4199 // If the subscription is no longer active, just return, since the callback
4200 // will already have been removed internally.
4201 } finally {
4202 Binder.restoreCallingIdentity(token);
4203 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004204 }
4205
4206 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004207 public boolean isCapable(int subId, int capability, int regTech) {
4208 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004209 final long token = Binder.clearCallingIdentity();
4210 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004211 int slotId = getSlotIndexOrException(subId);
4212 verifyImsMmTelConfiguredOrThrow(slotId);
4213 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4214 } catch (com.android.ims.ImsException e) {
4215 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4216 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004217 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004218 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4219 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004220 } finally {
4221 Binder.restoreCallingIdentity(token);
4222 }
4223 }
4224
4225 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004226 public boolean isAvailable(int subId, int capability, int regTech) {
4227 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004228 final long token = Binder.clearCallingIdentity();
4229 try {
4230 Phone phone = getPhone(subId);
4231 if (phone == null) return false;
4232 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004233 } catch (com.android.ims.ImsException e) {
4234 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4235 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 } finally {
4237 Binder.restoreCallingIdentity(token);
4238 }
4239 }
4240
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004241 /**
4242 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4243 * subscription.
4244 * @param subId The subscription to use to check the configuration.
4245 * @param callback The callback that will be used to send the result.
4246 * @param capability The MmTelFeature capability that will be used to send the result.
4247 * @param transportType The transport type of the MmTelFeature capability.
4248 */
4249 @Override
4250 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4251 int transportType) {
4252 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004253 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4254 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4255 "IMS not available on device.");
4256 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004257 final long token = Binder.clearCallingIdentity();
4258 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004259 int slotId = getSlotIndex(subId);
4260 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4261 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4262 + subId + "'");
4263 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4264 }
4265 verifyImsMmTelConfiguredOrThrow(slotId);
4266 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4267 transportType, aBoolean -> {
4268 try {
4269 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4270 } catch (RemoteException e) {
4271 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4272 + "running. Ignore");
4273 }
4274 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004275 } catch (ImsException e) {
4276 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004277 } finally {
4278 Binder.restoreCallingIdentity(token);
4279 }
4280 }
4281
shilu366312e2019-12-17 09:28:10 -08004282 /**
4283 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4284 * @param subId The subscription to use to check the configuration.
4285 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004286 @Override
4287 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004288 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004289 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004290
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 final long token = Binder.clearCallingIdentity();
4292 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004293 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004294 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004295 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004296 } catch (ImsException e) {
4297 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 } finally {
4299 Binder.restoreCallingIdentity(token);
4300 }
4301 }
4302
4303 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004304 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004306 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004307 final long identity = Binder.clearCallingIdentity();
4308 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004309 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004310 // This setting doesn't require an active ImsService connection, so do not verify. The
4311 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004312 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004313 } catch (ImsException e) {
4314 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004315 } finally {
4316 Binder.restoreCallingIdentity(identity);
4317 }
4318 }
4319
shilu366312e2019-12-17 09:28:10 -08004320 /**
4321 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4322 * @param subId The subscription to use to check the configuration.
4323 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004324 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004325 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004326 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004327 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 final long identity = Binder.clearCallingIdentity();
4329 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004330 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004331 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004332 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004333 } catch (ImsException e) {
4334 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 } finally {
4336 Binder.restoreCallingIdentity(identity);
4337 }
4338 }
4339
4340 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004341 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004343 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004344 final long identity = Binder.clearCallingIdentity();
4345 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004346 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004347 // This setting doesn't require an active ImsService connection, so do not verify. The
4348 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004349 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004350 } catch (ImsException e) {
4351 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004352 } finally {
4353 Binder.restoreCallingIdentity(identity);
4354 }
4355 }
4356
shilu366312e2019-12-17 09:28:10 -08004357 /**
4358 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4359 * @param subId The subscription to use to check the configuration.
4360 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004361 @Override
4362 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004363 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004364 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 final long identity = Binder.clearCallingIdentity();
4366 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004367 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004368 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004369 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004370 } catch (ImsException e) {
4371 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 } finally {
4373 Binder.restoreCallingIdentity(identity);
4374 }
4375 }
4376
4377 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004378 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004380 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004381 final long identity = Binder.clearCallingIdentity();
4382 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004383 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004384 // This setting doesn't require an active ImsService connection, so do not verify. The
4385 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004386 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004387 } catch (ImsException e) {
4388 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004389 } finally {
4390 Binder.restoreCallingIdentity(identity);
4391 }
4392 }
4393
shilu366312e2019-12-17 09:28:10 -08004394 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004395 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4396 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4397 * @param subId The subscription to use to check the configuration.
4398 */
4399 @Override
4400 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004401 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004402 mApp, subId, "isCrossSimCallingEnabledByUser");
4403 final long identity = Binder.clearCallingIdentity();
4404 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004405 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004406 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004407 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004408 } catch (ImsException e) {
4409 throw new ServiceSpecificException(e.getCode());
4410 } finally {
4411 Binder.restoreCallingIdentity(identity);
4412 }
4413 }
4414
4415 /**
4416 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4417 * Requires MODIFY_PHONE_STATE permission.
4418 * @param subId The subscription to use to check the configuration.
4419 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4420 * false otherwise
4421 */
4422 @Override
4423 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4425 "setCrossSimCallingEnabled");
4426 final long identity = Binder.clearCallingIdentity();
4427 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004428 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004429 // This setting doesn't require an active ImsService connection, so do not verify. The
4430 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004431 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004432 } catch (ImsException e) {
4433 throw new ServiceSpecificException(e.getCode());
4434 } finally {
4435 Binder.restoreCallingIdentity(identity);
4436 }
4437 }
4438
4439 /**
shilu366312e2019-12-17 09:28:10 -08004440 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4441 * @param subId The subscription to use to check the configuration.
4442 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004443 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004444
Brad Ebinger35c841c2018-10-01 10:40:55 -07004445 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004446 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004447 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 final long identity = Binder.clearCallingIdentity();
4449 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004450 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004451 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004452 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004453 } catch (ImsException e) {
4454 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004455 } finally {
4456 Binder.restoreCallingIdentity(identity);
4457 }
4458 }
4459
4460 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004461 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004463 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004464 final long identity = Binder.clearCallingIdentity();
4465 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004466 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004467 // This setting doesn't require an active ImsService connection, so do not verify. The
4468 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004469 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004470 } catch (ImsException e) {
4471 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004472 } finally {
4473 Binder.restoreCallingIdentity(identity);
4474 }
4475 }
4476
4477 @Override
4478 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4479 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4480 "setVoWiFiNonPersistent");
4481 final long identity = Binder.clearCallingIdentity();
4482 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004483 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004484 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004485 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004486 } catch (ImsException e) {
4487 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004488 } finally {
4489 Binder.restoreCallingIdentity(identity);
4490 }
4491 }
4492
shilu366312e2019-12-17 09:28:10 -08004493 /**
4494 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4495 * @param subId The subscription to use to check the configuration.
4496 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004497 @Override
4498 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004499 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004500 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004501 final long identity = Binder.clearCallingIdentity();
4502 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004503 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004504 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004505 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004506 } catch (ImsException e) {
4507 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004508 } finally {
4509 Binder.restoreCallingIdentity(identity);
4510 }
4511 }
4512
4513 @Override
4514 public void setVoWiFiModeSetting(int subId, int mode) {
4515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4516 "setVoWiFiModeSetting");
4517 final long identity = Binder.clearCallingIdentity();
4518 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004519 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004520 // This setting doesn't require an active ImsService connection, so do not verify. The
4521 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004522 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004523 } catch (ImsException e) {
4524 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004525 } finally {
4526 Binder.restoreCallingIdentity(identity);
4527 }
4528 }
4529
4530 @Override
4531 public int getVoWiFiRoamingModeSetting(int subId) {
4532 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4533 final long identity = Binder.clearCallingIdentity();
4534 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004535 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004536 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004537 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004538 } catch (ImsException e) {
4539 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004540 } finally {
4541 Binder.restoreCallingIdentity(identity);
4542 }
4543 }
4544
4545 @Override
4546 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4548 "setVoWiFiRoamingModeSetting");
4549 final long identity = Binder.clearCallingIdentity();
4550 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004551 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004552 // This setting doesn't require an active ImsService connection, so do not verify. The
4553 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004554 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004555 } catch (ImsException e) {
4556 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
4560 }
4561
4562 @Override
4563 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4565 "setRttCapabilityEnabled");
4566 final long identity = Binder.clearCallingIdentity();
4567 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004568 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004569 // This setting doesn't require an active ImsService connection, so do not verify. The
4570 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004571 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004572 } catch (ImsException e) {
4573 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004574 } finally {
4575 Binder.restoreCallingIdentity(identity);
4576 }
4577 }
4578
shilu366312e2019-12-17 09:28:10 -08004579 /**
4580 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4581 * @param subId The subscription to use to check the configuration.
4582 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004583 @Override
4584 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004585 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004586 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004587 final long identity = Binder.clearCallingIdentity();
4588 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004589 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004590 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004591 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004592 } catch (ImsException e) {
4593 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004594 } finally {
4595 Binder.restoreCallingIdentity(identity);
4596 }
4597 }
4598
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004599 @Override
4600 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4601 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004602
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004603 final long identity = Binder.clearCallingIdentity();
4604 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004605 if (!isImsAvailableOnDevice()) {
4606 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4607 "IMS not available on device.");
4608 }
4609 int slotId = getSlotIndexOrException(subId);
4610 verifyImsMmTelConfiguredOrThrow(slotId);
4611 ImsManager.getInstance(mApp, slotId)
4612 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004613 } catch (ImsException e) {
4614 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004615 } finally {
4616 Binder.restoreCallingIdentity(identity);
4617 }
4618 }
4619
4620 @Override
4621 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4622 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004623
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004624 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004625 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4626 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4627 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004628 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004629 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004630 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004631 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004632 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4633 + "is inactive, ignoring unregister.");
4634 // If the subscription is no longer active, just return, since the callback will already
4635 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004636 } finally {
4637 Binder.restoreCallingIdentity(identity);
4638 }
4639 }
4640
joonhunshincffb7fc2021-11-28 07:32:01 +00004641 @Override
4642 public void registerFeatureProvisioningChangedCallback(int subId,
4643 IFeatureProvisioningCallback callback) {
4644 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4645 mApp, subId, "registerFeatureProvisioningChangedCallback");
4646
4647 final long identity = Binder.clearCallingIdentity();
4648 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4649 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4650 }
4651
joonhunshin91bc1952022-04-29 08:47:15 +00004652 try {
4653 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4654 if (controller == null) {
4655 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4656 "Device does not support IMS");
4657 }
4658 controller.addFeatureProvisioningChangedCallback(subId, callback);
4659 } finally {
4660 Binder.restoreCallingIdentity(identity);
4661 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004662 }
4663
4664 @Override
4665 public void unregisterFeatureProvisioningChangedCallback(int subId,
4666 IFeatureProvisioningCallback callback) {
4667 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4668 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4669
4670 final long identity = Binder.clearCallingIdentity();
4671 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4672 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4673 }
4674
joonhunshin91bc1952022-04-29 08:47:15 +00004675 try {
4676 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4677 if (controller == null) {
4678 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4679 return;
4680 }
4681 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4682 } finally {
4683 Binder.restoreCallingIdentity(identity);
4684 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004685 }
allenwtsu99c623b2020-01-03 18:24:23 +08004686
4687 private void checkModifyPhoneStatePermission(int subId, String message) {
4688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4689 message);
4690 }
4691
allenwtsu99c623b2020-01-03 18:24:23 +08004692 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004693 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004694 boolean isProvisioned) {
4695 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4696
4697 final long identity = Binder.clearCallingIdentity();
4698 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004699 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4700 if (controller == null) {
4701 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4702 return;
4703 }
4704 controller.setRcsProvisioningStatusForCapability(
4705 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004706 } finally {
4707 Binder.restoreCallingIdentity(identity);
4708 }
allenwtsu99c623b2020-01-03 18:24:23 +08004709 }
4710
4711
4712 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004713 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4714 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4715 mApp, subId, "getRcsProvisioningStatusForCapability");
4716
allenwtsu99c623b2020-01-03 18:24:23 +08004717 final long identity = Binder.clearCallingIdentity();
4718 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004719 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4720 if (controller == null) {
4721 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4722
4723 // device does not support IMS, this method will return true always.
4724 return true;
4725 }
4726 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004727 } finally {
4728 Binder.restoreCallingIdentity(identity);
4729 }
4730 }
4731
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004732 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004733 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4734 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004735 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004736
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004737 final long identity = Binder.clearCallingIdentity();
4738 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004739 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4740 if (controller == null) {
4741 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4742 return;
4743 }
4744 controller.setImsProvisioningStatusForCapability(
4745 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004746 } finally {
4747 Binder.restoreCallingIdentity(identity);
4748 }
4749 }
4750
4751 @Override
4752 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004753 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4754 mApp, subId, "getProvisioningStatusForCapability");
4755
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004756 final long identity = Binder.clearCallingIdentity();
4757 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004758 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4759 if (controller == null) {
4760 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004761
joonhunshin91bc1952022-04-29 08:47:15 +00004762 // device does not support IMS, this method will return true always.
4763 return true;
4764 }
4765 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004766 } finally {
4767 Binder.restoreCallingIdentity(identity);
4768 }
4769 }
4770
4771 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004772 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4773 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4774 mApp, subId, "isProvisioningRequiredForCapability");
4775
4776 final long identity = Binder.clearCallingIdentity();
4777 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004778 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4779 if (controller == null) {
4780 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4781
4782 // device does not support IMS, this method will return false
4783 return false;
4784 }
4785 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004786 } finally {
4787 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004788 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004789 }
4790
4791 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004792 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4793 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4794 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004795
joonhunshincffb7fc2021-11-28 07:32:01 +00004796 final long identity = Binder.clearCallingIdentity();
4797 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004798 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4799 if (controller == null) {
4800 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4801
4802 // device does not support IMS, this method will return false
4803 return false;
4804 }
4805 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004806 } finally {
4807 Binder.restoreCallingIdentity(identity);
4808 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004809 }
4810
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004811 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004812 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004813 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4814 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4815 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004816 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4817 mApp, subId, "getImsProvisioningInt");
4818
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004819 final long identity = Binder.clearCallingIdentity();
4820 try {
4821 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004822 int slotId = getSlotIndex(subId);
4823 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4824 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4825 + subId + "' for key:" + key);
4826 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4827 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004828
joonhunshin91bc1952022-04-29 08:47:15 +00004829 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4830 if (controller == null) {
4831 loge("getImsProvisioningInt: Device does not support IMS");
4832
4833 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4834 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4835 }
4836 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004837 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4838 return retVal;
4839 }
4840
calvinpanb5a34062021-02-08 19:59:36 +08004841 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004842 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004843 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4844 + subId + "' for key:" + key);
4845 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004846 } finally {
4847 Binder.restoreCallingIdentity(identity);
4848 }
4849 }
4850
4851 @Override
4852 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004853 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4854 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4855 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004856 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4857 mApp, subId, "getImsProvisioningString");
4858
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004859 final long identity = Binder.clearCallingIdentity();
4860 try {
4861 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004862 int slotId = getSlotIndex(subId);
4863 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4864 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4865 + subId + "' for key:" + key);
4866 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4867 }
calvinpanb5a34062021-02-08 19:59:36 +08004868 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004869 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004870 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4871 + subId + "' for key:" + key);
4872 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004873 } finally {
4874 Binder.restoreCallingIdentity(identity);
4875 }
4876 }
4877
4878 @Override
4879 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004880 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4881 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4882 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4884 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004885
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004886 final long identity = Binder.clearCallingIdentity();
4887 try {
4888 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004889 int slotId = getSlotIndex(subId);
4890 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4891 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4892 + subId + "' for key:" + key);
4893 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4894 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004895
joonhunshin91bc1952022-04-29 08:47:15 +00004896 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4897 if (controller == null) {
4898 loge("setImsProvisioningInt: Device does not support IMS");
4899
4900 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
4901 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4902 }
4903 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00004904 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4905 return retVal;
4906 }
4907
calvinpanb5a34062021-02-08 19:59:36 +08004908 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4909 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004910 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004911 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004912 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004913 } finally {
4914 Binder.restoreCallingIdentity(identity);
4915 }
4916 }
4917
4918 @Override
4919 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004920 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4921 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4922 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4924 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004925 final long identity = Binder.clearCallingIdentity();
4926 try {
4927 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004928 int slotId = getSlotIndex(subId);
4929 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4930 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4931 + subId + "' for key:" + key);
4932 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4933 }
calvinpanb5a34062021-02-08 19:59:36 +08004934 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4935 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004936 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004937 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004938 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004939 } finally {
4940 Binder.restoreCallingIdentity(identity);
4941 }
4942 }
4943
Brad Ebinger919631e2021-06-02 17:46:35 -07004944 /**
4945 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4946 * for the given slot ID or no ImsResolver instance has been created.
4947 * @param slotId The slot ID that the IMS service is created for.
4948 * @throws ImsException If there is no ImsService configured for this slot.
4949 */
4950 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4951 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4952 ImsFeature.FEATURE_MMTEL)) {
4953 throw new ImsException("This subscription does not support MMTEL over IMS",
4954 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4955 }
4956 }
4957
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004958 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004959 int slotId = SubscriptionManager.getSlotIndex(subId);
4960 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004961 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4962 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004963 }
4964 return slotId;
4965 }
4966
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004967 private int getSlotIndex(int subId) {
4968 int slotId = SubscriptionManager.getSlotIndex(subId);
4969 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4970 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4971 }
4972 return slotId;
4973 }
4974
Wink Saville36469e72014-06-11 15:17:00 -07004975 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004976 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004977 */
4978 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004979 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4980 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004981 try {
4982 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4983 } catch (SecurityException se) {
4984 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4985 throw new SecurityException("Package " + callingPackage + " does not belong to "
4986 + Binder.getCallingUid());
4987 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004988 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004989 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004990 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004991 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004992 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004993 mApp, subId, callingPackage, callingFeatureId,
4994 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004995 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4996 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004997
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 final long identity = Binder.clearCallingIdentity();
4999 try {
5000 final Phone phone = getPhone(subId);
5001 if (phone != null) {
5002 return phone.getServiceState().getDataNetworkType();
5003 } else {
5004 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5005 }
5006 } finally {
5007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005009 }
5010
5011 /**
5012 * Returns the data network type
5013 */
5014 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005015 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005016 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5017 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005018 }
5019
5020 /**
5021 * Returns the data network type for a subId
5022 */
5023 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005024 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5025 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005026 String functionName = "getDataNetworkTypeForSubscriber";
5027 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5028 mApp, functionName)) {
5029 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5030 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5031 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5032 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005033 }
5034
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005035 final long identity = Binder.clearCallingIdentity();
5036 try {
5037 final Phone phone = getPhone(subId);
5038 if (phone != null) {
5039 return phone.getServiceState().getDataNetworkType();
5040 } else {
5041 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5042 }
5043 } finally {
5044 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005045 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005046 }
5047
5048 /**
Wink Saville36469e72014-06-11 15:17:00 -07005049 * Returns the Voice network type for a subId
5050 */
5051 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005052 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5053 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005054 String functionName = "getVoiceNetworkTypeForSubscriber";
5055 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5056 mApp, functionName)) {
5057 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5058 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5059 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5060 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005061 }
5062
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063 final long identity = Binder.clearCallingIdentity();
5064 try {
5065 final Phone phone = getPhone(subId);
5066 if (phone != null) {
5067 return phone.getServiceState().getVoiceNetworkType();
5068 } else {
5069 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5070 }
5071 } finally {
5072 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005073 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005074 }
5075
5076 /**
5077 * @return true if a ICC card is present
5078 */
5079 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005080 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005081 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5082 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005083 }
5084
5085 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005086 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005087 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005088 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005089 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090 final long identity = Binder.clearCallingIdentity();
5091 try {
5092 final Phone phone = PhoneFactory.getPhone(slotIndex);
5093 if (phone != null) {
5094 return phone.getIccCard().hasIccCard();
5095 } else {
5096 return false;
5097 }
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005101 }
5102
5103 /**
5104 * Return if the current radio is LTE on CDMA. This
5105 * is a tri-state return value as for a period of time
5106 * the mode may be unknown.
5107 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005108 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005109 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005110 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005111 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005112 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005113 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5114 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5115 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005116 }
5117
Sanket Padawe356d7632015-06-22 14:03:32 -07005118 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005119 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5120 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005121 try {
5122 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5123 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005124 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5125 }
5126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005127 final long identity = Binder.clearCallingIdentity();
5128 try {
5129 final Phone phone = getPhone(subId);
5130 if (phone == null) {
5131 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5132 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005133 return TelephonyProperties.lte_on_cdma_device()
5134 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135 }
5136 } finally {
5137 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005138 }
Wink Saville36469e72014-06-11 15:17:00 -07005139 }
5140
Wink Saville36469e72014-06-11 15:17:00 -07005141 /**
5142 * {@hide}
5143 * Returns Default subId, 0 in the case of single standby.
5144 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005145 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005146 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005147 }
5148
Shishir Agrawala9f32182016-04-12 12:00:16 -07005149 private int getSlotForDefaultSubscription() {
5150 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5151 }
5152
Wink Savilleb564aae2014-10-23 10:18:09 -07005153 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005154 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005155 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005156
Pengquan Menge92a50d2018-09-21 15:54:48 -07005157 private boolean isActiveSubscription(int subId) {
5158 return mSubscriptionController.isActiveSubId(subId);
5159 }
5160
Ihab Awadf2177b72013-11-25 13:33:23 -08005161 /**
5162 * @see android.telephony.TelephonyManager.WifiCallingChoices
5163 */
5164 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005165 final long identity = Binder.clearCallingIdentity();
5166 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005167 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5169 getWhenToMakeWifiCallsDefaultPreference());
5170 } finally {
5171 Binder.restoreCallingIdentity(identity);
5172 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005173 }
5174
5175 /**
5176 * @see android.telephony.TelephonyManager.WifiCallingChoices
5177 */
5178 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 final long identity = Binder.clearCallingIdentity();
5180 try {
5181 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005182 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005183 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5184 } finally {
5185 Binder.restoreCallingIdentity(identity);
5186 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005187 }
5188
Sailesh Nepald1e68152013-12-12 19:08:02 -08005189 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005190 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005191 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005192 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005193
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005194 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5195 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5196 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005197 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005198 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5199 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005200 }
5201 return PhoneFactory.getPhone(phoneId);
5202 }
5203
Shishir Agrawal566b7612013-10-28 14:41:00 -07005204 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005205 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005206 @NonNull IccLogicalChannelRequest request) {
5207 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5208 /*message=*/ "iccOpenLogicalChannel");
5209
5210 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5211 // Verify that the callingPackage in the request belongs to the calling UID
5212 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5213
5214 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005215 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005216
Rambo Wanga1782702021-11-10 20:15:19 -08005217 private Phone getPhoneFromValidIccLogicalChannelRequest(
5218 @NonNull IccLogicalChannelRequest request, String message) {
5219 Phone phone;
5220 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5222 mApp, request.subId, message);
5223 phone = getPhoneFromSubId(request.subId);
5224 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5225 enforceModifyPermission();
5226 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5227 } else {
5228 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005229 }
Rambo Wanga1782702021-11-10 20:15:19 -08005230 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005231 }
5232
5233 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005234 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 final long identity = Binder.clearCallingIdentity();
5236 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005237 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005239 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5240 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005241 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5242 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 loge("The calling package is not allowed to access ISD-R.");
5244 throw new SecurityException(
5245 "The calling package is not allowed to access ISD-R.");
5246 }
Derek Tan740e1672017-06-27 14:56:27 -07005247 }
Derek Tan740e1672017-06-27 14:56:27 -07005248
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005249 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005250 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5251 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 return response;
5253 } finally {
5254 Binder.restoreCallingIdentity(identity);
5255 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005256 }
5257
5258 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005259 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5260 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5261 /*message=*/"iccCloseLogicalChannel");
5262
5263 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5264
5265 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005266 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005267
Rambo Wanga1782702021-11-10 20:15:19 -08005268 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5269 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005270 // before this feature is enabled, this API should only return false if
5271 // the operation fails instead of throwing runtime exception for
5272 // backward-compatibility.
5273 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5274 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 final long identity = Binder.clearCallingIdentity();
5276 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005277 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005278 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 }
Chen Xue9d737e2022-01-01 23:41:31 -08005280 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005281 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005282 Boolean success = false;
5283 if (result instanceof RuntimeException) {
5284 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005285 if (shouldThrowExceptionOnFailure) {
5286 throw (RuntimeException) result;
5287 } else {
5288 return false;
5289 }
Chen Xue9d737e2022-01-01 23:41:31 -08005290 } else if (result instanceof Boolean) {
5291 success = (Boolean) result;
5292 } else {
5293 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5294 }
Rambo Wanga1782702021-11-10 20:15:19 -08005295 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296 return success;
5297 } finally {
5298 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005299 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005300 }
5301
5302 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005303 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005304 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5306 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005307 if (DBG) {
5308 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5309 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5310 + p3 + " data=" + data);
5311 }
5312 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5313 command, p1, p2, p3, data);
5314 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005315
Jordan Liu4c733742019-02-28 12:03:40 -08005316 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005317 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5318 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005319 enforceModifyPermission();
5320 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005321 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5322 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5323 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005324 }
5325 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005326 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5327 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005328 }
5329
5330 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5331 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 final long identity = Binder.clearCallingIdentity();
5333 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005334 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 return "";
5336 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005339 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5340 null /* workSource */);
5341 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343 // Append the returned status code to the end of the response payload.
5344 String s = Integer.toHexString(
5345 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5346 if (response.payload != null) {
5347 s = IccUtils.bytesToHexString(response.payload) + s;
5348 }
5349 return s;
5350 } finally {
5351 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005352 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005353 }
Jake Hambye994d462014-02-03 13:10:13 -08005354
Evan Charltonc66da362014-05-16 14:06:40 -07005355 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005356 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5357 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5359 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005361 if (DBG) {
5362 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5363 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5364 }
5365 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5366 cla, command, p1, p2, p3, data);
5367 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005368
Jordan Liu4c733742019-02-28 12:03:40 -08005369 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005370 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5371 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005372 enforceModifyPermission();
5373 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5374 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005375 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5376 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5377 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005378 }
5379
5380 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005381 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5382 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005383 }
5384
5385 // open APDU basic channel assuming the caller has sufficient permissions
5386 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5387 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388 final long identity = Binder.clearCallingIdentity();
5389 try {
5390 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5391 && TextUtils.equals(ISDR_AID, data)) {
5392 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005393 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5394 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 if (bestComponent == null
5396 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5397 loge("The calling package is not allowed to select ISD-R.");
5398 throw new SecurityException(
5399 "The calling package is not allowed to select ISD-R.");
5400 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005401 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005404 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5405 null /* workSource */);
5406 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 // Append the returned status code to the end of the response payload.
5409 String s = Integer.toHexString(
5410 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5411 if (response.payload != null) {
5412 s = IccUtils.bytesToHexString(response.payload) + s;
5413 }
5414 return s;
5415 } finally {
5416 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005417 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005418 }
5419
5420 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005421 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005422 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5424 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 final long identity = Binder.clearCallingIdentity();
5427 try {
5428 if (DBG) {
5429 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5430 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5431 }
5432
5433 IccIoResult response =
5434 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5435 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5436 subId);
5437
5438 if (DBG) {
5439 log("Exchange SIM_IO [R]" + response);
5440 }
5441
5442 byte[] result = null;
5443 int length = 2;
5444 if (response.payload != null) {
5445 length = 2 + response.payload.length;
5446 result = new byte[length];
5447 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5448 } else {
5449 result = new byte[length];
5450 }
5451
5452 result[length - 1] = (byte) response.sw2;
5453 result[length - 2] = (byte) response.sw1;
5454 return result;
5455 } finally {
5456 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005457 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005458 }
5459
Nathan Haroldb3014052017-01-25 15:57:32 -08005460 /**
5461 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5462 * on a particular subscription
5463 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005464 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5465 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005467 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005468 return null;
5469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470
5471 final long identity = Binder.clearCallingIdentity();
5472 try {
5473 if (appType != TelephonyManager.APPTYPE_USIM
5474 && appType != TelephonyManager.APPTYPE_SIM) {
5475 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5476 return null;
5477 }
5478 Object response = sendRequest(
5479 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5480 if (response instanceof String[]) {
5481 return (String[]) response;
5482 }
yincheng zhao2737e882019-09-06 17:06:54 -07005483 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005485 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 } finally {
5487 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005488 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005489 }
5490
yincheng zhao2737e882019-09-06 17:06:54 -07005491 /**
5492 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5493 * subscription.
5494 *
5495 * @param subId the id of the subscription.
5496 * @param appType the uicc app type, must be USIM or SIM.
5497 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5498 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005499 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005500 * @return number of fplmns that is successfully written to the SIM.
5501 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005502 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5503 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5505 mApp, subId, "setForbiddenPlmns");
5506
yincheng zhao2737e882019-09-06 17:06:54 -07005507 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5508 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5509 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5510 }
5511 if (fplmns == null) {
5512 throw new IllegalArgumentException("Fplmn List provided is null");
5513 }
5514 for (String fplmn : fplmns) {
5515 if (!CellIdentity.isValidPlmn(fplmn)) {
5516 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5517 }
5518 }
5519 final long identity = Binder.clearCallingIdentity();
5520 try {
5521 Object response = sendRequest(
5522 CMD_SET_FORBIDDEN_PLMNS,
5523 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5524 subId);
5525 return (int) response;
5526 } finally {
5527 Binder.restoreCallingIdentity(identity);
5528 }
5529 }
5530
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005531 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005532 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5534 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005535
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536 final long identity = Binder.clearCallingIdentity();
5537 try {
5538 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5539 if (response.payload == null) {
5540 return "";
5541 }
Evan Charltonc66da362014-05-16 14:06:40 -07005542
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 // Append the returned status code to the end of the response payload.
5544 String s = Integer.toHexString(
5545 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5546 s = IccUtils.bytesToHexString(response.payload) + s;
5547 return s;
5548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
Evan Charltonc66da362014-05-16 14:06:40 -07005551 }
5552
Jake Hambye994d462014-02-03 13:10:13 -08005553 /**
5554 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5555 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5556 *
5557 * @param itemID the ID of the item to read
5558 * @return the NV item as a String, or null on error.
5559 */
5560 @Override
5561 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005562 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5564 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565
5566 final long identity = Binder.clearCallingIdentity();
5567 try {
5568 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005569 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5571 return value;
5572 } finally {
5573 Binder.restoreCallingIdentity(identity);
5574 }
Jake Hambye994d462014-02-03 13:10:13 -08005575 }
5576
5577 /**
5578 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5579 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5580 *
5581 * @param itemID the ID of the item to read
5582 * @param itemValue the value to write, as a String
5583 * @return true on success; false on any failure
5584 */
5585 @Override
5586 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005587 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5589 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590
5591 final long identity = Binder.clearCallingIdentity();
5592 try {
5593 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5594 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005595 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5597 return success;
5598 } finally {
5599 Binder.restoreCallingIdentity(identity);
5600 }
Jake Hambye994d462014-02-03 13:10:13 -08005601 }
5602
5603 /**
5604 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5605 * Used for device configuration by some CDMA operators.
5606 *
5607 * @param preferredRoamingList byte array containing the new PRL
5608 * @return true on success; false on any failure
5609 */
5610 @Override
5611 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5613 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614
5615 final long identity = Binder.clearCallingIdentity();
5616 try {
5617 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5618 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5619 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5620 return success;
5621 } finally {
5622 Binder.restoreCallingIdentity(identity);
5623 }
Jake Hambye994d462014-02-03 13:10:13 -08005624 }
5625
5626 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005627 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005628 * Used for device configuration by some CDMA operators.
5629 *
chen xu6dac5ab2018-10-26 17:39:23 -07005630 * @param slotIndex - device slot.
5631 *
Jake Hambye994d462014-02-03 13:10:13 -08005632 * @return true on success; false on any failure
5633 */
5634 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005635 public boolean resetModemConfig(int slotIndex) {
5636 Phone phone = PhoneFactory.getPhone(slotIndex);
5637 if (phone != null) {
5638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5639 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640
chen xu6dac5ab2018-10-26 17:39:23 -07005641 final long identity = Binder.clearCallingIdentity();
5642 try {
5643 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5644 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5645 return success;
5646 } finally {
5647 Binder.restoreCallingIdentity(identity);
5648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649 }
chen xu6dac5ab2018-10-26 17:39:23 -07005650 return false;
5651 }
5652
5653 /**
5654 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5655 *
5656 * @param slotIndex - device slot.
5657 *
5658 * @return true on success; false on any failure
5659 */
5660 @Override
5661 public boolean rebootModem(int slotIndex) {
5662 Phone phone = PhoneFactory.getPhone(slotIndex);
5663 if (phone != null) {
5664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5665 mApp, phone.getSubId(), "rebootModem");
5666
5667 final long identity = Binder.clearCallingIdentity();
5668 try {
5669 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5670 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5671 return success;
5672 } finally {
5673 Binder.restoreCallingIdentity(identity);
5674 }
5675 }
5676 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005677 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005678
Brad Ebinger51f743a2017-01-23 13:50:20 -08005679 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005680 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5681 * {@link #disableIms(int)}.
5682 * @param slotIndex device slot.
5683 */
5684 public void resetIms(int slotIndex) {
5685 enforceModifyPermission();
5686
5687 final long identity = Binder.clearCallingIdentity();
5688 try {
5689 if (mImsResolver == null) {
5690 // may happen if the does not support IMS.
5691 return;
5692 }
5693 mImsResolver.disableIms(slotIndex);
5694 mImsResolver.enableIms(slotIndex);
5695 } finally {
5696 Binder.restoreCallingIdentity(identity);
5697 }
5698 }
5699
5700 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005701 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5702 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005703 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005704 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005705 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706
5707 final long identity = Binder.clearCallingIdentity();
5708 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005709 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005710 // may happen if the device does not support IMS.
5711 return;
5712 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005713 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714 } finally {
5715 Binder.restoreCallingIdentity(identity);
5716 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005717 }
5718
5719 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005720 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5721 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005722 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005723 public void disableIms(int slotId) {
5724 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725
5726 final long identity = Binder.clearCallingIdentity();
5727 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005728 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005729 // may happen if the device does not support IMS.
5730 return;
5731 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005732 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733 } finally {
5734 Binder.restoreCallingIdentity(identity);
5735 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005736 }
5737
5738 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005739 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5740 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005741 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005742 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005743 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005744 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745
5746 final long identity = Binder.clearCallingIdentity();
5747 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005748 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005749 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5750 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005751 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005752 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005753 } finally {
5754 Binder.restoreCallingIdentity(identity);
5755 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005756 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005757 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005758 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5759 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005760 @Override
5761 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005762 enforceModifyPermission();
5763
5764 final long identity = Binder.clearCallingIdentity();
5765 try {
5766 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005767 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005768 } finally {
5769 Binder.restoreCallingIdentity(identity);
5770 }
5771 }
5772
5773 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005774 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005775 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005776 */
5777 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5778 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005779
5780 final long identity = Binder.clearCallingIdentity();
5781 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005782 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005783 // may happen if the device does not support IMS.
5784 return null;
5785 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005786 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 } finally {
5788 Binder.restoreCallingIdentity(identity);
5789 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005790 }
5791
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005792 /**
5793 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005794 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005795 */
5796 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798
5799 final long identity = Binder.clearCallingIdentity();
5800 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005801 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005802 // may happen if the device does not support IMS.
5803 return null;
5804 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005805 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 } finally {
5807 Binder.restoreCallingIdentity(identity);
5808 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005809 }
5810
Brad Ebinger884c07b2018-02-15 16:17:40 -08005811 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005812 * Sets the ImsService Package Name that Telephony will bind to.
5813 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005814 * @param slotIndex the slot ID that the ImsService should bind for.
5815 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005816 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005817 * @param featureTypes An integer array of feature types associated with a packageName.
5818 * @param packageName The name of the package that the current configuration will be replaced
5819 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005820 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005821 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005822 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5823 int[] featureTypes, String packageName) {
5824 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5825 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5827 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005828 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005829
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830 final long identity = Binder.clearCallingIdentity();
5831 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005832 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005833 // may happen if the device does not support IMS.
5834 return false;
5835 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005836 Map<Integer, String> featureConfig = new HashMap<>();
5837 for (int featureType : featureTypes) {
5838 featureConfig.put(featureType, packageName);
5839 }
5840 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5841 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 } finally {
5843 Binder.restoreCallingIdentity(identity);
5844 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005845 }
5846
5847 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005848 * Clears any carrier ImsService overrides for the slot index specified that were previously
5849 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5850 *
5851 * This should only be used for testing.
5852 *
5853 * @param slotIndex the slot ID that the ImsService should bind for.
5854 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5855 */
5856 @Override
5857 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5858 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5859 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5860 "clearCarrierImsServiceOverride");
5861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5862 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5863 "clearCarrierImsServiceOverride");
5864
5865 final long identity = Binder.clearCallingIdentity();
5866 try {
5867 if (mImsResolver == null) {
5868 // may happen if the device does not support IMS.
5869 return false;
5870 }
5871 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5872 } finally {
5873 Binder.restoreCallingIdentity(identity);
5874 }
5875 }
5876
5877 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005878 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005879 *
5880 * @param slotId The slot that the ImsService is associated with.
5881 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5882 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005883 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005884 * @return the package name of the ImsService configuration.
5885 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005886 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5887 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005888 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005889 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005890 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005891 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5892 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 final long identity = Binder.clearCallingIdentity();
5895 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005896 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005897 // may happen if the device does not support IMS.
5898 return "";
5899 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005900 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005901 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5902 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005906 }
5907
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005908 /**
5909 * Get the MmTelFeature state associated with the requested subscription id.
5910 * @param subId The subscription that the MmTelFeature is associated with.
5911 * @param callback A callback with an integer containing the
5912 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5913 */
5914 @Override
5915 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5916 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005917 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5918 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5919 "IMS not available on device.");
5920 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005921 final long token = Binder.clearCallingIdentity();
5922 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005923 int slotId = getSlotIndex(subId);
5924 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5925 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5926 + subId + "'");
5927 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5928 }
5929 verifyImsMmTelConfiguredOrThrow(slotId);
5930 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5931 try {
5932 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5933 } catch (RemoteException e) {
5934 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5935 + "Ignore");
5936 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005937 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005938 } catch (ImsException e) {
5939 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005940 } finally {
5941 Binder.restoreCallingIdentity(token);
5942 }
5943 }
5944
Daniel Brightbb5840b2021-01-12 15:48:18 -08005945 /**
5946 * Sets the ims registration state on all valid {@link Phone}s.
5947 */
5948 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005949 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950
5951 final long identity = Binder.clearCallingIdentity();
5952 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005953 // NOTE: Before S, this method only set the default phone.
5954 for (final Phone phone : PhoneFactory.getPhones()) {
5955 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5956 phone.setImsRegistrationState(registered);
5957 }
5958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005959 } finally {
5960 Binder.restoreCallingIdentity(identity);
5961 }
Wink Saville36469e72014-06-11 15:17:00 -07005962 }
5963
5964 /**
Stuart Scott54788802015-03-30 13:18:01 -07005965 * Set the network selection mode to automatic.
5966 *
5967 */
5968 @Override
5969 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5971 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972
5973 final long identity = Binder.clearCallingIdentity();
5974 try {
shilufc958392020-01-20 11:36:01 -08005975 if (!isActiveSubscription(subId)) {
5976 return;
5977 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005979 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5980 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 } finally {
5982 Binder.restoreCallingIdentity(identity);
5983 }
Stuart Scott54788802015-03-30 13:18:01 -07005984 }
5985
Jack Yud10cdd42020-09-28 20:28:01 -07005986 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005987 * Ask the radio to connect to the input network and change selection mode to manual.
5988 *
5989 * @param subId the id of the subscription.
5990 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5991 * the operator to attach to.
5992 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5993 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5994 * normal network selection next time.
5995 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005996 */
5997 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005998 public boolean setNetworkSelectionModeManual(
5999 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6001 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006002
6003 if (!isActiveSubscription(subId)) {
6004 return false;
6005 }
6006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 final long identity = Binder.clearCallingIdentity();
6008 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006009 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006011 if (DBG) {
6012 log("setNetworkSelectionModeManual: subId: " + subId
6013 + " operator: " + operatorInfo);
6014 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6016 } finally {
6017 Binder.restoreCallingIdentity(identity);
6018 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006019 }
shilu84f6e8b2019-12-19 13:58:01 -08006020 /**
6021 * Get the manual network selection
6022 *
6023 * @param subId the id of the subscription.
6024 *
6025 * @return the previously saved user selected PLMN
6026 */
6027 @Override
6028 public String getManualNetworkSelectionPlmn(int subId) {
6029 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006030 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006031 mApp, subId, "getManualNetworkSelectionPlmn");
6032
6033 final long identity = Binder.clearCallingIdentity();
6034 try {
6035 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006036 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006037 }
6038
6039 final Phone phone = getPhone(subId);
6040 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006041 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006042 }
6043 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6044 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6045 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6046 } finally {
6047 Binder.restoreCallingIdentity(identity);
6048 }
6049 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006050
6051 /**
6052 * Scans for available networks.
6053 */
6054 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006055 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6056 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6058 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006059 LocationAccessPolicy.LocationPermissionResult locationResult =
6060 LocationAccessPolicy.checkLocationPermission(mApp,
6061 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6062 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006063 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006064 .setCallingPid(Binder.getCallingPid())
6065 .setCallingUid(Binder.getCallingUid())
6066 .setMethod("getCellNetworkScanResults")
6067 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006068 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6069 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006070 .build());
6071 switch (locationResult) {
6072 case DENIED_HARD:
6073 throw new SecurityException("Not allowed to access scan results -- location");
6074 case DENIED_SOFT:
6075 return null;
6076 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077
Pengquan Menga1bb6272018-09-06 09:59:22 -07006078 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079 try {
6080 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006081 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083 } finally {
6084 Binder.restoreCallingIdentity(identity);
6085 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006086 }
6087
6088 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006089 * Get the call forwarding info, given the call forwarding reason.
6090 */
6091 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006092 public void getCallForwarding(int subId, int callForwardingReason,
6093 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006094 enforceReadPrivilegedPermission("getCallForwarding");
6095 long identity = Binder.clearCallingIdentity();
6096 try {
6097 if (DBG) {
6098 log("getCallForwarding: subId " + subId
6099 + " callForwardingReason" + callForwardingReason);
6100 }
Hall Liu27d24262020-09-18 19:04:59 -07006101
6102 Phone phone = getPhone(subId);
6103 if (phone == null) {
6104 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006105 callback.onError(
6106 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006107 } catch (RemoteException e) {
6108 // ignore
6109 }
6110 return;
6111 }
6112
6113 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6114 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6115 @Override
6116 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6117 try {
6118 callback.onCallForwardingInfoAvailable(info);
6119 } catch (RemoteException e) {
6120 // ignore
6121 }
6122 }
6123
6124 @Override
6125 public void onError(int error) {
6126 try {
6127 callback.onError(error);
6128 } catch (RemoteException e) {
6129 // ignore
6130 }
6131 }
6132 });
6133 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006134 } finally {
6135 Binder.restoreCallingIdentity(identity);
6136 }
6137 }
6138
6139 /**
6140 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6141 * reason, the number to forward, and the timeout before the forwarding is attempted.
6142 */
6143 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006144 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6145 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006146 enforceModifyPermission();
6147 long identity = Binder.clearCallingIdentity();
6148 try {
6149 if (DBG) {
6150 log("setCallForwarding: subId " + subId
6151 + " callForwardingInfo" + callForwardingInfo);
6152 }
Hall Liu27d24262020-09-18 19:04:59 -07006153
6154 Phone phone = getPhone(subId);
6155 if (phone == null) {
6156 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006157 callback.accept(
6158 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006159 } catch (RemoteException e) {
6160 // ignore
6161 }
6162 return;
6163 }
6164
6165 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6166 FunctionalUtils.ignoreRemoteException(callback::accept));
6167
6168 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006169 } finally {
6170 Binder.restoreCallingIdentity(identity);
6171 }
6172 }
6173
6174 /**
Hall Liu27d24262020-09-18 19:04:59 -07006175 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006176 */
6177 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006178 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006179 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006180 long identity = Binder.clearCallingIdentity();
6181 try {
Hall Liu27d24262020-09-18 19:04:59 -07006182 Phone phone = getPhone(subId);
6183 if (phone == null) {
6184 try {
6185 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6186 } catch (RemoteException e) {
6187 // ignore
6188 }
6189 return;
6190 }
SongFerngWang0e767992021-03-31 22:08:45 +08006191 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6192 PersistableBundle c = configManager.getConfigForSubId(subId);
6193 boolean requireUssd = c.getBoolean(
6194 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006195
Shuo Qian4a594052020-01-23 11:59:30 -08006196 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006197 if (requireUssd) {
6198 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6199 getSubscriptionCarrierId(subId));
6200 String newUssdCommand = "";
6201 try {
6202 newUssdCommand = carrierXmlParser.getFeature(
6203 CarrierXmlParser.FEATURE_CALL_WAITING)
6204 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6205 } catch (NullPointerException e) {
6206 loge("Failed to generate USSD number" + e);
6207 }
6208 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6209 mMainThreadHandler, callback, carrierXmlParser,
6210 CarrierXmlParser.SsEntry.SSAction.QUERY);
6211 final String ussdCommand = newUssdCommand;
6212 Executors.newSingleThreadExecutor().execute(() -> {
6213 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6214 });
6215 } else {
6216 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6217 callback::accept);
6218 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6219 }
Shuo Qian4a594052020-01-23 11:59:30 -08006220 } finally {
6221 Binder.restoreCallingIdentity(identity);
6222 }
6223 }
6224
6225 /**
Hall Liu27d24262020-09-18 19:04:59 -07006226 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006227 */
6228 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006229 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006230 enforceModifyPermission();
6231 long identity = Binder.clearCallingIdentity();
6232 try {
Hall Liu27d24262020-09-18 19:04:59 -07006233 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6234
6235 Phone phone = getPhone(subId);
6236 if (phone == null) {
6237 try {
6238 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6239 } catch (RemoteException e) {
6240 // ignore
6241 }
6242 return;
6243 }
6244
SongFerngWang0e767992021-03-31 22:08:45 +08006245 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6246 PersistableBundle c = configManager.getConfigForSubId(subId);
6247 boolean requireUssd = c.getBoolean(
6248 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006249
SongFerngWang0e767992021-03-31 22:08:45 +08006250 if (DBG) log("getCallWaitingStatus: subId " + subId);
6251 if (requireUssd) {
6252 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6253 getSubscriptionCarrierId(subId));
6254 CarrierXmlParser.SsEntry.SSAction ssAction =
6255 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6256 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6257 String newUssdCommand = "";
6258 try {
6259 newUssdCommand = carrierXmlParser.getFeature(
6260 CarrierXmlParser.FEATURE_CALL_WAITING)
6261 .makeCommand(ssAction, null);
6262 } catch (NullPointerException e) {
6263 loge("Failed to generate USSD number" + e);
6264 }
6265 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6266 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6267 final String ussdCommand = newUssdCommand;
6268 Executors.newSingleThreadExecutor().execute(() -> {
6269 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6270 });
6271 } else {
6272 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6273 FunctionalUtils.ignoreRemoteException(callback::accept));
6274
6275 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6276 }
Shuo Qian4a594052020-01-23 11:59:30 -08006277 } finally {
6278 Binder.restoreCallingIdentity(identity);
6279 }
6280 }
6281
6282 /**
yinxub1bed742017-04-17 11:45:04 -07006283 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006284 *
yinxub1bed742017-04-17 11:45:04 -07006285 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006286 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6287 * location related information which will be sent if the caller already possess
6288 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006289 * @param request contains the radio access networks with bands/channels to scan
6290 * @param messenger callback messenger for scan results or errors
6291 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006292 * @return the id of the requested scan which can be used to stop the scan.
6293 */
6294 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006295 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6296 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006297 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6299 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006300 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006301 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6302 if (!renounceFineLocationAccess) {
6303 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6304 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6305 .setCallingPackage(callingPackage)
6306 .setCallingFeatureId(callingFeatureId)
6307 .setCallingPid(Binder.getCallingPid())
6308 .setCallingUid(Binder.getCallingUid())
6309 .setMethod("requestNetworkScan")
6310 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6311 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6312 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6313 .build());
6314 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006315 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006316 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6317 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006318 if (e != null) {
6319 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6320 throw e;
6321 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006322 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006323 return TelephonyScanManager.INVALID_SCAN_ID;
6324 }
6325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006326 }
Hall Liu912dfd32019-04-25 14:02:26 -07006327 int callingUid = Binder.getCallingUid();
6328 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006329 final long identity = Binder.clearCallingIdentity();
6330 try {
6331 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006332 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006333 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006334 } finally {
6335 Binder.restoreCallingIdentity(identity);
6336 }
yinxu504e1392017-04-12 16:03:22 -07006337 }
6338
Hall Liub2ac8ef2019-02-28 15:56:23 -08006339 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006340 NetworkScanRequest request, int subId, String callingPackage) {
6341 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006342 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6343 boolean hasNetworkScanPermission =
6344 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6345 == PERMISSION_GRANTED;
6346
6347 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6348 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6349 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006350 }
6351
6352 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6353 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006354 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6355 return new SecurityException("Specific channels must not be"
6356 + " scanned without location access.");
6357 }
6358 }
6359 }
6360
Hall Liub2ac8ef2019-02-28 15:56:23 -08006361 return null;
6362 }
6363
yinxu504e1392017-04-12 16:03:22 -07006364 /**
6365 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006366 *
6367 * @param subId id of the subscription
6368 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006369 */
6370 @Override
6371 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6373 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374
Hall Liu912dfd32019-04-25 14:02:26 -07006375 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376 final long identity = Binder.clearCallingIdentity();
6377 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006378 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 } finally {
6380 Binder.restoreCallingIdentity(identity);
6381 }
yinxu504e1392017-04-12 16:03:22 -07006382 }
6383
6384 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006385 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006386 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006387 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006388 */
6389 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006390 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006391 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006392 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006393 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394
6395 final long identity = Binder.clearCallingIdentity();
6396 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006397 if (DBG) log("getAllowedNetworkTypesBitmask");
6398 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6399 int networkTypesBitmask = (result != null ? result[0] : -1);
6400 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6401 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 } finally {
6403 Binder.restoreCallingIdentity(identity);
6404 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006405 }
6406
6407 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006408 * Get the allowed network types for certain reason.
6409 *
6410 * @param subId the id of the subscription.
6411 * @param reason the reason the allowed network type change is taking place
6412 * @return the allowed network types.
6413 */
6414 @Override
6415 public long getAllowedNetworkTypesForReason(int subId,
6416 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006417 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006418 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006419 final long identity = Binder.clearCallingIdentity();
6420 try {
6421 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6422 } finally {
6423 Binder.restoreCallingIdentity(identity);
6424 }
6425 }
6426
6427 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006428 * Enable/Disable E-UTRA-NR Dual Connectivity
6429 * @param subId subscription id of the sim card
6430 * @param nrDualConnectivityState expected NR dual connectivity state
6431 * This can be passed following states
6432 * <ol>
6433 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6434 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6435 * <li>Disable NR dual connectivity and force secondary cell to be released
6436 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6437 * </ol>
6438 * @return operation result.
6439 */
6440 @Override
6441 public int setNrDualConnectivityState(int subId,
6442 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6444 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006445 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006446 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6447 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6448 }
6449
Sooraj Sasindran37444802020-08-11 10:40:43 -07006450 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6451 final long identity = Binder.clearCallingIdentity();
6452 try {
6453 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6454 nrDualConnectivityState, subId,
6455 workSource);
6456 if (DBG) log("enableNRDualConnectivity result: " + result);
6457 return result;
6458 } finally {
6459 Binder.restoreCallingIdentity(identity);
6460 }
6461 }
6462
6463 /**
6464 * Is E-UTRA-NR Dual Connectivity enabled
6465 * @return true if dual connectivity is enabled else false
6466 */
6467 @Override
6468 public boolean isNrDualConnectivityEnabled(int subId) {
6469 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006470 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006471 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006472 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006473 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6474 return false;
6475 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006476 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6477 final long identity = Binder.clearCallingIdentity();
6478 try {
6479 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6480 null, subId, workSource);
6481 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6482 return isEnabled;
6483 } finally {
6484 Binder.restoreCallingIdentity(identity);
6485 }
6486 }
6487
6488 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006489 * Set the allowed network types of the device and
6490 * provide the reason triggering the allowed network change.
6491 *
6492 * @param subId the id of the subscription.
6493 * @param reason the reason the allowed network type change is taking place
6494 * @param allowedNetworkTypes the allowed network types.
6495 * @return true on success; false on any failure.
6496 */
6497 @Override
6498 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006499 @TelephonyManager.AllowedNetworkTypesReason int reason,
6500 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6502 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006503 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006504 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6505 return false;
6506 }
6507 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6508 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006509 return false;
6510 }
6511
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006512 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6513 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6514
6515
6516 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6517 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6518 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006519 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006520
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006521 final long identity = Binder.clearCallingIdentity();
6522 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006523 Boolean success = (Boolean) sendRequest(
6524 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6525 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6526
6527 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6528 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006529 } finally {
6530 Binder.restoreCallingIdentity(identity);
6531 }
6532 }
6533
6534 /**
Miaoa84611c2019-03-15 09:21:10 +08006535 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006536 *
Miaoa84611c2019-03-15 09:21:10 +08006537 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006538 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006539 * @hide
6540 */
6541 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006542 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006543 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006545 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006546 try {
Miaoa84611c2019-03-15 09:21:10 +08006547 if (phone != null) {
6548 return phone.hasMatchedTetherApnSetting();
6549 } else {
6550 return false;
6551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552 } finally {
6553 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006554 }
Junda Liu475951f2014-11-07 16:45:03 -08006555 }
6556
6557 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006558 * Get the user enabled state of Mobile Data.
6559 *
6560 * TODO: remove and use isUserDataEnabled.
6561 * This can't be removed now because some vendor codes
6562 * calls through ITelephony directly while they should
6563 * use TelephonyManager.
6564 *
6565 * @return true on enabled
6566 */
6567 @Override
6568 public boolean getDataEnabled(int subId) {
6569 return isUserDataEnabled(subId);
6570 }
6571
6572 /**
6573 * Get whether mobile data is enabled per user setting.
6574 *
6575 * There are other factors deciding whether mobile data is actually enabled, but they are
6576 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006577 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006578 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6579 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006580 *
6581 * @return {@code true} if data is enabled else {@code false}
6582 */
6583 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006584 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006585 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006586 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006587 try {
6588 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6589 functionName);
6590 } catch (Exception e) {
6591 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6592 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006593 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006595 mApp, subId, functionName);
6596
Robert Greenwalt646120a2014-05-23 11:54:03 -07006597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598
6599 final long identity = Binder.clearCallingIdentity();
6600 try {
6601 int phoneId = mSubscriptionController.getPhoneId(subId);
6602 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6603 Phone phone = PhoneFactory.getPhone(phoneId);
6604 if (phone != null) {
6605 boolean retVal = phone.isUserDataEnabled();
6606 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6607 return retVal;
6608 } else {
6609 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6610 return false;
6611 }
6612 } finally {
6613 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006614 }
6615 }
6616
6617 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006618 * Checks if the device is capable of mobile data by considering whether whether the
6619 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6620 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006621 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006622 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006623 */
6624 @Override
6625 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006626 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006627 try {
6628 try {
6629 mApp.enforceCallingOrSelfPermission(
6630 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006631 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006632 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006633 try {
6634 mApp.enforceCallingOrSelfPermission(
6635 android.Manifest.permission.READ_PHONE_STATE,
6636 functionName);
6637 } catch (Exception e2) {
6638 mApp.enforceCallingOrSelfPermission(
6639 permission.READ_BASIC_PHONE_STATE, functionName);
6640 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006641 }
6642 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006643 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645
6646 final long identity = Binder.clearCallingIdentity();
6647 try {
6648 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649 Phone phone = PhoneFactory.getPhone(phoneId);
6650 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006651 boolean retVal;
6652 if (phone.isUsingNewDataStack()) {
Sarah Chin2c094c52022-03-09 13:57:52 -08006653 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006654 } else {
6655 retVal = phone.getDataEnabledSettings().isDataEnabled();
6656 }
6657 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006658 return retVal;
6659 } else {
6660 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6661 return false;
6662 }
6663 } finally {
6664 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006665 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006666 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006667
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006668 /**
6669 * Check if data is enabled for a specific reason
6670 * @param subId Subscription index
6671 * @param reason the reason the data enable change is taking place
6672 * @return {@code true} if the overall data is enabled; {@code false} if not.
6673 */
6674 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006675 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006676 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006677 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006678 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006679 try {
6680 mApp.enforceCallingOrSelfPermission(
6681 android.Manifest.permission.ACCESS_NETWORK_STATE,
6682 functionName);
6683 } catch (Exception e) {
6684 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6685 functionName);
6686 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006687 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006688 try {
6689 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006690 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006691 } catch (Exception e2) {
6692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006693 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006694 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006695 }
6696
6697
6698 final long identity = Binder.clearCallingIdentity();
6699 try {
6700 int phoneId = mSubscriptionController.getPhoneId(subId);
6701 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006702 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006703 + " reason=" + reason);
6704 }
6705 Phone phone = PhoneFactory.getPhone(phoneId);
6706 if (phone != null) {
6707 boolean retVal;
Jack Yu99e87332021-12-17 23:14:15 -08006708 if (phone.isUsingNewDataStack()) {
6709 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006710 } else {
Jack Yu99e87332021-12-17 23:14:15 -08006711 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6712 retVal = phone.isUserDataEnabled();
6713 } else {
6714 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6715 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006716 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006717 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006718 return retVal;
6719 } else {
6720 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006721 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006722 + subId + " retVal=false");
6723 }
6724 return false;
6725 }
6726 } finally {
6727 Binder.restoreCallingIdentity(identity);
6728 }
6729 }
6730
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006731 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006732 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006733 // No permission needed; this only lets the caller inspect their own status.
6734 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006735 }
Junda Liu29340342014-07-10 15:23:27 -07006736
6737 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006738 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006739 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006740 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6741 }
6742
6743 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6744 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006745 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006746 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006747 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6748 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006749 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6750 if (cpt == null) {
6751 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006752 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6753 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006754 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006755 }
6756
6757 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006758 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006759 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006760 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006761 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006762 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006763 Phone phone = getPhone(subId);
6764 if (phone == null) {
6765 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6766 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6767 }
6768 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6769 if (cpt == null) {
6770 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006771 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6772 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006773 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006774 }
6775
6776 @Override
6777 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006778 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006779 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6780 }
6781
6782 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006783 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006784 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006785 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006786 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006787 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6788 Phone phone = PhoneFactory.getPhone(phoneId);
6789 if (phone == null) {
6790 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006791 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006792 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6793 if (cpt == null) {
6794 continue;
6795 }
6796 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006797 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6798 break;
6799 }
6800 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006801 return result;
Junda Liu29340342014-07-10 15:23:27 -07006802 }
Derek Tan89e89d42014-07-08 17:00:10 -07006803
6804 @Override
Junda Liue64de782015-04-16 17:19:16 -07006805 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006806 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006807 Phone phone = PhoneFactory.getPhone(phoneId);
6808 if (phone == null) {
6809 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006810 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006811 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6812 if (cpt == null) {
6813 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006814 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006815 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006816 }
6817
Amith Yamasani6e118872016-02-19 12:53:51 -08006818 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006819 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006820 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006821 Phone phone = PhoneFactory.getPhone(phoneId);
6822 if (phone == null) {
6823 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006824 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006825 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6826 if (cpt == null) {
6827 return Collections.emptyList();
6828 }
6829 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006830 }
6831
chen xuf7e9fe82019-05-09 19:31:02 -07006832 @Override
6833 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006834 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006835 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006836 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006837 try {
6838 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6839 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6840 }
6841 } finally {
6842 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006843 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006844 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006845 }
6846
Rambo Wang6812ffb2022-03-15 16:54:17 -07006847 @Override
6848 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6849 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6850
6851 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6852 if (phone == null) {
6853 return null;
6854 }
6855 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6856 if (cpt == null) {
6857 return null;
6858 }
6859 return cpt.getCarrierServicePackageName();
6860 }
6861
Wink Savilleb564aae2014-10-23 10:18:09 -07006862 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006863 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006864 UiccPort port = phone == null ? null : phone.getUiccPort();
6865 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006866 return null;
6867 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006868 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006869 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006870 return null;
6871 }
6872 return iccId;
6873 }
6874
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006875 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006876 public void setCallComposerStatus(int subId, int status) {
6877 enforceModifyPermission();
6878
6879 final long identity = Binder.clearCallingIdentity();
6880 try {
6881 Phone phone = getPhone(subId);
6882 if (phone != null) {
6883 Phone defaultPhone = phone.getImsPhone();
6884 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6885 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6886 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006887 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6888 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006889 }
6890 }
Shuo Qian284ae752020-12-22 19:10:14 -08006891 } catch (ImsException e) {
6892 throw new ServiceSpecificException(e.getCode());
6893 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006894 Binder.restoreCallingIdentity(identity);
6895 }
6896 }
6897
6898 @Override
6899 public int getCallComposerStatus(int subId) {
6900 enforceReadPrivilegedPermission("getCallComposerStatus");
6901
6902 final long identity = Binder.clearCallingIdentity();
6903 try {
6904 Phone phone = getPhone(subId);
6905 if (phone != null) {
6906 Phone defaultPhone = phone.getImsPhone();
6907 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6908 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6909 return imsPhone.getCallComposerStatus();
6910 }
6911 }
6912 } finally {
6913 Binder.restoreCallingIdentity(identity);
6914 }
6915 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6916 }
6917
6918 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006919 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6920 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006921 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006922 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006923
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006924 final long identity = Binder.clearCallingIdentity();
6925 try {
6926 final String iccId = getIccId(subId);
6927 final Phone phone = getPhone(subId);
6928 if (phone == null) {
6929 return false;
6930 }
6931 final String subscriberId = phone.getSubscriberId();
6932
6933 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006934 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006935 + subscriberId + " to " + number);
6936 }
6937
6938 if (TextUtils.isEmpty(iccId)) {
6939 return false;
6940 }
6941
6942 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6943
6944 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6945 if (alphaTag == null) {
6946 editor.remove(alphaTagPrefKey);
6947 } else {
6948 editor.putString(alphaTagPrefKey, alphaTag);
6949 }
6950
6951 // Record both the line number and IMSI for this ICCID, since we need to
6952 // track all merged IMSIs based on line number
6953 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6954 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6955 if (number == null) {
6956 editor.remove(numberPrefKey);
6957 editor.remove(subscriberPrefKey);
6958 } else {
6959 editor.putString(numberPrefKey, number);
6960 editor.putString(subscriberPrefKey, subscriberId);
6961 }
6962
6963 editor.commit();
6964 return true;
6965 } finally {
6966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006967 }
Derek Tan7226c842014-07-02 17:42:23 -07006968 }
6969
6970 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006971 public String getLine1NumberForDisplay(int subId, String callingPackage,
6972 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006973 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006974 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006975 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006976 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006977 return null;
6978 }
Derek Tan97ebb422014-09-05 16:55:38 -07006979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006980 final long identity = Binder.clearCallingIdentity();
6981 try {
6982 String iccId = getIccId(subId);
6983 if (iccId != null) {
6984 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6985 if (DBG_MERGE) {
6986 log("getLine1NumberForDisplay returning "
6987 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6988 }
6989 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006990 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006991 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6992 return null;
6993 } finally {
6994 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006995 }
Derek Tan7226c842014-07-02 17:42:23 -07006996 }
6997
6998 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006999 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7000 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007001 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007002 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007003 return null;
7004 }
Derek Tan97ebb422014-09-05 16:55:38 -07007005
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007006 final long identity = Binder.clearCallingIdentity();
7007 try {
7008 String iccId = getIccId(subId);
7009 if (iccId != null) {
7010 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7011 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7012 }
7013 return null;
7014 } finally {
7015 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007016 }
Derek Tan7226c842014-07-02 17:42:23 -07007017 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007018
7019 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007020 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7021 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007022 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7023 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007024 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007025 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007026 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007027 return null;
7028 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007029
Jordan Liub49b04b2019-05-06 14:45:15 -07007030 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7031 // the process, where TelephonyManager was instantiated.
7032 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007033 final long identity = Binder.clearCallingIdentity();
7034 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007035 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007036 final TelephonyManager tele = TelephonyManager.from(context);
7037 final SubscriptionManager sub = SubscriptionManager.from(context);
7038
7039 // Figure out what subscribers are currently active
7040 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041
Jordan Liub49b04b2019-05-06 14:45:15 -07007042 // Only consider subs which match the current subId
7043 // This logic can be simplified. See b/131189269 for progress.
7044 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007045 activeSubscriberIds.add(tele.getSubscriberId(subId));
7046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007047
7048 // First pass, find a number override for an active subscriber
7049 String mergeNumber = null;
7050 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7051 for (String key : prefs.keySet()) {
7052 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7053 final String subscriberId = (String) prefs.get(key);
7054 if (activeSubscriberIds.contains(subscriberId)) {
7055 final String iccId = key.substring(
7056 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7057 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7058 mergeNumber = (String) prefs.get(numberKey);
7059 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007060 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007061 + " for active subscriber " + subscriberId);
7062 }
7063 if (!TextUtils.isEmpty(mergeNumber)) {
7064 break;
7065 }
7066 }
7067 }
7068 }
7069
7070 // Shortcut when no active merged subscribers
7071 if (TextUtils.isEmpty(mergeNumber)) {
7072 return null;
7073 }
7074
7075 // Second pass, find all subscribers under that line override
7076 final ArraySet<String> result = new ArraySet<>();
7077 for (String key : prefs.keySet()) {
7078 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7079 final String number = (String) prefs.get(key);
7080 if (mergeNumber.equals(number)) {
7081 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7082 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7083 final String subscriberId = (String) prefs.get(subscriberKey);
7084 if (!TextUtils.isEmpty(subscriberId)) {
7085 result.add(subscriberId);
7086 }
7087 }
7088 }
7089 }
7090
7091 final String[] resultArray = result.toArray(new String[result.size()]);
7092 Arrays.sort(resultArray);
7093 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007094 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7096 }
7097 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007098 } finally {
7099 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007100 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007101 }
7102
7103 @Override
zoey chen38003472019-12-13 17:16:31 +08007104 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7105 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007106
7107 final long identity = Binder.clearCallingIdentity();
7108 try {
7109 final TelephonyManager telephonyManager = mApp.getSystemService(
7110 TelephonyManager.class);
7111 String subscriberId = telephonyManager.getSubscriberId(subId);
7112 if (subscriberId == null) {
7113 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007114 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007115 + subId);
7116 }
7117 return null;
7118 }
7119
7120 final SubscriptionInfo info = SubscriptionController.getInstance()
7121 .getSubscriptionInfo(subId);
7122 final ParcelUuid groupUuid = info.getGroupUuid();
7123 // If it doesn't belong to any group, return just subscriberId of itself.
7124 if (groupUuid == null) {
7125 return new String[]{subscriberId};
7126 }
7127
7128 // Get all subscriberIds from the group.
7129 final List<String> mergedSubscriberIds = new ArrayList<>();
7130 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007131 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007132 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007133 for (SubscriptionInfo subInfo : groupInfos) {
7134 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7135 if (subscriberId != null) {
7136 mergedSubscriberIds.add(subscriberId);
7137 }
7138 }
7139
7140 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7141 } finally {
7142 Binder.restoreCallingIdentity(identity);
7143
7144 }
7145 }
7146
7147 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007148 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007149 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007150 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151
7152 final long identity = Binder.clearCallingIdentity();
7153 try {
7154 final Phone phone = getPhone(subId);
7155 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7156 } finally {
7157 Binder.restoreCallingIdentity(identity);
7158 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007159 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007160
7161 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007162 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007163 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7164 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007165 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7166 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007167
7168 final long identity = Binder.clearCallingIdentity();
7169 try {
7170 final Phone phone = getPhone(subId);
7171 if (phone == null) {
7172 return false;
7173 }
7174 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7175 cdmaNonRoamingList);
7176 } finally {
7177 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007178 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007179 }
7180
7181 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007182 @Deprecated
7183 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7184 enforceModifyPermission();
7185
7186 int returnValue = 0;
7187 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007188 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007189 if(result.exception == null) {
7190 if (result.result != null) {
7191 byte[] responseData = (byte[])(result.result);
7192 if(responseData.length > oemResp.length) {
7193 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7194 responseData.length + "bytes. Buffer Size is " +
7195 oemResp.length + "bytes.");
7196 }
7197 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7198 returnValue = responseData.length;
7199 }
7200 } else {
7201 CommandException ex = (CommandException) result.exception;
7202 returnValue = ex.getCommandError().ordinal();
7203 if(returnValue > 0) returnValue *= -1;
7204 }
7205 } catch (RuntimeException e) {
7206 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7207 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7208 if(returnValue > 0) returnValue *= -1;
7209 }
7210
7211 return returnValue;
7212 }
7213
7214 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007215 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007216 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007217 try {
7218 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007219 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007220 mApp, phone.getSubId(), "getRadioAccessFamily");
7221 } catch (SecurityException e) {
7222 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7223 throw e;
7224 }
chen xub97461a2018-10-26 14:17:57 -07007225 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007226 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007227 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007229 final long identity = Binder.clearCallingIdentity();
7230 try {
chen xub97461a2018-10-26 14:17:57 -07007231 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007232 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007233 mApp, phone.getSubId(), "getRadioAccessFamily");
7234 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 } finally {
7236 Binder.restoreCallingIdentity(identity);
7237 }
chen xub97461a2018-10-26 14:17:57 -07007238 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007239 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007240
7241 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007242 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007243 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007244 try {
7245 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7246 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007247 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007248 }
7249 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007250 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007251 }
7252 RoleManager rm = mApp.getSystemService(RoleManager.class);
7253 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7254 if (!dialerRoleHolders.contains(callingPackage)) {
7255 throw new SecurityException("App must be the dialer role holder to"
7256 + " upload a call composer pic");
7257 }
7258
7259 Executors.newSingleThreadExecutor().execute(() -> {
7260 ByteArrayOutputStream output = new ByteArrayOutputStream(
7261 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7262 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7263 boolean readUntilEnd = false;
7264 int totalBytesRead = 0;
7265 byte[] buffer = new byte[16 * 1024];
7266 while (true) {
7267 int numRead;
7268 try {
7269 numRead = input.read(buffer);
7270 } catch (IOException e) {
7271 try {
7272 fd.checkError();
7273 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7274 null);
7275 } catch (IOException e1) {
7276 // This means that the other side closed explicitly with an error. If this
7277 // happens, log and ignore.
7278 loge("Remote end of call composer picture pipe closed: " + e1);
7279 }
7280 break;
7281 }
7282 if (numRead == -1) {
7283 readUntilEnd = true;
7284 break;
7285 }
7286 totalBytesRead += numRead;
7287 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7288 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7289 try {
7290 input.close();
7291 } catch (IOException e) {
7292 // ignore
7293 }
7294 break;
7295 }
7296 output.write(buffer, 0, numRead);
7297 }
7298 // Generally, the remote end will close the file descriptors. The only case where we
7299 // close is above, where the picture size is too big.
7300
7301 try {
7302 fd.checkError();
7303 } catch (IOException e) {
7304 loge("Remote end for call composer closed with an error: " + e);
7305 return;
7306 }
7307
Hall Liuaa4211e2021-01-20 15:43:39 -08007308 if (!readUntilEnd) {
7309 loge("Did not finish reading entire image; aborting");
7310 return;
7311 }
Hall Liu82694d52020-12-11 18:22:04 -08007312
Hall Liuaa4211e2021-01-20 15:43:39 -08007313 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7314 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7315 new CallComposerPictureTransfer.Factory() {},
7316 imageData,
7317 (result) -> {
7318 if (result.first != null) {
7319 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7320 Bundle outputResult = new Bundle();
7321 outputResult.putParcelable(
7322 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7323 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7324 outputResult);
7325 } else {
7326 callback.send(result.second, null);
7327 }
7328 }
7329 );
Hall Liu82694d52020-12-11 18:22:04 -08007330 });
7331 }
7332
7333 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007334 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007335 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007336 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337
7338 final long identity = Binder.clearCallingIdentity();
7339 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007340 ImsManager.getInstance(defaultPhone.getContext(),
7341 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007342 } finally {
7343 Binder.restoreCallingIdentity(identity);
7344 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007345 }
7346
7347 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007348 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007349 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007350 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7351 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007352 return false;
7353 }
Svet Ganovb320e182015-04-16 12:30:10 -07007354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007355 final long identity = Binder.clearCallingIdentity();
7356 try {
7357 // Check the user preference and the system-level IMS setting. Even if the user has
7358 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7359 // In the long run, we may instead need to check if there exists a connection service
7360 // which can support video calling.
7361 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007362 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363 return imsManager.isVtEnabledByPlatform()
7364 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7365 && imsManager.isVtEnabledByUser();
7366 } finally {
7367 Binder.restoreCallingIdentity(identity);
7368 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007369 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007370
Andrew Leea1239f22015-03-02 17:44:07 -08007371 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007372 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7373 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007375 mApp, subId, callingPackage, callingFeatureId,
7376 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 return false;
7378 }
7379
7380 final long identity = Binder.clearCallingIdentity();
7381 try {
7382 CarrierConfigManager configManager =
7383 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007384 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7386 } finally {
7387 Binder.restoreCallingIdentity(identity);
7388 }
Andrew Leea1239f22015-03-02 17:44:07 -08007389 }
7390
7391 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007392 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007394 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007395 return false;
7396 }
7397
7398 final long identity = Binder.clearCallingIdentity();
7399 try {
7400 CarrierConfigManager configManager =
7401 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007402 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007403 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7404 } finally {
7405 Binder.restoreCallingIdentity(identity);
7406 }
Andrew Leea1239f22015-03-02 17:44:07 -08007407 }
7408
Andrew Lee9431b832015-03-09 18:46:45 -07007409 @Override
7410 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007411 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007412 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007413 }
7414
7415 @Override
7416 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007417 final long identity = Binder.clearCallingIdentity();
7418 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007419 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420 } finally {
7421 Binder.restoreCallingIdentity(identity);
7422 }
Andrew Lee9431b832015-03-09 18:46:45 -07007423 }
7424
Hall Liuf6668912018-10-31 17:05:23 -07007425 /**
7426 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7427 * support for the feature and device firmware support.
7428 *
7429 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7430 */
7431 @Override
7432 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007433 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007434 final Phone phone = getPhone(subscriptionId);
7435 if (phone == null) {
7436 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7437 return false;
7438 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007440 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7442 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007443 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 return isCarrierSupported && isDeviceSupported;
7445 } finally {
7446 Binder.restoreCallingIdentity(identity);
7447 }
Hall Liu98187582018-01-22 19:15:32 -08007448 }
7449
Hall Liuf6668912018-10-31 17:05:23 -07007450 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007451 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7452 * RTT setting, will return true if the device and carrier both support RTT.
7453 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007454 */
7455 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 final long identity = Binder.clearCallingIdentity();
7457 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007458 boolean isRttSupported = isRttSupported(subscriptionId);
7459 boolean isUserRttSettingOn = Settings.Secure.getInt(
7460 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7461 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7462 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7463 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 } finally {
7465 Binder.restoreCallingIdentity(identity);
7466 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007467 }
7468
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007469 @Deprecated
7470 @Override
7471 public String getDeviceId(String callingPackage) {
7472 return getDeviceIdWithFeature(callingPackage, null);
7473 }
7474
Sanket Padawe7310cc72015-01-14 09:53:20 -08007475 /**
7476 * Returns the unique device ID of phone, for example, the IMEI for
7477 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7478 *
7479 * <p>Requires Permission:
7480 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7481 */
7482 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007483 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007484 try {
7485 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7486 } catch (SecurityException se) {
7487 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7488 throw new SecurityException("Package " + callingPackage + " does not belong to "
7489 + Binder.getCallingUid());
7490 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007491 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007492 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007493 return null;
7494 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007495 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007496 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007497 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007498 return null;
7499 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500
7501 final long identity = Binder.clearCallingIdentity();
7502 try {
7503 return phone.getDeviceId();
7504 } finally {
7505 Binder.restoreCallingIdentity(identity);
7506 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007507 }
7508
Ping Sunc67b7c22016-03-02 19:16:45 +08007509 /**
7510 * {@hide}
7511 * Returns the IMS Registration Status on a particular subid
7512 *
7513 * @param subId
7514 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007515 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007516 Phone phone = getPhone(subId);
7517 if (phone != null) {
7518 return phone.isImsRegistered();
7519 } else {
7520 return false;
7521 }
7522 }
7523
Santos Cordon7a1885b2015-02-03 11:15:19 -08007524 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007525 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007526 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007527 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007528 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007529 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7530 }
7531 final long identity = Binder.clearCallingIdentity();
7532 try {
7533 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7534 } finally {
7535 Binder.restoreCallingIdentity(identity);
7536 }
7537 }
7538
7539 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007540 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007541 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007542 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007543 mApp,
7544 subscriptionId,
7545 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007546 final long identity = Binder.clearCallingIdentity();
7547 try {
7548 Phone phone = getPhone(subscriptionId);
7549 if (phone == null) {
7550 return null;
7551 }
7552 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7553 } finally {
7554 Binder.restoreCallingIdentity(identity);
7555 }
7556 }
7557
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007558 /**
7559 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007560 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007561 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562 final long identity = Binder.clearCallingIdentity();
7563 try {
7564 Phone phone = getPhone(subId);
7565 if (phone != null) {
7566 return phone.isWifiCallingEnabled();
7567 } else {
7568 return false;
7569 }
7570 } finally {
7571 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007572 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007573 }
7574
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007575 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007576 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007577 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007578 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579 final long identity = Binder.clearCallingIdentity();
7580 try {
7581 Phone phone = getPhone(subId);
7582 if (phone != null) {
7583 return phone.isVideoEnabled();
7584 } else {
7585 return false;
7586 }
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007589 }
7590 }
7591
7592 /**
7593 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7594 * defined in {@link ImsRegistrationImplBase}.
7595 */
7596 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007597 final long identity = Binder.clearCallingIdentity();
7598 try {
7599 Phone phone = getPhone(subId);
7600 if (phone != null) {
7601 return phone.getImsRegistrationTech();
7602 } else {
7603 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7604 }
7605 } finally {
7606 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007607 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007608 }
7609
Stuart Scott8eef64f2015-04-08 15:13:54 -07007610 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007611 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007612 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007613 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7614 return;
7615 }
Kai Shif70f46f2021-03-03 13:59:46 -08007616 Phone defaultPhone = getDefaultPhone();
7617 if (defaultPhone != null) {
7618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7619 mApp, getDefaultPhone().getSubId(), "factoryReset");
7620 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007621 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007622
Svet Ganovcc087f82015-05-12 20:35:54 -07007623 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007624 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7625 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007626 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007627 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007628 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007629 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007630 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007631 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007632 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007633 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007634 // There has been issues when Sms raw table somehow stores orphan
7635 // fragments. They lead to garbled message when new fragments come
7636 // in and combined with those stale ones. In case this happens again,
7637 // user can reset all network settings which will clean up this table.
7638 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007639 // Clean up IMS settings as well here.
7640 int slotId = getSlotIndex(subId);
7641 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7642 ImsManager.getInstance(mApp, slotId).factoryReset();
7643 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007644
Kai Shif70f46f2021-03-03 13:59:46 -08007645 if (defaultPhone == null) {
7646 return;
7647 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007648 // Erase modem config if erase modem on network setting is enabled.
7649 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7650 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7651 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007652 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007653 }
Kai Shif70f46f2021-03-03 13:59:46 -08007654
7655 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007656 } finally {
7657 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007658 }
7659 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007660
SongFerngWangfd89b102021-05-27 22:44:54 +08007661 @VisibleForTesting
7662 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7663 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7664 return;
7665 }
7666 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7667 RILConstants.PREFERRED_NETWORK_MODE);
7668 SubscriptionManager.setSubscriptionProperty(subId,
7669 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7670 "user=" + defaultNetworkType);
7671 phone.loadAllowedNetworksFromSubscriptionDatabase();
7672 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7673 defaultNetworkType, null);
7674 }
7675
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007676 private void cleanUpSmsRawTable(Context context) {
7677 ContentResolver resolver = context.getContentResolver();
7678 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7679 resolver.delete(uri, null, null);
7680 }
7681
Narayan Kamath1c496c22015-04-16 14:40:19 +01007682 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007683 public String getSimLocaleForSubscriber(int subId) {
7684 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7685 final Phone phone = getPhone(subId);
7686 if (phone == null) {
7687 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007688 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 final long identity = Binder.clearCallingIdentity();
7691 try {
chen xu5d3637b2019-01-21 23:31:38 -08007692 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007693 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007694 if (info == null) {
7695 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7696 return null;
7697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698 // Try and fetch the locale from the carrier properties or from the SIM language
7699 // preferences (EF-PL and EF-LI)...
7700 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007702 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7703 if (localeFromDefaultSim != null) {
7704 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7705 if (DBG) log("Using locale from subId: " + subId + " locale: "
7706 + localeFromDefaultSim);
tom hsu0b59d292022-09-29 23:49:21 +08007707 return matchLocaleFromSupportedLocaleList(localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007708 } else {
7709 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710 }
7711 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007713 // The SIM language preferences only store a language (e.g. fr = French), not an
7714 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7715 // the SIM and carrier preferences does not include a country we add the country
7716 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007717 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007718 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007719 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu0b59d292022-09-29 23:49:21 +08007720 return matchLocaleFromSupportedLocaleList(mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007721 }
7722
7723 if (DBG) log("No locale found - returning null");
7724 return null;
7725 } finally {
7726 Binder.restoreCallingIdentity(identity);
7727 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007728 }
7729
tom hsu0b59d292022-09-29 23:49:21 +08007730 @VisibleForTesting
7731 String matchLocaleFromSupportedLocaleList(@NonNull Locale inputLocale) {
7732 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
7733 getDefaultPhone().getContext());
7734 for (String localeTag : supportedLocale) {
7735 if (LocaleList.matchesLanguageAndScript(
7736 inputLocale, Locale.forLanguageTag(localeTag))
7737 && inputLocale.getCountry().equals(
7738 Locale.forLanguageTag(localeTag).getCountry())) {
7739 return localeTag;
7740 }
7741 }
7742 return inputLocale.toLanguageTag();
7743 }
7744
Narayan Kamath1c496c22015-04-16 14:40:19 +01007745 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007746 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007747 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007748 }
7749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007750 /**
7751 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7752 */
7753 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007754 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007755 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007756 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007757
Gary Jian3aa9a762022-01-24 16:41:19 +08007758 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7759 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007760
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007761 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007762 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7763 * representing the state of the modem.
7764 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007765 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7766 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007767 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007768 */
7769 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007770 public void requestModemActivityInfo(ResultReceiver result) {
7771 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007772 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007773
7774 final long identity = Binder.clearCallingIdentity();
7775 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007776 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007777 } finally {
7778 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007779 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007780 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007781
Siddharth Rayb8114062018-06-17 15:02:38 -07007782 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7783 // less than total activity duration.
7784 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7785 if (info == null) {
7786 return false;
7787 }
7788 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007789 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7790 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7791
Siddharth Rayb8114062018-06-17 15:02:38 -07007792 return (info.isValid()
7793 && (info.getSleepTimeMillis() <= activityDurationMs)
7794 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007795 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007796 && (totalTxTimeMs <= activityDurationMs));
7797 }
7798
Gary Jian3aa9a762022-01-24 16:41:19 +08007799 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7800 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7801 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7802 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7803
7804 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7805 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7806 }
7807
7808 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7809 mLastModemActivityInfo.setReceiveTimeMillis(
7810 rat,
7811 freq,
7812 info.getReceiveTimeMillis(rat, freq)
7813 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7814 }
7815
7816 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7817 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7818 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7819 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7820
7821 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7822 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7823 }
7824 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7825 mLastModemActivityInfo.setReceiveTimeMillis(
7826 rat,
7827 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7828 }
7829
7830 /**
7831 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7832 * @param info recent ModemActivityInfo
7833 */
7834 private void mergeModemActivityInfo(ModemActivityInfo info) {
7835 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7836 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7837 boolean matched;
7838 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7839 matched = false;
7840 int rat = info.getSpecificInfoRat(i);
7841 int freq = info.getSpecificInfoFrequencyRange(i);
7842 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7843 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7844 //if it already exists
7845 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7846 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7847 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7848 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7849 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7850 updateLastModemActivityInfo(info, rat, freq);
7851 matched = true;
7852 }
7853 } else {
7854 updateLastModemActivityInfo(info, rat);
7855 matched = true;
7856 }
7857 }
7858 }
7859
7860 if (!matched) {
7861 mDeltaSpecificInfo =
7862 new ActivityStatsTechSpecificInfo(
7863 rat,
7864 freq,
7865 info.getTransmitTimeMillis(rat, freq),
7866 (int) info.getReceiveTimeMillis(rat, freq));
7867 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7868 }
7869 }
7870 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7871 mLastModemActivitySpecificInfo =
7872 new ActivityStatsTechSpecificInfo[merged.size()];
7873 merged.toArray(mLastModemActivitySpecificInfo);
7874
7875 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7876 mLastModemActivityInfo.setSleepTimeMillis(
7877 info.getSleepTimeMillis()
7878 + mLastModemActivityInfo.getSleepTimeMillis());
7879 mLastModemActivityInfo.setIdleTimeMillis(
7880 info.getIdleTimeMillis()
7881 + mLastModemActivityInfo.getIdleTimeMillis());
7882 }
7883
Jack Yu85bd38a2015-11-09 11:34:32 -08007884 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007885 * Returns the service state information on specified subscription.
7886 */
7887 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007888 public ServiceState getServiceStateForSubscriber(int subId,
7889 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7890 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007892 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007893 return null;
7894 }
7895
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007896 boolean hasFinePermission = false;
7897 boolean hasCoarsePermission = false;
7898 if (!renounceFineLocationAccess) {
7899 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7900 LocationAccessPolicy.checkLocationPermission(mApp,
7901 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7902 .setCallingPackage(callingPackage)
7903 .setCallingFeatureId(callingFeatureId)
7904 .setCallingPid(Binder.getCallingPid())
7905 .setCallingUid(Binder.getCallingUid())
7906 .setMethod("getServiceStateForSubscriber")
7907 .setLogAsInfo(true)
7908 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7909 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7910 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7911 .build());
7912 hasFinePermission =
7913 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7914 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007915
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007916 if (!renounceCoarseLocationAccess) {
7917 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7918 LocationAccessPolicy.checkLocationPermission(mApp,
7919 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7920 .setCallingPackage(callingPackage)
7921 .setCallingFeatureId(callingFeatureId)
7922 .setCallingPid(Binder.getCallingPid())
7923 .setCallingUid(Binder.getCallingUid())
7924 .setMethod("getServiceStateForSubscriber")
7925 .setLogAsInfo(true)
7926 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7927 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7928 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7929 .build());
7930 hasCoarsePermission =
7931 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7932 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007933
Jack Yu479f40e2020-10-27 21:29:25 -07007934 final Phone phone = getPhone(subId);
7935 if (phone == null) {
7936 return null;
7937 }
7938
Jordan Liu0f2bc442020-11-18 16:47:37 -08007939 final long identity = Binder.clearCallingIdentity();
7940
Jack Yu479f40e2020-10-27 21:29:25 -07007941 boolean isCallingPackageDataService = phone.getDataServicePackages()
7942 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007943 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007944 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7945 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7946 Rlog.d(LOG_TAG,
7947 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7948 return null;
7949 }
7950
Hall Liuf19c44f2018-11-27 14:38:17 -08007951 ServiceState ss = phone.getServiceState();
7952
7953 // Scrub out the location info in ServiceState depending on what level of access
7954 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007955 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007956 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7957 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958 } finally {
7959 Binder.restoreCallingIdentity(identity);
7960 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007961 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007962
7963 /**
7964 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7965 *
7966 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7967 * voicemail ringtone.
7968 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7969 * PhoneAccount.
7970 */
7971 @Override
7972 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007973 final long identity = Binder.clearCallingIdentity();
7974 try {
7975 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7976 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007977 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007978 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007980 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7981 } finally {
7982 Binder.restoreCallingIdentity(identity);
7983 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007984 }
7985
7986 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007987 * Sets the per-account voicemail ringtone.
7988 *
7989 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7990 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7991 *
7992 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7993 * voicemail ringtone.
7994 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7995 * PhoneAccount.
7996 */
7997 @Override
7998 public void setVoicemailRingtoneUri(String callingPackage,
7999 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008000 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008001 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008002 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8003 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8005 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8006 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008008
8009 final long identity = Binder.clearCallingIdentity();
8010 try {
8011 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8012 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008013 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008014 }
8015 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8016 } finally {
8017 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008018 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008019 }
8020
8021 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008022 * Returns whether vibration is set for voicemail notification in Phone settings.
8023 *
8024 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8025 * voicemail vibration setting.
8026 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8027 */
8028 @Override
8029 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008030 final long identity = Binder.clearCallingIdentity();
8031 try {
8032 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8033 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008034 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008036
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008037 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8038 } finally {
8039 Binder.restoreCallingIdentity(identity);
8040 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008041 }
8042
Youhan Wange64578a2016-05-02 15:32:42 -07008043 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008044 * Sets the per-account voicemail vibration.
8045 *
8046 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8047 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8048 *
8049 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8050 * voicemail vibration setting.
8051 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8052 * specific PhoneAccount.
8053 */
8054 @Override
8055 public void setVoicemailVibrationEnabled(String callingPackage,
8056 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008057 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008058 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008059 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8060 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8062 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8063 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008064 }
8065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008066 final long identity = Binder.clearCallingIdentity();
8067 try {
8068 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8069 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008070 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008071 }
8072 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8073 } finally {
8074 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008075 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008076 }
8077
8078 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008079 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8080 *
8081 * @throws SecurityException if the caller does not have the required permission
8082 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008083 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008084 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008085 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008086 }
8087
8088 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008089 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8090 * permission.
8091 *
8092 * @throws SecurityException if the caller does not have the required permission
8093 */
8094 private void enforceSendSmsPermission() {
8095 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8096 }
8097
8098 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008099 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008100 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008101 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008102 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008103 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104 final long identity = Binder.clearCallingIdentity();
8105 try {
8106 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008107 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108 if (componentName == null) {
8109 throw new SecurityException(
8110 "Caller not current active visual voicemail package[null]");
8111 }
8112 String vvmPackage = componentName.getPackageName();
8113 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008114 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008115 }
8116 } finally {
8117 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008118 }
8119 }
8120
8121 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008122 * Return the application ID for the app type.
8123 *
8124 * @param subId the subscription ID that this request applies to.
8125 * @param appType the uicc app type.
8126 * @return Application ID for specificied app type, or null if no uicc.
8127 */
8128 @Override
8129 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008130 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008131 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008132
8133 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008134 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008135 if (phone == null) {
8136 return null;
8137 }
8138 String aid = null;
8139 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008140 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008141 .getApplicationByType(appType).getAid();
8142 } catch (Exception e) {
8143 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8144 }
8145 return aid;
8146 } finally {
8147 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008148 }
Youhan Wange64578a2016-05-02 15:32:42 -07008149 }
8150
Youhan Wang4001d252016-05-11 10:29:41 -07008151 /**
8152 * Return the Electronic Serial Number.
8153 *
8154 * @param subId the subscription ID that this request applies to.
8155 * @return ESN or null if error.
8156 */
8157 @Override
8158 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008159 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008160 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008161
8162 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008163 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008164 if (phone == null) {
8165 return null;
8166 }
8167 String esn = null;
8168 try {
8169 esn = phone.getEsn();
8170 } catch (Exception e) {
8171 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8172 }
8173 return esn;
8174 } finally {
8175 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008176 }
Youhan Wang4001d252016-05-11 10:29:41 -07008177 }
8178
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008179 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008180 * Return the Preferred Roaming List Version.
8181 *
8182 * @param subId the subscription ID that this request applies to.
8183 * @return PRLVersion or null if error.
8184 */
8185 @Override
8186 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008187 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008188 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189
8190 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008191 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008192 if (phone == null) {
8193 return null;
8194 }
8195 String cdmaPrlVersion = null;
8196 try {
8197 cdmaPrlVersion = phone.getCdmaPrlVersion();
8198 } catch (Exception e) {
8199 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8200 }
8201 return cdmaPrlVersion;
8202 } finally {
8203 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008204 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008205 }
8206
8207 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008208 * Get snapshot of Telephony histograms
8209 * @return List of Telephony histograms
8210 * @hide
8211 */
8212 @Override
8213 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8215 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008216
8217 final long identity = Binder.clearCallingIdentity();
8218 try {
8219 return RIL.getTelephonyRILTimingHistograms();
8220 } finally {
8221 Binder.restoreCallingIdentity(identity);
8222 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008223 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008224
8225 /**
8226 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008227 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8228 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008229 * Require system privileges. In the future we may add this to carrier APIs.
8230 *
Michele Berionne482f8202018-11-27 18:57:59 -08008231 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008232 */
8233 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008234 @TelephonyManager.SetCarrierRestrictionResult
8235 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008236 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008237 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008238
Michele Berionne482f8202018-11-27 18:57:59 -08008239 if (carrierRestrictionRules == null) {
8240 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008241 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008243 final long identity = Binder.clearCallingIdentity();
8244 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008245 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008246 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008247 } finally {
8248 Binder.restoreCallingIdentity(identity);
8249 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008250 }
8251
8252 /**
8253 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008254 * Get the allowed carrier list and the excluded carrier list, including the priority between
8255 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008256 * Require system privileges. In the future we may add this to carrier APIs.
8257 *
Michele Berionne482f8202018-11-27 18:57:59 -08008258 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008259 */
8260 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008261 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008262 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008264
8265 final long identity = Binder.clearCallingIdentity();
8266 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008267 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8268 if (response instanceof CarrierRestrictionRules) {
8269 return (CarrierRestrictionRules) response;
8270 }
8271 // Response is an Exception of some kind,
8272 // which is signalled to the user as a NULL retval
8273 return null;
8274 } catch (Exception e) {
8275 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8276 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008277 } finally {
8278 Binder.restoreCallingIdentity(identity);
8279 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008280 }
8281
fionaxu59545b42016-05-25 15:53:37 -07008282 /**
fionaxu59545b42016-05-25 15:53:37 -07008283 * Action set from carrier signalling broadcast receivers to enable/disable radio
8284 * @param subId the subscription ID that this action applies to.
8285 * @param enabled control enable or disable radio.
8286 * {@hide}
8287 */
8288 @Override
8289 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8290 enforceModifyPermission();
8291 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008292
8293 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008294 if (phone == null) {
8295 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8296 return;
8297 }
8298 try {
8299 phone.carrierActionSetRadioEnabled(enabled);
8300 } catch (Exception e) {
8301 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302 } finally {
8303 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008304 }
8305 }
8306
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008307 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008308 * Enable or disable Voice over NR (VoNR)
8309 * @param subId the subscription ID that this action applies to.
8310 * @param enabled enable or disable VoNR.
8311 * @return operation result.
8312 */
8313 @Override
8314 public int setVoNrEnabled(int subId, boolean enabled) {
8315 enforceModifyPermission();
8316 final Phone phone = getPhone(subId);
8317
8318 final long identity = Binder.clearCallingIdentity();
8319 if (phone == null) {
8320 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8321 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8322 }
8323
8324 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8325 try {
8326 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8327 workSource);
8328 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008329
8330 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8331 if (DBG) {
8332 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8333 }
8334 SubscriptionManager.setSubscriptionProperty(
8335 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8336 (enabled ? "1" : "0"));
8337 }
8338
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008339 return result;
8340 } finally {
8341 Binder.restoreCallingIdentity(identity);
8342 }
8343 }
8344
8345 /**
8346 * Is voice over NR enabled
8347 * @return true if VoNR is enabled else false
8348 */
8349 @Override
8350 public boolean isVoNrEnabled(int subId) {
8351 enforceReadPrivilegedPermission("isVoNrEnabled");
8352 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8353 final long identity = Binder.clearCallingIdentity();
8354 try {
8355 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8356 null, subId, workSource);
8357 if (DBG) log("isVoNrEnabled: " + isEnabled);
8358 return isEnabled;
8359 } finally {
8360 Binder.restoreCallingIdentity(identity);
8361 }
8362 }
8363
8364 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008365 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8366 * network status based on which carrier apps could apply actions accordingly,
8367 * enable/disable default url handler for example.
8368 *
8369 * @param subId the subscription ID that this action applies to.
8370 * @param report control start/stop reporting the default network status.
8371 * {@hide}
8372 */
8373 @Override
8374 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8375 enforceModifyPermission();
8376 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008377
8378 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008379 if (phone == null) {
8380 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8381 return;
8382 }
8383 try {
8384 phone.carrierActionReportDefaultNetworkStatus(report);
8385 } catch (Exception e) {
8386 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008387 } finally {
8388 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008389 }
8390 }
8391
8392 /**
fionaxud9622282017-07-17 17:51:30 -07008393 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8394 * @param subId the subscription ID that this action applies to.
8395 * {@hide}
8396 */
8397 @Override
8398 public void carrierActionResetAll(int subId) {
8399 enforceModifyPermission();
8400 final Phone phone = getPhone(subId);
8401 if (phone == null) {
8402 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8403 return;
8404 }
8405 try {
8406 phone.carrierActionResetAll();
8407 } catch (Exception e) {
8408 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8409 }
8410 }
8411
8412 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008413 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8414 * bug report is being generated.
8415 */
8416 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008417 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008418 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8419 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008420 writer.println("Permission Denial: can't dump Phone from pid="
8421 + Binder.getCallingPid()
8422 + ", uid=" + Binder.getCallingUid()
8423 + "without permission "
8424 + android.Manifest.permission.DUMP);
8425 return;
8426 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008427 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008428 }
Jack Yueb89b242016-06-22 13:27:47 -07008429
Brad Ebingerdac2f002018-04-03 15:17:52 -07008430 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008431 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8432 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8433 @NonNull String[] args) {
8434 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8435 this, in.getFileDescriptor(), out.getFileDescriptor(),
8436 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008437 }
8438
Jack Yueb89b242016-06-22 13:27:47 -07008439 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008440 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008441 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008442 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008443 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008444 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008445 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008446 */
8447 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008448 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008449 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008450 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8451 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8452 try {
8453 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008454 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008455 } catch (SecurityException se) {
8456 enforceModifyPermission();
8457 }
8458 } else {
8459 enforceModifyPermission();
8460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008461
8462 final long identity = Binder.clearCallingIdentity();
8463 try {
8464 Phone phone = getPhone(subId);
8465 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008466 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8467 phone.carrierActionSetMeteredApnsEnabled(enabled);
8468 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008469 if (phone.isUsingNewDataStack()) {
Sarah Chinecc78c42022-03-31 21:16:48 -07008470 phone.getDataSettingsManager().setDataEnabled(
8471 reason, enabled, callingPackage);
Jack Yu99e87332021-12-17 23:14:15 -08008472 } else {
8473 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8474 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008476 }
8477 } finally {
8478 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008479 }
8480 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008481
8482 /**
8483 * Get Client request stats
8484 * @return List of Client Request Stats
8485 * @hide
8486 */
8487 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008488 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8489 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008490 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008491 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008492 return null;
8493 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008494 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008496 final long identity = Binder.clearCallingIdentity();
8497 try {
8498 if (phone != null) {
8499 return phone.getClientRequestStats();
8500 }
8501
8502 return null;
8503 } finally {
8504 Binder.restoreCallingIdentity(identity);
8505 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008506 }
8507
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008508 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008509 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008510 if (uid == Process.ROOT_UID && packageName == null) {
8511 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8512 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8513 // exception. ROOT_UID seems not to have a valid package name returned by
8514 // PackageManager, so just fake it here to avoid issues when running telephony shell
8515 // commands that plumb through the RIL as root, like so:
8516 // $ adb root
8517 // $ adb shell cmd phone ...
8518 packageName = "root";
8519 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008520 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008521 }
Jack Yueb4124c2017-02-16 15:32:43 -08008522
8523 /**
Grace Chen70990072017-03-24 17:21:30 -07008524 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008525 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008526 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008527 * @param state State of SIM (power down, power up, pass through)
8528 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8529 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8530 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008531 *
8532 **/
8533 @Override
Grace Chen70990072017-03-24 17:21:30 -07008534 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008535 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008536 Phone phone = PhoneFactory.getPhone(slotIndex);
8537
vagdeviaf9a5b92018-08-15 16:01:53 -07008538 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008540 final long identity = Binder.clearCallingIdentity();
8541 try {
8542 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008543 phone.setSimPowerState(state, null, workSource);
8544 }
8545 } finally {
8546 Binder.restoreCallingIdentity(identity);
8547 }
8548 }
8549
8550 /**
8551 * Set SIM card power state.
8552 *
8553 * @param slotIndex SIM slot id.
8554 * @param state State of SIM (power down, power up, pass through)
8555 * @param callback callback to trigger after success or failure
8556 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8557 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8558 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8559 *
8560 **/
8561 @Override
8562 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8563 IIntegerConsumer callback) {
8564 enforceModifyPermission();
8565 Phone phone = PhoneFactory.getPhone(slotIndex);
8566
8567 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8568
8569 final long identity = Binder.clearCallingIdentity();
8570 try {
8571 if (phone != null) {
8572 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8573 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008574 }
8575 } finally {
8576 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008577 }
8578 }
Shuo Qiandd210312017-04-12 22:11:33 +00008579
Tyler Gunn65d45c22017-06-05 11:22:26 -07008580 private boolean isUssdApiAllowed(int subId) {
8581 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008582 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008583 if (configManager == null) {
8584 return false;
8585 }
8586 PersistableBundle pb = configManager.getConfigForSubId(subId);
8587 if (pb == null) {
8588 return false;
8589 }
8590 return pb.getBoolean(
8591 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8592 }
8593
Shuo Qiandd210312017-04-12 22:11:33 +00008594 /**
8595 * Check if phone is in emergency callback mode
8596 * @return true if phone is in emergency callback mode
8597 * @param subId sub id
8598 */
goneil9c5f4872017-12-05 14:07:56 -08008599 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008600 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008601 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008602 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008603
8604 final long identity = Binder.clearCallingIdentity();
8605 try {
8606 if (phone != null) {
8607 return phone.isInEcm();
8608 } else {
8609 return false;
8610 }
8611 } finally {
8612 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008613 }
8614 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008615
8616 /**
8617 * Get the current signal strength information for the given subscription.
8618 * Because this information is not updated when the device is in a low power state
8619 * it should not be relied-upon to be current.
8620 * @param subId Subscription index
8621 * @return the most recent cached signal strength info from the modem
8622 */
8623 @Override
8624 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008625 final long identity = Binder.clearCallingIdentity();
8626 try {
8627 Phone p = getPhone(subId);
8628 if (p == null) {
8629 return null;
8630 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008631
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008632 return p.getSignalStrength();
8633 } finally {
8634 Binder.restoreCallingIdentity(identity);
8635 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008636 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008637
Pengquan Meng77b7f132018-08-22 14:49:57 -07008638 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008639 * Get the current modem radio state for the given slot.
8640 * @param slotIndex slot index.
8641 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008642 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008643 * @return the current radio power state from the modem
8644 */
8645 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008646 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008647 Phone phone = PhoneFactory.getPhone(slotIndex);
8648 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8650 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008651 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8652 }
8653
8654 final long identity = Binder.clearCallingIdentity();
8655 try {
8656 return phone.getRadioPowerState();
8657 } finally {
8658 Binder.restoreCallingIdentity(identity);
8659 }
8660 }
8661 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8662 }
8663
8664 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008665 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8666 *
8667 * <p>Requires one of the following permissions:
8668 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008669 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008670 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8671 * privileges.
8672 *
8673 * @param subId subscription id
8674 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8675 * {@code false}.
8676 */
8677 @Override
8678 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008679 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008680 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008681 try {
8682 mApp.enforceCallingOrSelfPermission(
8683 android.Manifest.permission.ACCESS_NETWORK_STATE,
8684 functionName);
8685 } catch (Exception e) {
8686 mApp.enforceCallingOrSelfPermission(
8687 permission.READ_BASIC_PHONE_STATE, functionName);
8688 }
Shuo Qian093013d2020-08-13 15:42:55 -07008689 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008690 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008691 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008692 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008693
Pengquan Menga1bb6272018-09-06 09:59:22 -07008694 boolean isEnabled = false;
8695 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008696 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008697 Phone phone = getPhone(subId);
8698 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008699 } finally {
8700 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008701 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008702 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008703 }
8704
8705
8706 /**
8707 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8708 *
8709 * <p> Requires permission:
8710 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8711 * privileges.
8712 *
8713 * @param subId subscription id
8714 * @param isEnabled {@code true} means enable, {@code false} means disable.
8715 */
8716 @Override
8717 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8719 mApp, subId, "setDataRoamingEnabled");
8720
Pengquan Menga1bb6272018-09-06 09:59:22 -07008721 final long identity = Binder.clearCallingIdentity();
8722 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008723 Phone phone = getPhone(subId);
8724 if (phone != null) {
8725 phone.setDataRoamingEnabled(isEnabled);
8726 }
8727 } finally {
8728 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008729 }
8730 }
8731
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008732 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008733 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008734 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008735 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008736 mApp, subId, "isManualNetworkSelectionAllowed");
8737
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008738 boolean isAllowed = true;
8739 final long identity = Binder.clearCallingIdentity();
8740 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008741 Phone phone = getPhone(subId);
8742 if (phone != null) {
8743 isAllowed = phone.isCspPlmnEnabled();
8744 }
8745 } finally {
8746 Binder.restoreCallingIdentity(identity);
8747 }
8748 return isAllowed;
8749 }
8750
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008751 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8752 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008753 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008754 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008755 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008756 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8757 if (phone == null) {
8758 return false;
8759 }
8760 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8761 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8762 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008763 }
8764
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008765 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008766 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008767 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008768 mApp.getSystemService(AppOpsManager.class)
8769 .checkPackage(Binder.getCallingUid(), callingPackage);
8770
Jordan Liu1e142fc2019-04-22 15:10:43 -07008771 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008772 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008773 try {
8774 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008775 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008776 } catch (SecurityException e) {
8777 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8778 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008779 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008780 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008781 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008782 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008783 }
sandeepjsb6c87872021-09-27 15:34:44 +00008784 // checking compatibility, if calling app's target SDK is T and beyond.
8785 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8786 Binder.getCallingUid())) {
8787 isIccIdAccessRestricted = true;
8788 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008789 final long identity = Binder.clearCallingIdentity();
8790 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008791 UiccController uiccController = UiccController.getInstance();
8792 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008793 if (hasReadPermission) {
8794 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008795 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008796
8797 // Remove private info if the caller doesn't have access
8798 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8799 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008800 //setting the value after compatibility check
8801 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008802 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8803 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008804 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008805 if (card == null) {
8806 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008807 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008808 continue;
8809 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008810 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8811 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008812 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008813 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008814 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008815 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8816 for (UiccPortInfo portInfo : portInfos) {
8817 UiccPort port = uiccController.getUiccPortForSlot(
8818 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8819 if (port == null) {
8820 // assume no access if port is null
8821 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8822 continue;
8823 }
8824 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8825 uiccPortInfos.add(portInfo);
8826 } else {
8827 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8828 }
8829 }
8830 filteredInfos.add(new UiccCardInfo(
8831 cardInfo.isEuicc(),
8832 cardInfo.getCardId(),
8833 null,
8834 cardInfo.getPhysicalSlotIndex(),
8835 cardInfo.isRemovable(),
8836 cardInfo.isMultipleEnabledProfilesSupported(),
8837 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008838 }
8839 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008840 } finally {
8841 Binder.restoreCallingIdentity(identity);
8842 }
8843 }
8844
sandeepjsb6c87872021-09-27 15:34:44 +00008845 /**
8846 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8847 * generally private and require carrier privileges to view.
8848 *
8849 * @hide
8850 */
8851 @NonNull
8852 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8853 List<UiccPortInfo> portinfo = new ArrayList<>();
8854 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8855 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8856 }
8857 return new UiccCardInfo(
8858 cardInfo.isEuicc(),
8859 cardInfo.getCardId(),
8860 null,
8861 cardInfo.getPhysicalSlotIndex(),
8862 cardInfo.isRemovable(),
8863 cardInfo.isMultipleEnabledProfilesSupported(),
8864 portinfo
8865 );
8866 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008867
sandeepjsb6c87872021-09-27 15:34:44 +00008868 /**
8869 * @hide
8870 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8871 * These values are generally private and require carrier privileges to view.
8872 */
8873 @NonNull
8874 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8875 return new UiccPortInfo(
8876 UiccPortInfo.ICCID_REDACTED,
8877 portInfo.getPortIndex(),
8878 portInfo.getLogicalSlotIndex(),
8879 portInfo.isActive()
8880 );
8881 }
8882 @Override
8883 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008884 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008885 mApp.getSystemService(AppOpsManager.class)
8886 .checkPackage(Binder.getCallingUid(), callingPackage);
8887
sandeepjsb6c87872021-09-27 15:34:44 +00008888 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008889
Aman Guptaf3c90b32022-03-17 04:54:16 +00008890 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8891 // we are reading iccId which is PII data.
8892 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008893
8894 // checking compatibility, if calling app's target SDK is T and beyond.
8895 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8896 Binder.getCallingUid())) {
8897 isLogicalSlotAccessRestricted = true;
8898 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008899 final long identity = Binder.clearCallingIdentity();
8900 try {
8901 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008902 if (slots == null || slots.length == 0) {
8903 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008904 return null;
8905 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008906 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8907 for (int i = 0; i < slots.length; i++) {
8908 UiccSlot slot = slots[i];
8909 if (slot == null) {
8910 continue;
8911 }
8912
Jordan Liu7be7e652019-05-06 18:55:02 +00008913 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008914 UiccCard card = slot.getUiccCard();
8915 if (card != null) {
8916 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008917 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008918 cardId = slot.getEid();
8919 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00008920 // If cardId is null, use iccId of default port as cardId.
8921 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07008922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008923 }
8924
Jordan Liu857451f2019-05-09 16:35:35 -07008925 if (cardId != null) {
8926 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8927 // if cardId is an EID, it's all digits so this is fine
8928 cardId = IccUtils.stripTrailingFs(cardId);
8929 }
8930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008931 int cardState = 0;
8932 switch (slot.getCardState()) {
8933 case CARDSTATE_ABSENT:
8934 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8935 break;
8936 case CARDSTATE_PRESENT:
8937 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8938 break;
8939 case CARDSTATE_ERROR:
8940 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8941 break;
8942 case CARDSTATE_RESTRICTED:
8943 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8944 break;
8945 default:
8946 break;
8947
8948 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008949 List<UiccPortInfo> portInfos = new ArrayList<>();
8950 int[] portIndexes = slot.getPortList();
8951 for (int portIdx : portIndexes) {
8952 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00008953 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008954 portInfos.add(new UiccPortInfo(iccId, portIdx,
8955 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008957 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008958 slot.isEuicc(),
8959 cardId,
8960 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008961 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008962 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008963 //setting the value after compatibility check
8964 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008965 }
8966 return infos;
8967 } finally {
8968 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008969 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008970 }
8971
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008972 /* Returns null if doesn't have read permission or carrier privilege access. */
8973 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8974 boolean hasReadPermission) {
8975 String iccId = slot.getIccId(portIndex);
8976 if (hasReadPermission) { // if has read permission
8977 return iccId;
8978 } else {
8979 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8980 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8981 // if no read permission, checking carrier privilege access
8982 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8983 return iccId;
8984 }
8985 }
8986 }
8987 // No read permission or carrier privilege access.
8988 return UiccPortInfo.ICCID_REDACTED;
8989 }
8990
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008991 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008992 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008993 public boolean switchSlots(int[] physicalSlots) {
8994 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008995
8996 final long identity = Binder.clearCallingIdentity();
8997 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008998 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8999 for (int i = 0; i < physicalSlots.length; i++) {
9000 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9001 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9002 physicalSlots[i], i));
9003 }
9004 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009005 } finally {
9006 Binder.restoreCallingIdentity(identity);
9007 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009008 }
Jack Yu4c988042018-02-27 15:30:01 -08009009
9010 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009011 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9012 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9013 enforceModifyPermission();
9014
9015 final long identity = Binder.clearCallingIdentity();
9016 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009017 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009018 } finally {
9019 Binder.restoreCallingIdentity(identity);
9020 }
9021 }
9022
9023 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009024 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009025 final long identity = Binder.clearCallingIdentity();
9026 try {
9027 return UiccController.getInstance().getCardIdForDefaultEuicc();
9028 } finally {
9029 Binder.restoreCallingIdentity(identity);
9030 }
9031 }
9032
Pengquan Meng85728fb2018-03-12 16:31:21 -07009033 /**
goneil47ffb6e2018-04-06 15:40:58 -07009034 * A test API to reload the UICC profile.
9035 *
9036 * <p>Requires that the calling app has permission
9037 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9038 * @hide
9039 */
9040 @Override
9041 public void refreshUiccProfile(int subId) {
9042 enforceModifyPermission();
9043
9044 final long identity = Binder.clearCallingIdentity();
9045 try {
9046 Phone phone = getPhone(subId);
9047 if (phone == null) {
9048 return;
9049 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009050 UiccPort uiccPort = phone.getUiccPort();
9051 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009052 return;
9053 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009054 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009055 if (uiccProfile == null) {
9056 return;
9057 }
9058 uiccProfile.refresh();
9059 } finally {
9060 Binder.restoreCallingIdentity(identity);
9061 }
9062 }
9063
9064 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009065 * Returns false if the mobile data is disabled by default, otherwise return true.
9066 */
9067 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009068 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009069 }
9070
9071 /**
9072 * Returns true if the data roaming is enabled by default, i.e the system property
9073 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9074 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9075 */
9076 private boolean getDefaultDataRoamingEnabled(int subId) {
9077 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009078 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009079 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009080 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9081 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9082 return isDataRoamingEnabled;
9083 }
9084
9085 /**
9086 * Returns the default network type for the given {@code subId}, if the default network type is
9087 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9088 */
9089 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009090 List<Integer> list = TelephonyProperties.default_network();
9091 int phoneId = mSubscriptionController.getPhoneId(subId);
9092 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9093 return list.get(phoneId);
9094 }
9095 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009096 }
fionaxua13278b2018-03-21 00:08:13 -07009097
9098 @Override
9099 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009100 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009101 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009102
9103 final long identity = Binder.clearCallingIdentity();
9104 try {
9105 final Phone phone = getPhone(subId);
9106 if (phone == null) {
9107 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9108 return;
9109 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009110 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9111 if (cpt != null) {
9112 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9113 }
9114 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009115 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9116 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009117 if (carrierPrivilegeRules == null) {
9118 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9119 } else {
9120 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9121 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009122 } finally {
9123 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009124 }
fionaxua13278b2018-03-21 00:08:13 -07009125 }
9126
9127 @Override
9128 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009129 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009130
9131 final long identity = Binder.clearCallingIdentity();
9132 try {
9133 final Phone phone = getPhone(subId);
9134 if (phone == null) {
9135 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9136 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9137 }
9138 return phone.getCarrierIdListVersion();
9139 } finally {
9140 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009141 }
fionaxua13278b2018-03-21 00:08:13 -07009142 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009143
9144 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009145 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9146 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009147 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009148 mApp, subId, callingPackage, callingFeatureId,
9149 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009150 return -1;
9151 }
9152
9153 final long identity = Binder.clearCallingIdentity();
9154 try {
9155 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9156 } finally {
9157 Binder.restoreCallingIdentity(identity);
9158 }
9159 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009160
9161 @Override
9162 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009163 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009164 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009165 mApp, subId, "getCdmaRoamingMode");
9166
9167 final long identity = Binder.clearCallingIdentity();
9168 try {
9169 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9170 } finally {
9171 Binder.restoreCallingIdentity(identity);
9172 }
9173 }
9174
9175 @Override
9176 public boolean setCdmaRoamingMode(int subId, int mode) {
9177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9178 mApp, subId, "setCdmaRoamingMode");
9179
9180 final long identity = Binder.clearCallingIdentity();
9181 try {
9182 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9183 } finally {
9184 Binder.restoreCallingIdentity(identity);
9185 }
9186 }
9187
9188 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009189 public int getCdmaSubscriptionMode(int subId) {
9190 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009191 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009192 mApp, subId, "getCdmaSubscriptionMode");
9193
9194 final long identity = Binder.clearCallingIdentity();
9195 try {
9196 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9197 } finally {
9198 Binder.restoreCallingIdentity(identity);
9199 }
9200 }
9201
9202 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009203 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9205 mApp, subId, "setCdmaSubscriptionMode");
9206
9207 final long identity = Binder.clearCallingIdentity();
9208 try {
9209 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9210 } finally {
9211 Binder.restoreCallingIdentity(identity);
9212 }
9213 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009214
sqianc5eccab2018-10-19 18:46:41 -07009215 @Override
sqian8c685422019-02-22 15:55:18 -08009216 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009217 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009219 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9220 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009221 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9222 }
9223 final long identity = Binder.clearCallingIdentity();
9224 try {
sqian854d44b2018-12-12 16:48:18 -08009225 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9226 for (Phone phone: PhoneFactory.getPhones()) {
9227 if (phone.getEmergencyNumberTracker() != null
9228 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9229 emergencyNumberListInternal.put(
9230 phone.getSubId(),
9231 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9232 }
sqian11b7a0e2018-12-05 18:48:28 -08009233 }
sqian854d44b2018-12-12 16:48:18 -08009234 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009235 } finally {
9236 Binder.restoreCallingIdentity(identity);
9237 }
sqianc5eccab2018-10-19 18:46:41 -07009238 }
9239
9240 @Override
sqian8c685422019-02-22 15:55:18 -08009241 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009242 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009243 if (!exactMatch) {
9244 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009245 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009246 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009247 }
9248 final long identity = Binder.clearCallingIdentity();
9249 try {
sqian854d44b2018-12-12 16:48:18 -08009250 for (Phone phone: PhoneFactory.getPhones()) {
9251 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009252 && phone.getEmergencyNumberTracker()
9253 .isEmergencyNumber(number, exactMatch)) {
9254 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009255 }
sqian11b7a0e2018-12-05 18:48:28 -08009256 }
9257 return false;
9258 } finally {
9259 Binder.restoreCallingIdentity(identity);
9260 }
9261 }
9262
sqianf4ca7ed2019-01-15 18:32:07 -08009263 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009264 * Start emergency callback mode for GsmCdmaPhone for testing.
9265 */
9266 @Override
9267 public void startEmergencyCallbackMode() {
9268 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9269 "startEmergencyCallbackMode");
9270 enforceModifyPermission();
9271 final long identity = Binder.clearCallingIdentity();
9272 try {
9273 for (Phone phone : PhoneFactory.getPhones()) {
9274 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9275 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9276 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9277 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9278 gsmCdmaPhone.obtainMessage(
9279 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9280 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9281 }
9282 }
9283 } finally {
9284 Binder.restoreCallingIdentity(identity);
9285 }
9286 }
9287
9288 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009289 * Update emergency number list for test mode.
9290 */
9291 @Override
9292 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9293 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9294 "updateEmergencyNumberListTestMode");
9295
9296 final long identity = Binder.clearCallingIdentity();
9297 try {
9298 for (Phone phone: PhoneFactory.getPhones()) {
9299 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9300 if (tracker != null) {
9301 tracker.executeEmergencyNumberTestModeCommand(action, num);
9302 }
9303 }
9304 } finally {
9305 Binder.restoreCallingIdentity(identity);
9306 }
9307 }
9308
9309 /**
9310 * Get the full emergency number list for test mode.
9311 */
9312 @Override
9313 public List<String> getEmergencyNumberListTestMode() {
9314 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9315 "getEmergencyNumberListTestMode");
9316
9317 final long identity = Binder.clearCallingIdentity();
9318 try {
9319 Set<String> emergencyNumbers = new HashSet<>();
9320 for (Phone phone: PhoneFactory.getPhones()) {
9321 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9322 if (tracker != null) {
9323 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9324 emergencyNumbers.add(num.getNumber());
9325 }
9326 }
9327 }
9328 return new ArrayList<>(emergencyNumbers);
9329 } finally {
9330 Binder.restoreCallingIdentity(identity);
9331 }
9332 }
9333
chen xud6b45bd2018-10-30 22:27:10 -07009334 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009335 public int getEmergencyNumberDbVersion(int subId) {
9336 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9337
9338 final long identity = Binder.clearCallingIdentity();
9339 try {
9340 final Phone phone = getPhone(subId);
9341 if (phone == null) {
9342 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9343 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9344 }
9345 return phone.getEmergencyNumberDbVersion();
9346 } finally {
9347 Binder.restoreCallingIdentity(identity);
9348 }
9349 }
9350
9351 @Override
9352 public void notifyOtaEmergencyNumberDbInstalled() {
9353 enforceModifyPermission();
9354
9355 final long identity = Binder.clearCallingIdentity();
9356 try {
9357 for (Phone phone: PhoneFactory.getPhones()) {
9358 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9359 if (tracker != null) {
9360 tracker.updateOtaEmergencyNumberDatabase();
9361 }
9362 }
9363 } finally {
9364 Binder.restoreCallingIdentity(identity);
9365 }
9366 }
9367
9368 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009369 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009370 enforceActiveEmergencySessionPermission();
9371
9372 final long identity = Binder.clearCallingIdentity();
9373 try {
9374 for (Phone phone: PhoneFactory.getPhones()) {
9375 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9376 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009377 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9378 }
9379 }
9380 } finally {
9381 Binder.restoreCallingIdentity(identity);
9382 }
9383 }
9384
9385 @Override
9386 public void resetOtaEmergencyNumberDbFilePath() {
9387 enforceActiveEmergencySessionPermission();
9388
9389 final long identity = Binder.clearCallingIdentity();
9390 try {
9391 for (Phone phone: PhoneFactory.getPhones()) {
9392 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9393 if (tracker != null) {
9394 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009395 }
9396 }
9397 } finally {
9398 Binder.restoreCallingIdentity(identity);
9399 }
9400 }
9401
9402 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009403 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9404 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9405 Phone phone = getPhone(subId);
9406 if (phone == null) {
9407 return null;
9408 }
9409 final long identity = Binder.clearCallingIdentity();
9410 try {
9411 UiccProfile profile = UiccController.getInstance()
9412 .getUiccProfileForPhone(phone.getPhoneId());
9413 if (profile != null) {
9414 return profile.getCertsFromCarrierPrivilegeAccessRules();
9415 }
9416 } finally {
9417 Binder.restoreCallingIdentity(identity);
9418 }
9419 return null;
9420 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009421
9422 /**
9423 * Enable or disable a modem stack.
9424 */
9425 @Override
9426 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9427 enforceModifyPermission();
9428
9429 final long identity = Binder.clearCallingIdentity();
9430 try {
9431 Phone phone = PhoneFactory.getPhone(slotIndex);
9432 if (phone == null) {
9433 return false;
9434 } else {
9435 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9436 }
9437 } finally {
9438 Binder.restoreCallingIdentity(identity);
9439 }
9440 }
Michelecea4cf22018-12-21 15:00:11 -08009441
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009442 /**
9443 * Whether a modem stack is enabled or not.
9444 */
9445 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009446 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9447 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009448 Phone phone = PhoneFactory.getPhone(slotIndex);
9449 if (phone == null) return false;
9450
9451 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009452 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9453 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009454 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9455 }
9456
9457 final long identity = Binder.clearCallingIdentity();
9458 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009459 try {
9460 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9461 } catch (NoSuchElementException ex) {
9462 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9463 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009464 } finally {
9465 Binder.restoreCallingIdentity(identity);
9466 }
9467 }
9468
Michelecea4cf22018-12-21 15:00:11 -08009469 @Override
Michele0ea7d782019-03-19 14:58:42 -07009470 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009471 enforceModifyPermission();
9472
9473 final long identity = Binder.clearCallingIdentity();
9474 try {
9475 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009476 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009477 .commit();
9478 } finally {
9479 Binder.restoreCallingIdentity(identity);
9480 }
9481 }
9482
9483 @Override
Michele0ea7d782019-03-19 14:58:42 -07009484 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009485 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009486 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009487 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9488 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009489 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009490 }
Michelecea4cf22018-12-21 15:00:11 -08009491
9492 final long identity = Binder.clearCallingIdentity();
9493 try {
Michele0ea7d782019-03-19 14:58:42 -07009494 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009495 } finally {
9496 Binder.restoreCallingIdentity(identity);
9497 }
9498 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009499
Michele0ea7d782019-03-19 14:58:42 -07009500 @TelephonyManager.IsMultiSimSupportedResult
9501 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009502 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9503 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9504 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009505 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9506 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009507 }
9508 // Check if the hardware supports multisim functionality. If usage of multisim is not
9509 // supported by the modem, indicate that it is restricted.
9510 PhoneCapability staticCapability =
9511 mPhoneConfigurationManager.getStaticPhoneCapability();
9512 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009513 loge("isMultiSimSupportedInternal: no static configuration available");
9514 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009515 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009516 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009517 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9518 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009519 }
9520 // Check if support of multiple SIMs is restricted by carrier
9521 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009522 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009523 }
9524
Michele0ea7d782019-03-19 14:58:42 -07009525 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009526 }
9527
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009528 /**
9529 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009530 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9531 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9532 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009533 * @param numOfSims number of active sims we want to switch to
9534 */
9535 @Override
9536 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009537 if (numOfSims == 1) {
9538 enforceModifyPermission();
9539 } else {
9540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9541 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9542 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009543 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009544
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009545 try {
Michele30b57b22019-03-01 12:01:14 -08009546 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009547 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009548 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9549 return;
9550 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009551 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9552 } finally {
9553 Binder.restoreCallingIdentity(identity);
9554 }
9555 }
9556
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009557 @Override
9558 public boolean isApplicationOnUicc(int subId, int appType) {
9559 enforceReadPrivilegedPermission("isApplicationOnUicc");
9560 Phone phone = getPhone(subId);
9561 if (phone == null) {
9562 return false;
9563 }
9564 final long identity = Binder.clearCallingIdentity();
9565 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009566 UiccPort uiccPort = phone.getUiccPort();
9567 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009568 return false;
9569 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009570 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009571 if (uiccProfile == null) {
9572 return false;
9573 }
9574 if (TelephonyManager.APPTYPE_SIM <= appType
9575 && appType <= TelephonyManager.APPTYPE_ISIM) {
9576 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9577 }
9578 return false;
9579 } finally {
9580 Binder.restoreCallingIdentity(identity);
9581 }
9582 }
9583
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009584 /**
chen xub4baa772019-04-03 10:23:41 -07009585 * Get whether making changes to modem configurations will trigger reboot.
9586 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009587 */
9588 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009589 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9590 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009591 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009592 mApp, subId, callingPackage, callingFeatureId,
9593 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009594 return false;
9595 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009596 final long identity = Binder.clearCallingIdentity();
9597 try {
9598 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9599 } finally {
9600 Binder.restoreCallingIdentity(identity);
9601 }
9602 }
9603
Nathan Harold29f5f052019-02-15 13:41:57 -08009604 private void updateModemStateMetrics() {
9605 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9606 // TODO: check the state for each modem if the api is ready.
9607 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9608 }
9609
Pengquan Meng3889a572019-01-23 11:16:29 -08009610 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009611 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009612 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009613 // Verify that the callingPackage belongs to the calling UID
9614 mApp.getSystemService(AppOpsManager.class)
9615 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009616 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009617 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009618 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009619 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9620 if (slotInfos != null) {
9621 for (int i = 0; i < slotInfos.length; i++) {
9622 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9623 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9624 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9625 portInfo.getLogicalSlotIndex()));
9626 }
9627 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009628 }
9629 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009630 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009631 } finally {
9632 Binder.restoreCallingIdentity(identity);
9633 }
9634 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009635
9636 /**
9637 * Get the IRadio HAL Version
9638 */
9639 @Override
9640 public int getRadioHalVersion() {
9641 Phone phone = getDefaultPhone();
9642 if (phone == null) return -1;
9643 HalVersion hv = phone.getHalVersion();
9644 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9645 return hv.major * 100 + hv.minor;
9646 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009647
9648 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009649 * Get the current calling package name.
9650 * @return the current calling package name
9651 */
9652 @Override
9653 public String getCurrentPackageName() {
9654 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9655 }
9656
9657 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009658 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9659 * corresponding network requests on a subId.
9660 *
9661 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009662 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009663 * 2) APN is un-metered for this subscription, or
9664 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009665 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009666 *
9667 * @return whether data is allowed for a apn type.
9668 *
9669 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009670 */
9671 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009672 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009673 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9674 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009675
9676 // Now that all security checks passes, perform the operation as ourselves.
9677 final long identity = Binder.clearCallingIdentity();
9678 try {
9679 Phone phone = getPhone(subId);
9680 if (phone == null) return false;
9681
Jack Yu27422a52022-03-21 10:38:05 -07009682 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009683 boolean isDataEnabled;
9684 if (phone.isUsingNewDataStack()) {
Jack Yu27422a52022-03-21 10:38:05 -07009685 isMetered = phone.getDataNetworkController().getDataConfigManager()
9686 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9687 phone.getServiceState().getDataRoaming());
Jack Yu99e87332021-12-17 23:14:15 -08009688 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9689 } else {
Jack Yu27422a52022-03-21 10:38:05 -07009690 isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009691 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9692 }
9693 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009694 } finally {
9695 Binder.restoreCallingIdentity(identity);
9696 }
9697 }
9698
9699 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009700 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009701 enforceReadPrivilegedPermission("isApnMetered");
9702
9703 // Now that all security checks passes, perform the operation as ourselves.
9704 final long identity = Binder.clearCallingIdentity();
9705 try {
9706 Phone phone = getPhone(subId);
9707 if (phone == null) return true; // By default return true.
Jack Yu27422a52022-03-21 10:38:05 -07009708 if (phone.isUsingNewDataStack()) {
9709 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9710 DataUtils.apnTypeToNetworkCapability(apnType),
9711 phone.getServiceState().getDataRoaming());
9712 }
Malcolm Chene5ad5792019-04-18 13:51:02 -07009713
Jack Yu41407ee2019-05-13 16:54:09 -07009714 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009715 } finally {
9716 Binder.restoreCallingIdentity(identity);
9717 }
9718 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009719
9720 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009721 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9722 int subscriptionId, IBooleanConsumer resultCallback) {
9723 enforceModifyPermission();
9724 long token = Binder.clearCallingIdentity();
9725 try {
9726 Phone phone = getPhone(subscriptionId);
9727 if (phone == null) {
9728 try {
9729 if (resultCallback != null) {
9730 resultCallback.accept(false);
9731 }
9732 } catch (RemoteException e) {
9733 // ignore
9734 }
9735 return;
9736 }
9737 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9738 Pair.create(specifiers, (x) -> {
9739 try {
9740 if (resultCallback != null) {
9741 resultCallback.accept(x);
9742 }
9743 } catch (RemoteException e) {
9744 // ignore
9745 }
9746 });
9747 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9748 } finally {
9749 Binder.restoreCallingIdentity(token);
9750 }
9751 }
9752
9753 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009754 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9755 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009756 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009757 mApp, subId, "getSystemSelectionChannels");
9758 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9759 final long identity = Binder.clearCallingIdentity();
9760 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009761 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9762 if (result instanceof IllegalStateException) {
9763 throw (IllegalStateException) result;
9764 }
9765 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009766 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9767 return specifiers;
9768 } finally {
9769 Binder.restoreCallingIdentity(identity);
9770 }
9771 }
9772
9773 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009774 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009775 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009776 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009777 }
9778
9779 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009780 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9781 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009782 if (callingPackage == null) {
9783 callingPackage = getCurrentPackageName();
9784 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009785 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9786 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009787 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9788 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009789 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9790 }
9791 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9792 Intent intent = new Intent();
9793 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9794 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9795 // Bring up choose default SMS subscription dialog right now
9796 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9797 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9798 mApp.startActivity(intent);
9799 }
chen xud5ca2d52019-05-28 15:20:57 -07009800
9801 @Override
9802 public String getMmsUAProfUrl(int subId) {
9803 //TODO investigate if this API should require proper permission check in R b/133791609
9804 final long identity = Binder.clearCallingIdentity();
9805 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009806 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9807 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9808 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9809 return carrierUAProfUrl;
9810 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009811 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9812 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009813 } finally {
9814 Binder.restoreCallingIdentity(identity);
9815 }
9816 }
9817
9818 @Override
9819 public String getMmsUserAgent(int subId) {
9820 //TODO investigate if this API should require proper permission check in R b/133791609
9821 final long identity = Binder.clearCallingIdentity();
9822 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009823 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9824 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9825 if (!TextUtils.isEmpty(carrierUserAgent)) {
9826 return carrierUserAgent;
9827 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009828 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9829 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009830 } finally {
9831 Binder.restoreCallingIdentity(identity);
9832 }
9833 }
Jack Yub07d4972019-05-28 16:12:25 -07009834
9835 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009836 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9837 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009838
Jack Yub07d4972019-05-28 16:12:25 -07009839 final long identity = Binder.clearCallingIdentity();
9840 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009841 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009842 if (phone == null) return false;
9843
Hall Liua62f5da2020-09-25 10:42:19 -07009844 switch (policy) {
9845 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009846 if (phone.isUsingNewDataStack()) {
9847 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9848 } else {
9849 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9850 }
Hall Liua62f5da2020-09-25 10:42:19 -07009851 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009852 if (phone.isUsingNewDataStack()) {
9853 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9854 } else {
9855 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9856 }
Hall Liua62f5da2020-09-25 10:42:19 -07009857 default:
9858 throw new IllegalArgumentException(policy + " is not a valid policy");
9859 }
Jack Yub07d4972019-05-28 16:12:25 -07009860 } finally {
9861 Binder.restoreCallingIdentity(identity);
9862 }
9863 }
9864
9865 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009866 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009867 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009868 enforceModifyPermission();
9869
changbettyd5c246e2019-12-24 15:40:37 +08009870 final long identity = Binder.clearCallingIdentity();
9871 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009872 Phone phone = getPhone(subscriptionId);
9873 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009874
Hall Liua62f5da2020-09-25 10:42:19 -07009875 switch (policy) {
9876 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009877 if (phone.isUsingNewDataStack()) {
9878 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9879 } else {
9880 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9881 }
Hall Liua62f5da2020-09-25 10:42:19 -07009882 break;
9883 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009884 if (phone.isUsingNewDataStack()) {
9885 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9886 } else {
9887 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9888 }
Hall Liua62f5da2020-09-25 10:42:19 -07009889 break;
9890 default:
9891 throw new IllegalArgumentException(policy + " is not a valid policy");
9892 }
changbettyd5c246e2019-12-24 15:40:37 +08009893 } finally {
9894 Binder.restoreCallingIdentity(identity);
9895 }
9896 }
9897
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009898 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009899 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009900 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9901 * otherwise.
9902 */
9903 @Override
9904 public void setCepEnabled(boolean isCepEnabled) {
9905 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9906
9907 final long identity = Binder.clearCallingIdentity();
9908 try {
9909 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9910 for (Phone phone : PhoneFactory.getPhones()) {
9911 Phone defaultPhone = phone.getImsPhone();
9912 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9913 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9914 ImsPhoneCallTracker imsPhoneCallTracker =
9915 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9916 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9917 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9918 + imsPhone.getMsisdn());
9919 }
9920 }
9921 } finally {
9922 Binder.restoreCallingIdentity(identity);
9923 }
9924 }
allenwtsu46dcc572020-01-08 18:24:03 +08009925
9926 /**
9927 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9928 *
9929 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9930 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9931 * before being read.
9932 */
9933 @Override
9934 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9935 isCompressed) {
9936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9937 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009938 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9939 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9940 }
9941 if (!isImsAvailableOnDevice()) {
9942 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9943 "IMS not available on device.");
9944 }
9945
9946 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009947 try {
Hui Wang761a6682020-10-31 05:12:53 +00009948 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9949 } finally {
9950 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009951 }
9952 }
zoey chene02881a2019-12-30 16:11:23 +08009953
9954 @Override
9955 public boolean isIccLockEnabled(int subId) {
9956 enforceReadPrivilegedPermission("isIccLockEnabled");
9957
9958 // Now that all security checks passes, perform the operation as ourselves.
9959 final long identity = Binder.clearCallingIdentity();
9960 try {
9961 Phone phone = getPhone(subId);
9962 if (phone != null && phone.getIccCard() != null) {
9963 return phone.getIccCard().getIccLockEnabled();
9964 } else {
9965 return false;
9966 }
9967 } finally {
9968 Binder.restoreCallingIdentity(identity);
9969 }
9970 }
9971
9972 /**
9973 * Set the ICC pin lock enabled or disabled.
9974 *
9975 * @return an integer representing the status of IccLock enabled or disabled in the following
9976 * three cases:
9977 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9978 * successfully.
9979 * - Positive number and zero for remaining password attempts.
9980 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9981 *
9982 */
9983 @Override
9984 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9985 enforceModifyPermission();
9986
9987 Phone phone = getPhone(subId);
9988 if (phone == null) {
9989 return 0;
9990 }
9991 // Now that all security checks passes, perform the operation as ourselves.
9992 final long identity = Binder.clearCallingIdentity();
9993 try {
9994 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9995 new Pair<Boolean, String>(enabled, password), phone, null);
9996 return attemptsRemaining;
9997
9998 } catch (Exception e) {
9999 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10000 } finally {
10001 Binder.restoreCallingIdentity(identity);
10002 }
10003 return 0;
10004 }
10005
10006 /**
10007 * Change the ICC password used in ICC pin lock.
10008 *
10009 * @return an integer representing the status of IccLock changed in the following three cases:
10010 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10011 * - Positive number and zero for remaining password attempts.
10012 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10013 *
10014 */
10015 @Override
10016 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10017 enforceModifyPermission();
10018
10019 Phone phone = getPhone(subId);
10020 if (phone == null) {
10021 return 0;
10022 }
10023 // Now that all security checks passes, perform the operation as ourselves.
10024 final long identity = Binder.clearCallingIdentity();
10025 try {
10026 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10027 new Pair<String, String>(oldPassword, newPassword), phone, null);
10028 return attemptsRemaining;
10029
10030 } catch (Exception e) {
10031 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10032 } finally {
10033 Binder.restoreCallingIdentity(identity);
10034 }
10035 return 0;
10036 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010037
10038 /**
10039 * Request for receiving user activity notification
10040 */
10041 @Override
10042 public void requestUserActivityNotification() {
10043 if (!mNotifyUserActivity.get()
10044 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10045 mNotifyUserActivity.set(true);
10046 }
10047 }
10048
10049 /**
10050 * Called when userActivity is signalled in the power manager.
10051 * This is safe to call from any thread, with any window manager locks held or not.
10052 */
10053 @Override
10054 public void userActivity() {
10055 // ***************************************
10056 // * Inherited from PhoneWindowManager *
10057 // ***************************************
10058 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10059 // WITH ITS LOCKS HELD.
10060 //
10061 // This code must be VERY careful about the locks
10062 // it acquires.
10063 // In fact, the current code acquires way too many,
10064 // and probably has lurking deadlocks.
10065
10066 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10067 throw new SecurityException("Only the OS may call notifyUserActivity()");
10068 }
10069
10070 if (mNotifyUserActivity.getAndSet(false)) {
10071 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10072 USER_ACTIVITY_NOTIFICATION_DELAY);
10073 }
10074 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010075
10076 @Override
10077 public boolean canConnectTo5GInDsdsMode() {
10078 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10079 }
Jack Yud10cdd42020-09-28 20:28:01 -070010080
10081 @Override
10082 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10083 String callingFeatureId) {
10084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10085 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10086 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10087 }
10088
10089 Phone phone = getPhone(subId);
10090 if (phone == null) {
10091 throw new RuntimeException("phone is not available");
10092 }
10093 // Now that all security checks passes, perform the operation as ourselves.
10094 final long identity = Binder.clearCallingIdentity();
10095 try {
10096 return phone.getEquivalentHomePlmns();
10097 } finally {
10098 Binder.restoreCallingIdentity(identity);
10099 }
10100 }
Daniel Bright59e67312020-11-13 11:49:37 -080010101
10102 @Override
10103 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010104 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10105 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010106 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010107 if (radioInterfaceCapabilities == null) {
10108 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010109 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010110 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010111 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010112
Hui Wang641e81c2020-10-12 12:14:23 -070010113 @Override
10114 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10115 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010116 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10117 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10118 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10119 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10120 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010121 if (DBG) {
10122 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10123 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10124 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10125 }
10126
10127 if (!SubscriptionManager.isValidSubscriptionId(subId)
10128 || appType < TelephonyManager.APPTYPE_UNKNOWN
10129 || appType > TelephonyManager.APPTYPE_ISIM
10130 || nafUrl == null || securityProtocol == null || callback == null) {
10131 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10132 if (callback != null) {
10133 try {
10134 callback.onAuthenticationFailure(
10135 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10136 } catch (RemoteException exception) {
10137 log("Fail to notify onAuthenticationFailure due to " + exception);
10138 }
10139 return;
10140 }
10141 }
10142
10143 final long token = Binder.clearCallingIdentity();
10144 try {
10145 getGbaManager(subId).bootstrapAuthenticationRequest(
10146 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10147 forceBootStrapping, callback));
10148 } finally {
10149 Binder.restoreCallingIdentity(token);
10150 }
10151 }
10152
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010153 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010154 * Attempts to set the radio power state for all phones for thermal reason.
10155 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010156 * requested radio power state will actually be set. See {@link
10157 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10158 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010159 * @param enable {@code true} if trying to turn radio on.
10160 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10161 * false}.
10162 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010163 private boolean setRadioPowerForThermal(boolean enable) {
10164 boolean isPhoneAvailable = false;
10165 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10166 Phone phone = PhoneFactory.getPhone(i);
10167 if (phone != null) {
10168 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10169 isPhoneAvailable = true;
10170 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010171 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010172
10173 // return true if successfully informed the phone object about the thermal radio power
10174 // request.
10175 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010176 }
10177
10178 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010179 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010180 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10181 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10182 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10183 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10184 throw new IllegalArgumentException("modem does not support data throttling");
10185 }
10186
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010187 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10188 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010189 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010190 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10191 }
10192
Sarah Chinecc78c42022-03-31 21:16:48 -070010193 setDataEnabledForReason(
10194 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010195
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010196 if (isDataThrottlingSupported) {
10197 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010198 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010199 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10200 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10201 } else if (thermalMitigationResult
10202 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010203 log("Modem likely does not support data throttling on secondary carrier. Data " +
10204 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10205 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010206 }
10207 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010208 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010209
10210 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010211 }
10212
Jack Nudelman644b91a2021-03-12 14:09:48 -080010213 private static List<String> getThermalMitigationAllowlist(Context context) {
10214 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10215 for (String pckg : context.getResources()
10216 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10217 sThermalMitigationAllowlistedPackages.add(pckg);
10218 }
10219 }
10220
10221 return sThermalMitigationAllowlistedPackages;
10222 }
10223
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010224 private boolean isAnyPhoneInEmergencyState() {
10225 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10226 if (tm.isInEmergencyCall()) {
10227 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10228 return true;
10229 }
10230 for (Phone phone : PhoneFactory.getPhones()) {
10231 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10232 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10233 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10234 + phone.isInEcm());
10235 return true;
10236 }
10237 }
10238
10239 return false;
10240 }
10241
Jack Nudelman644b91a2021-03-12 14:09:48 -080010242 /**
10243 * Used by shell commands to add an authorized package name for thermal mitigation.
10244 * @param packageName name of package to be allowlisted
10245 * @param context
10246 */
10247 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10248 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10249 sThermalMitigationAllowlistedPackages.add(packageName);
10250 }
10251
10252 /**
10253 * Used by shell commands to remove an authorized package name for thermal mitigation.
10254 * @param packageName name of package to remove from allowlist
10255 * @param context
10256 */
10257 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10258 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10259 sThermalMitigationAllowlistedPackages.remove(packageName);
10260 }
10261
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010262 /**
10263 * Thermal mitigation request to control functionalities at modem.
10264 *
10265 * @param subId the id of the subscription.
10266 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010267 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010268 *
10269 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10270 */
10271 @Override
10272 @ThermalMitigationResult
10273 public int sendThermalMitigationRequest(
10274 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010275 ThermalMitigationRequest thermalMitigationRequest,
10276 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010277 enforceModifyPermission();
10278
Jack Nudelman644b91a2021-03-12 14:09:48 -080010279 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10280 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10281 .contains(callingPackage)) {
10282 throw new SecurityException("Calling package must be configured in the device config. "
10283 + "calling package: " + callingPackage);
10284 }
10285
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010286 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10287 final long identity = Binder.clearCallingIdentity();
10288
10289 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10290 try {
10291 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10292 switch (thermalMitigationAction) {
10293 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10294 thermalMitigationResult =
10295 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010296 thermalMitigationRequest.getDataThrottlingRequest(),
10297 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010298 break;
10299 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10300 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10301 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10302 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10303 }
10304
10305 // Ensure that radio is on. If not able to power on due to phone being
10306 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010307 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010308 thermalMitigationResult =
10309 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10310 break;
10311 }
10312
10313 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010314 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010315 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10316 break;
10317 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10318 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10319 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10320 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10321 }
10322
10323 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10324 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010325 Phone phone = getPhone(subId);
10326 if (phone == null) {
10327 thermalMitigationResult =
10328 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10329 break;
10330 }
10331
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010332 TelephonyConnectionService service =
10333 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010334 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010335 Log.e(LOG_TAG, "An emergency call is pending");
10336 thermalMitigationResult =
10337 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10338 break;
10339 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010340 thermalMitigationResult =
10341 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10342 break;
10343 }
10344 } else {
10345 thermalMitigationResult =
10346 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10347 break;
10348 }
10349
10350 // Turn radio off. If not able to power off due to phone being unavailable,
10351 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010352 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010353 thermalMitigationResult =
10354 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10355 break;
10356 }
10357 thermalMitigationResult =
10358 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10359 break;
10360 default:
10361 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10362 + "not exist. Requested action: " + thermalMitigationAction);
10363 }
10364 } catch (IllegalArgumentException e) {
10365 throw e;
10366 } catch (Exception e) {
10367 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10368 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10369 } finally {
10370 Binder.restoreCallingIdentity(identity);
10371 }
10372
10373 if (DBG) {
10374 log("thermalMitigationRequest returning with thermalMitigationResult: "
10375 + thermalMitigationResult);
10376 }
10377
10378 return thermalMitigationResult;
10379 }
Hui Wang641e81c2020-10-12 12:14:23 -070010380
10381 /**
10382 * Set the GbaService Package Name that Telephony will bind to.
10383 *
10384 * @param subId The sim that the GbaService is associated with.
10385 * @param packageName The name of the package to be replaced with.
10386 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10387 */
10388 @Override
10389 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10390 enforceModifyPermission();
10391
10392 final long identity = Binder.clearCallingIdentity();
10393 try {
10394 return getGbaManager(subId).overrideServicePackage(packageName);
10395 } finally {
10396 Binder.restoreCallingIdentity(identity);
10397 }
10398 }
10399
10400 /**
10401 * Return the package name of the currently bound GbaService.
10402 *
10403 * @param subId The sim that the GbaService is associated with.
10404 * @return the package name of the GbaService configuration, null if GBA is not supported.
10405 */
10406 @Override
10407 public String getBoundGbaService(int subId) {
10408 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10409
10410 final long identity = Binder.clearCallingIdentity();
10411 try {
10412 return getGbaManager(subId).getServicePackage();
10413 } finally {
10414 Binder.restoreCallingIdentity(identity);
10415 }
10416 }
10417
10418 /**
10419 * Set the release time for telephony to unbind GbaService.
10420 *
10421 * @param subId The sim that the GbaService is associated with.
10422 * @param interval The release time to unbind GbaService by millisecond.
10423 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10424 */
10425 @Override
10426 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10427 enforceModifyPermission();
10428
10429 final long identity = Binder.clearCallingIdentity();
10430 try {
10431 return getGbaManager(subId).overrideReleaseTime(interval);
10432 } finally {
10433 Binder.restoreCallingIdentity(identity);
10434 }
10435 }
10436
10437 /**
10438 * Return the release time for telephony to unbind GbaService.
10439 *
10440 * @param subId The sim that the GbaService is associated with.
10441 * @return The release time to unbind GbaService by millisecond.
10442 */
10443 @Override
10444 public int getGbaReleaseTime(int subId) {
10445 enforceReadPrivilegedPermission("getGbaReleaseTime");
10446
10447 final long identity = Binder.clearCallingIdentity();
10448 try {
10449 return getGbaManager(subId).getReleaseTime();
10450 } finally {
10451 Binder.restoreCallingIdentity(identity);
10452 }
10453 }
10454
10455 private GbaManager getGbaManager(int subId) {
10456 GbaManager instance = GbaManager.getInstance(subId);
10457 if (instance == null) {
10458 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10459 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10460 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10461 }
10462 return instance;
10463 }
Hui Wang761a6682020-10-31 05:12:53 +000010464
10465 /**
10466 * indicate whether the device and the carrier can support
10467 * RCS VoLTE single registration.
10468 */
10469 @Override
10470 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010471 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10472 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10473 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10474 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010475
10476 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10477 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10478 }
10479
10480 final long identity = Binder.clearCallingIdentity();
10481 try {
10482 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10483 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010484 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10485 if (isCapable != null) {
10486 return isCapable;
10487 }
Hui Wang761a6682020-10-31 05:12:53 +000010488 }
Hui Wang67af90e2021-06-04 16:57:15 -070010489 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10490 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010491 } finally {
10492 Binder.restoreCallingIdentity(identity);
10493 }
10494 }
10495
10496 /**
10497 * Register RCS provisioning callback.
10498 */
10499 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010500 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010501 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010502 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010503 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010504 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10505 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010506
10507 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10508 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10509 }
10510 if (!isImsAvailableOnDevice()) {
10511 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10512 "IMS not available on device.");
10513 }
10514
10515 final long identity = Binder.clearCallingIdentity();
10516 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010517 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010518 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010519 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10520 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010521 }
Hui Wang761a6682020-10-31 05:12:53 +000010522 } finally {
10523 Binder.restoreCallingIdentity(identity);
10524 }
10525 }
10526
10527 /**
10528 * Unregister RCS provisioning callback.
10529 */
10530 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010531 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010532 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010533 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010534 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010535 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10536 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010537
10538 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10539 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10540 }
10541 if (!isImsAvailableOnDevice()) {
10542 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10543 "IMS not available on device.");
10544 }
10545
10546 final long identity = Binder.clearCallingIdentity();
10547 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010548 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010549 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010550 } finally {
10551 Binder.restoreCallingIdentity(identity);
10552 }
10553 }
10554
10555 /**
10556 * trigger RCS reconfiguration.
10557 */
10558 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010559 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10560 "triggerRcsReconfiguration",
10561 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010562
10563 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10564 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10565 }
10566 if (!isImsAvailableOnDevice()) {
10567 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10568 "IMS not available on device.");
10569 }
10570
10571 final long identity = Binder.clearCallingIdentity();
10572 try {
10573 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10574 } finally {
10575 Binder.restoreCallingIdentity(identity);
10576 }
10577 }
10578
10579 /**
10580 * Provide the client configuration parameters of the RCS application.
10581 */
10582 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010583 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10584 "setRcsClientConfiguration",
10585 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010586
10587 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10588 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10589 }
10590 if (!isImsAvailableOnDevice()) {
10591 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10592 "IMS not available on device.");
10593 }
10594
10595 final long identity = Binder.clearCallingIdentity();
10596
10597 try {
10598 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10599 if (configBinder == null) {
10600 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010601 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10602 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010603 } else {
10604 configBinder.setRcsClientConfiguration(rcc);
10605 }
joonhunshin3e154242021-09-17 06:33:39 +000010606
10607 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10608 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010609 } catch (RemoteException e) {
10610 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010611 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10612 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010613 } finally {
10614 Binder.restoreCallingIdentity(identity);
10615 }
10616 }
10617
10618 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010619 * Enables or disables the test mode for RCS VoLTE single registration.
10620 */
10621 @Override
10622 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10623 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10624 "setRcsSingleRegistrationTestModeEnabled");
10625
10626 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10627 }
10628
10629 /**
10630 * Gets the test mode for RCS VoLTE single registration.
10631 */
10632 @Override
10633 public boolean getRcsSingleRegistrationTestModeEnabled() {
10634 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10635 "getRcsSingleRegistrationTestModeEnabled");
10636
10637 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10638 }
10639
10640 /**
Hui Wang761a6682020-10-31 05:12:53 +000010641 * Overrides the config of RCS VoLTE single registration enabled for the device.
10642 */
10643 @Override
10644 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10645 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10646 "setDeviceSingleRegistrationEnabledOverride");
10647 enforceModifyPermission();
10648
10649 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10650 : Boolean.parseBoolean(enabledStr);
10651 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010652 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010653 }
10654
10655 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010656 * Sends a device to device communication message. Only usable via shell.
10657 * @param message message to send.
10658 * @param value message value.
10659 */
10660 @Override
10661 public void sendDeviceToDeviceMessage(int message, int value) {
10662 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010663 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010664 enforceModifyPermission();
10665
10666 final long identity = Binder.clearCallingIdentity();
10667 try {
10668 TelephonyConnectionService service =
10669 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10670 if (service == null) {
10671 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10672 return;
10673 }
10674 service.sendTestDeviceToDeviceMessage(message, value);
10675 } finally {
10676 Binder.restoreCallingIdentity(identity);
10677 }
10678 }
10679
Tyler Gunnbabbda02021-02-10 11:05:02 -080010680 /**
10681 * Sets the specified device to device transport active.
10682 * @param transport The transport to set active.
10683 */
10684 @Override
10685 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10686 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10687 "setActiveDeviceToDeviceTransport");
10688 enforceModifyPermission();
10689
10690 final long identity = Binder.clearCallingIdentity();
10691 try {
10692 TelephonyConnectionService service =
10693 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10694 if (service == null) {
10695 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10696 return;
10697 }
10698 service.setActiveDeviceToDeviceTransport(transport);
10699 } finally {
10700 Binder.restoreCallingIdentity(identity);
10701 }
10702 }
Tyler Gunn92479152021-01-20 16:30:10 -080010703
Tyler Gunnd4339262021-05-03 14:46:49 -070010704 @Override
10705 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10706 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10707 "setDeviceToDeviceForceEnabled");
10708
10709 final long identity = Binder.clearCallingIdentity();
10710 try {
10711 Arrays.stream(PhoneFactory.getPhones()).forEach(
10712 p -> {
10713 Phone thePhone = p.getImsPhone();
10714 if (thePhone != null && thePhone instanceof ImsPhone) {
10715 ImsPhone imsPhone = (ImsPhone) thePhone;
10716 CallTracker tracker = imsPhone.getCallTracker();
10717 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10718 ImsPhoneCallTracker imsPhoneCallTracker =
10719 (ImsPhoneCallTracker) tracker;
10720 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10721 }
10722 }
10723 }
10724 );
10725 } finally {
10726 Binder.restoreCallingIdentity(identity);
10727 }
10728 }
10729
Tyler Gunn92479152021-01-20 16:30:10 -080010730 /**
Hui Wang761a6682020-10-31 05:12:53 +000010731 * Gets the config of RCS VoLTE single registration enabled for the device.
10732 */
10733 @Override
10734 public boolean getDeviceSingleRegistrationEnabled() {
10735 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10736 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10737 }
10738
10739 /**
10740 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10741 */
10742 @Override
10743 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10744 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10745 "setCarrierSingleRegistrationEnabledOverride");
10746 enforceModifyPermission();
10747
10748 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10749 : Boolean.parseBoolean(enabledStr);
10750 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10751 subId, enabled);
10752 }
10753
10754 /**
10755 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10756 */
10757 @Override
10758 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10759 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10760 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10761 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010762
10763 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010764 * Overrides the ims feature validation result
10765 */
10766 @Override
10767 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10768 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10769 "setImsFeatureValidationOverride");
10770
10771 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10772 : Boolean.parseBoolean(enabledStr);
10773 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10774 subId, enabled);
10775 }
10776
10777 /**
10778 * Gets the ims feature validation override value
10779 */
10780 @Override
10781 public boolean getImsFeatureValidationOverride(int subId) {
10782 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10783 "getImsFeatureValidationOverride");
10784 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10785 }
10786
10787 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010788 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10789 * their mobile plan.
10790 */
10791 @Override
10792 public String getMobileProvisioningUrl() {
10793 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10794 final long identity = Binder.clearCallingIdentity();
10795 try {
10796 return getDefaultPhone().getMobileProvisioningUrl();
10797 } finally {
10798 Binder.restoreCallingIdentity(identity);
10799 }
10800 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010801
James.cf Linbcdf8b32021-01-14 16:44:13 +080010802 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010803 * Get the EAB contact from the EAB database.
10804 */
10805 @Override
10806 public String getContactFromEab(String contact) {
10807 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10808 enforceModifyPermission();
10809 final long identity = Binder.clearCallingIdentity();
10810 try {
10811 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10812 } finally {
10813 Binder.restoreCallingIdentity(identity);
10814 }
10815 }
10816
10817 /**
Calvin Pana1434322021-07-01 19:27:01 +080010818 * Get the EAB capability from the EAB database.
10819 */
10820 @Override
10821 public String getCapabilityFromEab(String contact) {
10822 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10823 enforceModifyPermission();
10824 final long identity = Binder.clearCallingIdentity();
10825 try {
10826 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10827 } finally {
10828 Binder.restoreCallingIdentity(identity);
10829 }
10830 }
10831
10832 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010833 * Remove the EAB contacts from the EAB database.
10834 */
10835 @Override
10836 public int removeContactFromEab(int subId, String contacts) {
10837 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10838 enforceModifyPermission();
10839 final long identity = Binder.clearCallingIdentity();
10840 try {
10841 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10842 } finally {
10843 Binder.restoreCallingIdentity(identity);
10844 }
10845 }
10846
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010847 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010848 public boolean getDeviceUceEnabled() {
10849 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10850 final long identity = Binder.clearCallingIdentity();
10851 try {
10852 return mApp.getDeviceUceEnabled();
10853 } finally {
10854 Binder.restoreCallingIdentity(identity);
10855 }
10856 }
10857
10858 @Override
10859 public void setDeviceUceEnabled(boolean isEnabled) {
10860 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10861 final long identity = Binder.clearCallingIdentity();
10862 try {
10863 mApp.setDeviceUceEnabled(isEnabled);
10864 } finally {
10865 Binder.restoreCallingIdentity(identity);
10866 }
10867 }
10868
Brad Ebinger14d467f2021-02-12 06:18:28 +000010869 /**
10870 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10871 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10872 */
10873 // Used for SHELL command only right now.
10874 @Override
10875 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10876 List<String> featureTags) {
10877 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10878 "addUceRegistrationOverrideShell");
10879 final long identity = Binder.clearCallingIdentity();
10880 try {
10881 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10882 new ArraySet<>(featureTags));
10883 } catch (ImsException e) {
10884 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10885 } finally {
10886 Binder.restoreCallingIdentity(identity);
10887 }
10888 }
10889
10890 /**
10891 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10892 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10893 */
10894 // Used for SHELL command only right now.
10895 @Override
10896 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10897 List<String> featureTags) {
10898 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10899 "removeUceRegistrationOverrideShell");
10900 final long identity = Binder.clearCallingIdentity();
10901 try {
10902 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10903 new ArraySet<>(featureTags));
10904 } catch (ImsException e) {
10905 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10906 } finally {
10907 Binder.restoreCallingIdentity(identity);
10908 }
10909 }
10910
10911 /**
10912 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10913 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10914 */
10915 // Used for SHELL command only right now.
10916 @Override
10917 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10918 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10919 "clearUceRegistrationOverrideShell");
10920 final long identity = Binder.clearCallingIdentity();
10921 try {
10922 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10923 } catch (ImsException e) {
10924 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10925 } finally {
10926 Binder.restoreCallingIdentity(identity);
10927 }
10928 }
10929
10930 /**
10931 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10932 */
10933 // Used for SHELL command only right now.
10934 @Override
10935 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10936 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10937 "getLatestRcsContactUceCapabilityShell");
10938 final long identity = Binder.clearCallingIdentity();
10939 try {
10940 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10941 } catch (ImsException e) {
10942 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10943 } finally {
10944 Binder.restoreCallingIdentity(identity);
10945 }
10946 }
10947
10948 /**
10949 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10950 * device does not have an active PUBLISH.
10951 */
10952 // Used for SHELL command only right now.
10953 @Override
10954 public String getLastUcePidfXmlShell(int subId) {
10955 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10956 final long identity = Binder.clearCallingIdentity();
10957 try {
10958 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10959 } catch (ImsException e) {
10960 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10961 } finally {
10962 Binder.restoreCallingIdentity(identity);
10963 }
10964 }
10965
James.cf Line8713a42021-04-29 16:04:26 +080010966 /**
10967 * Remove UCE requests cannot be sent to the network status.
10968 */
10969 // Used for SHELL command only right now.
10970 @Override
10971 public boolean removeUceRequestDisallowedStatus(int subId) {
10972 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10973 final long identity = Binder.clearCallingIdentity();
10974 try {
10975 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10976 } catch (ImsException e) {
10977 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10978 } finally {
10979 Binder.restoreCallingIdentity(identity);
10980 }
10981 }
10982
James.cf Lin18bb9002021-05-25 01:37:38 +080010983 /**
10984 * Remove UCE requests cannot be sent to the network status.
10985 */
10986 // Used for SHELL command only.
10987 @Override
10988 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10989 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10990 final long identity = Binder.clearCallingIdentity();
10991 try {
10992 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10993 } catch (ImsException e) {
10994 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10995 } finally {
10996 Binder.restoreCallingIdentity(identity);
10997 }
10998 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010999
James.cf Lin4b784aa2021-01-31 03:25:15 +080011000 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011001 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11002 String callingPackage) {
11003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11004 mApp, subId, "setSignalStrengthUpdateRequest");
11005
11006 final int callingUid = Binder.getCallingUid();
11007 // Verify that tha callingPackage belongs to the calling UID
11008 mApp.getSystemService(AppOpsManager.class)
11009 .checkPackage(callingUid, callingPackage);
11010
Rambo Wang3607f502021-02-01 21:51:40 -080011011 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011012
11013 final long identity = Binder.clearCallingIdentity();
11014 try {
11015 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11016 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11017
11018 if (result instanceof IllegalStateException) {
11019 throw (IllegalStateException) result;
11020 }
11021 } finally {
11022 Binder.restoreCallingIdentity(identity);
11023 }
11024 }
11025
11026 @Override
11027 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11028 String callingPackage) {
11029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11030 mApp, subId, "clearSignalStrengthUpdateRequest");
11031
11032 final int callingUid = Binder.getCallingUid();
11033 // Verify that tha callingPackage belongs to the calling UID
11034 mApp.getSystemService(AppOpsManager.class)
11035 .checkPackage(callingUid, callingPackage);
11036
11037 final long identity = Binder.clearCallingIdentity();
11038 try {
11039 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11040 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11041
11042 if (result instanceof IllegalStateException) {
11043 throw (IllegalStateException) result;
11044 }
11045 } finally {
11046 Binder.restoreCallingIdentity(identity);
11047 }
11048 }
11049
Rambo Wang3607f502021-02-01 21:51:40 -080011050 private static void validateSignalStrengthUpdateRequest(Context context,
11051 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011052 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11053 // phone/system process do not have further restriction on request
11054 return;
11055 }
11056
11057 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011058 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011059 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011060 context.enforceCallingOrSelfPermission(
11061 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11062 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011063 }
11064
11065 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11066 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11067 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11068 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11069 || info.isEnabled()) {
11070 throw new IllegalArgumentException(
11071 "Only system can set hide fields in SignalThresholdInfo");
11072 }
11073
11074 // Thresholds length for each RAN need in range. This has been validated in
11075 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11076 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11077 final int[] thresholds = info.getThresholds();
11078 Objects.requireNonNull(thresholds);
11079 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11080 || thresholds.length
11081 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11082 throw new IllegalArgumentException(
11083 "thresholds length is out of range: " + thresholds.length);
11084 }
11085 }
11086 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011087
11088 /**
11089 * Gets the current phone capability.
11090 *
11091 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11092 * @return the PhoneCapability which describes the data connection capability of modem.
11093 * It's used to evaluate possible phone config change, for example from single
11094 * SIM device to multi-SIM device.
11095 */
11096 @Override
11097 public PhoneCapability getPhoneCapability() {
11098 enforceReadPrivilegedPermission("getPhoneCapability");
11099 final long identity = Binder.clearCallingIdentity();
11100 try {
11101 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11102 } finally {
11103 Binder.restoreCallingIdentity(identity);
11104 }
11105 }
Michele Berionne5e411512020-11-13 02:36:59 +000011106
11107 /**
11108 * Prepare TelephonyManager for an unattended reboot. The reboot is
11109 * required to be done shortly after the API is invoked.
11110 */
11111 @Override
11112 @TelephonyManager.PrepareUnattendedRebootResult
11113 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011114 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011115 enforceRebootPermission();
11116
11117 final long identity = Binder.clearCallingIdentity();
11118 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011119 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011120 } finally {
11121 Binder.restoreCallingIdentity(identity);
11122 }
11123 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011124
11125 /**
11126 * Request to get the current slicing configuration including URSP rules and
11127 * NSSAIs (configured, allowed and rejected).
11128 *
11129 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11130 */
11131 @Override
11132 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011133 TelephonyPermissions
11134 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11135 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011136
11137 final long identity = Binder.clearCallingIdentity();
11138 try {
11139 Phone phone = getDefaultPhone();
11140 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11141 } finally {
11142 Binder.restoreCallingIdentity(identity);
11143 }
11144 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011145
11146 /**
11147 * Register an IMS connection state callback
11148 */
11149 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011150 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11151 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011152 if (feature == ImsFeature.FEATURE_MMTEL) {
11153 // ImsMmTelManager
11154 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11155 TelephonyPermissions
11156 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11157 mApp, subId, "registerImsStateCallback");
11158 } else if (feature == ImsFeature.FEATURE_RCS) {
11159 // ImsRcsManager or SipDelegateManager
11160 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11161 Binder.getCallingUid(), "registerImsStateCallback",
11162 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11163 Manifest.permission.READ_PRECISE_PHONE_STATE,
11164 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11165 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11166 }
11167
11168 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11169 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11170 "IMS not available on device.");
11171 }
11172
11173 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11174 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11175 }
11176
11177 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11178 if (controller == null) {
11179 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11180 "IMS not available on device.");
11181 }
11182
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011183 if (callingPackage == null) {
11184 callingPackage = getCurrentPackageName();
11185 }
11186
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011187 final long token = Binder.clearCallingIdentity();
11188 try {
11189 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011190 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011191 } catch (ImsException e) {
11192 throw new ServiceSpecificException(e.getCode());
11193 } finally {
11194 Binder.restoreCallingIdentity(token);
11195 }
11196 }
11197
11198 /**
11199 * Unregister an IMS connection state callback
11200 */
11201 @Override
11202 public void unregisterImsStateCallback(IImsStateCallback cb) {
11203 final long token = Binder.clearCallingIdentity();
11204 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11205 if (controller == null) {
11206 return;
11207 }
11208 try {
11209 controller.unregisterImsStateCallback(cb);
11210 } finally {
11211 Binder.restoreCallingIdentity(token);
11212 }
11213 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011214
11215 /**
11216 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11217 *
11218 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11219 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11220 * SecurityException.
11221 * If there is current registered network this value will be same as the registered cell
11222 * identity. If the device goes out of service the previous cell identity is cached and
11223 * will be returned. If the cache age of the Cell identity is more than 24 hours
11224 * it will be cleared and null will be returned.
11225 *
11226 */
11227 @Override
11228 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11229 String callingFeatureId) {
11230 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11231 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11232 LocationAccessPolicy.checkLocationPermission(mApp,
11233 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11234 .setCallingPackage(callingPackage)
11235 .setCallingFeatureId(callingFeatureId)
11236 .setCallingPid(Binder.getCallingPid())
11237 .setCallingUid(Binder.getCallingUid())
11238 .setMethod("getLastKnownCellIdentity")
11239 .setLogAsInfo(true)
11240 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11241 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11242 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11243 .build());
11244
11245 boolean hasFinePermission =
11246 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11247 if (!hasFinePermission
11248 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11249 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011250 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011251 }
11252
11253 final long identity = Binder.clearCallingIdentity();
11254 try {
11255 Phone phone = getPhone(subId);
11256 if (phone == null) return null;
11257 ServiceStateTracker sst = phone.getServiceStateTracker();
11258 if (sst == null) return null;
11259 return sst.getLastKnownCellIdentity();
11260 } finally {
11261 Binder.restoreCallingIdentity(identity);
11262 }
11263 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011264
11265 @Override
11266 public boolean isUsingNewDataStack() {
11267 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11268 return getDefaultPhone().isUsingNewDataStack();
11269 }
jimsun3b9ccac2021-10-26 15:01:23 +080011270
11271 /**
11272 * Sets the modem service class Name that Telephony will bind to.
11273 *
11274 * @param serviceName The class name of the modem service.
11275 * @return true if the operation is succeed, otherwise false.
11276 */
11277 public boolean setModemService(String serviceName) {
11278 Log.d(LOG_TAG, "setModemService - " + serviceName);
11279 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11281 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11282 "setModemService");
11283 return mPhoneConfigurationManager.setModemService(serviceName);
11284 }
11285
11286 /**
11287 * Return the class name of the currently bounded modem service.
11288 *
11289 * @return the class name of the modem service.
11290 */
11291 public String getModemService() {
11292 String result;
11293 Log.d(LOG_TAG, "getModemService");
11294 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11295 TelephonyPermissions
11296 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11297 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11298 "getModemService");
11299 result = mPhoneConfigurationManager.getModemService();
11300 Log.d(LOG_TAG, "result = " + result);
11301 return result;
11302 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011303
11304 @Override
11305 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11306 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11307 mApp.enforceCallingOrSelfPermission(
11308 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11309 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11310
11311 final long identity = Binder.clearCallingIdentity();
11312 try {
11313 Phone phone = getPhone(subId);
11314 if (phone == null) return;
11315 phone.setVoiceServiceStateOverride(hasService);
11316 } finally {
11317 Binder.restoreCallingIdentity(identity);
11318 }
11319 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011320
11321 /**
11322 * set removable eSIM as default eUICC.
11323 *
11324 * @hide
11325 */
11326 @Override
11327 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11328 enforceModifyPermission();
11329 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11330
11331 final long identity = Binder.clearCallingIdentity();
11332 try {
11333 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11334 } finally {
11335 Binder.restoreCallingIdentity(identity);
11336 }
11337 }
11338
11339 /**
11340 * Returns whether the removable eSIM is default eUICC or not.
11341 *
11342 * @hide
11343 */
11344 @Override
11345 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11346 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11347 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11348
11349 final long identity = Binder.clearCallingIdentity();
11350 try {
11351 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11352 } finally {
11353 Binder.restoreCallingIdentity(identity);
11354 }
11355 }
11356
11357
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011358}