blob: 706373bf2c813fb60949ff62cde662c47071b43c [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 hsue9360cd2022-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;
Ryan Savitskicab25c52023-03-14 14:23:49 +0000112import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800113import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800114import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800115import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000116import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000117import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000118import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700119import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700120import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800121import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800122import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700123import android.telephony.gba.GbaAuthRequest;
124import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700125import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800126import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000127import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000128import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700129import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000130import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700131import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800132import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700133import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800134import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700135import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000136import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700137import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800138import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800139import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800141import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700142import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800144import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800145
Andrew Lee312e8172014-10-23 17:01:36 -0700146import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800147import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800148import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800149import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800150import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700151import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700152import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700153import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800154import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800155import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700156import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700157import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800158import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700159import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800160import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800161import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800162import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700163import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000164import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800166import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.telephony.IccCard;
Ryan Savitskicab25c52023-03-14 14:23:49 +0000169import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800170import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700172import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700173import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700175import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800176import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700177import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700178import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700179import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700180import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800181import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800182import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700183import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700184import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700185import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800186import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800187import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800188import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700189import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800190import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700191import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800192import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700193import com.android.internal.telephony.imsphone.ImsPhone;
194import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000195import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800196import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yudf049d72022-12-02 22:48:35 -0800197import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
198import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700199import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700200import com.android.internal.telephony.uicc.IccIoResult;
201import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800202import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700203import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800204import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700205import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000206import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800207import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000208import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800209import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700210import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700211import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800212import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800213import com.android.phone.callcomposer.CallComposerPictureManager;
214import com.android.phone.callcomposer.CallComposerPictureTransfer;
215import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700216import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700217import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800218import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700219import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700220import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800221import com.android.services.telephony.TelecomAccountRegistry;
222import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800223import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800224
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700226import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800227import java.io.IOException;
228import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700229import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700230import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800231import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000232import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800233import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800234import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800235import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800236import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100237import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800238import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700239import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800240import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800241import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800242import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800243import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800244import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245
246/**
247 * Implementation of the ITelephony interface.
248 */
Santos Cordon117fee72014-05-16 17:56:12 -0700249public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250 private static final String LOG_TAG = "PhoneInterfaceManager";
251 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
252 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800253 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254
255 // Message codes used with mMainThreadHandler
256 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700257 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
258 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700259 private static final int CMD_OPEN_CHANNEL = 9;
260 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
261 private static final int CMD_CLOSE_CHANNEL = 11;
262 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800263 private static final int CMD_NV_READ_ITEM = 13;
264 private static final int EVENT_NV_READ_ITEM_DONE = 14;
265 private static final int CMD_NV_WRITE_ITEM = 15;
266 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
267 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
268 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700269 private static final int CMD_RESET_MODEM_CONFIG = 19;
270 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800271 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
272 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800273 private static final int CMD_SEND_ENVELOPE = 25;
274 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000275 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
276 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700277 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
278 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
279 private static final int CMD_EXCHANGE_SIM_IO = 31;
280 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800281 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
282 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700283 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
284 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700285 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
286 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700287 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
288 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
289 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
290 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700291 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
292 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
293 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
294 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700295 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800296 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
297 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000298 private static final int CMD_SWITCH_SLOTS = 50;
299 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700300 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
301 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
302 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
303 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
304 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
305 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
306 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
307 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700308 private static final int CMD_GET_ALL_CELL_INFO = 60;
309 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
310 private static final int CMD_GET_CELL_LOCATION = 62;
311 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700312 private static final int CMD_MODEM_REBOOT = 64;
313 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700314 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
315 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800316 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
317 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700318 private static final int CMD_GET_MODEM_STATUS = 70;
319 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700320 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
321 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700322 private static final int CMD_ERASE_MODEM_CONFIG = 74;
323 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800324 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
325 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
326 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
327 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800328 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
329 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800330 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800331 private static final int CMD_GET_CALL_FORWARDING = 83;
332 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
333 private static final int CMD_SET_CALL_FORWARDING = 85;
334 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
335 private static final int CMD_GET_CALL_WAITING = 87;
336 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
337 private static final int CMD_SET_CALL_WAITING = 89;
338 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700339 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
340 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
341 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
342 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700343 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
344 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800345 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
346 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800347 private static final int CMD_SET_DATA_THROTTLING = 99;
348 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800349 private static final int CMD_SET_SIM_POWER = 101;
350 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800351 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
352 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
353 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
354 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800355 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
356 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000357 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800358 private static final int CMD_GET_SLICING_CONFIG = 110;
359 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800360 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700361 private static final int CMD_ENABLE_VONR = 113;
362 private static final int EVENT_ENABLE_VONR_DONE = 114;
363 private static final int CMD_IS_VONR_ENABLED = 115;
364 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800366 // Parameters of select command.
367 private static final int SELECT_COMMAND = 0xA4;
368 private static final int SELECT_P1 = 0x04;
369 private static final int SELECT_P2 = 0;
370 private static final int SELECT_P3 = 0x10;
371
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 /** The singleton instance. */
373 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800374 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800378 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700379 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800380 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700381 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800382 private MainThreadHandler mMainThreadHandler;
Jack Yu5e360c42022-12-16 11:53:37 -0800383 private final SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800384 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700385 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800386 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000387 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388
Peter Wangdafb9ac2020-01-15 14:13:38 -0800389 /** User Activity */
390 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800391 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
392
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700393 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
394
Derek Tan97ebb422014-09-05 16:55:38 -0700395 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
396 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800397 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800398 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700399
Michelecea4cf22018-12-21 15:00:11 -0800400 // String to store multi SIM allowed
401 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
402
Derek Tan740e1672017-06-27 14:56:27 -0700403 // The AID of ISD-R.
404 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
405
yinxub1bed742017-04-17 11:45:04 -0700406 private NetworkScanRequestTracker mNetworkScanRequestTracker;
407
David Kelly5e06a7f2018-03-12 14:10:59 +0000408 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
409 private static final int MANUFACTURER_CODE_LENGTH = 8;
410
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800411 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800412 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800413
Derek Tan89e89d42014-07-08 17:00:10 -0700414 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700415 * Experiment flag to enable erase modem config on reset network, default value is false
416 */
417 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
418 "reset_network_erase_modem_config_enabled";
419
Rambo Wang0f050d82021-02-12 11:43:36 -0800420 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800421
sandeepjsb6c87872021-09-27 15:34:44 +0000422 /**
423 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
424 * one ICCID active at the same time.
425 * Apps should use below API signatures if targeting SDK is T and beyond.
426 *
427 * @hide
428 */
429 @ChangeId
430 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
431 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800432
Naina Nallurid63128d2019-09-17 14:10:30 -0700433 /**
Chen Xu540470b2021-12-14 17:15:47 -0800434 * Apps targeting on Android T and beyond will get exception whenever icc close channel
435 * operation fails.
436 */
437 @ChangeId
438 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
439 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
440
441 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 * A request object to use for transmitting data to an ICC.
443 */
444 private static final class IccAPDUArgument {
445 public int channel, cla, command, p1, p2, p3;
446 public String data;
447
448 public IccAPDUArgument(int channel, int cla, int command,
449 int p1, int p2, int p3, String data) {
450 this.channel = channel;
451 this.cla = cla;
452 this.command = command;
453 this.p1 = p1;
454 this.p2 = p2;
455 this.p3 = p3;
456 this.data = data;
457 }
458 }
459
460 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700461 * A request object to use for transmitting data to an ICC.
462 */
463 private static final class ManualNetworkSelectionArgument {
464 public OperatorInfo operatorInfo;
465 public boolean persistSelection;
466
467 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
468 this.operatorInfo = operatorInfo;
469 this.persistSelection = persistSelection;
470 }
471 }
472
473 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
475 * request after sending. The main thread will notify the request when it is complete.
476 */
477 private static final class MainThreadRequest {
478 /** The argument to use for the request */
479 public Object argument;
480 /** The result of the request that is run on the main thread */
481 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800482 // The subscriber id that this request applies to. Defaults to
483 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
484 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485
Nathan Harold92bed182018-10-12 18:16:49 -0700486 // In cases where subId is unavailable, the caller needs to specify the phone.
487 public Phone phone;
488
vagdeviaf9a5b92018-08-15 16:01:53 -0700489 public WorkSource workSource;
490
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700491 public MainThreadRequest(Object argument) {
492 this.argument = argument;
493 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800494
Nathan Harold92bed182018-10-12 18:16:49 -0700495 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
496 this.argument = argument;
497 if (phone != null) {
498 this.phone = phone;
499 }
500 this.workSource = workSource;
501 }
502
vagdeviaf9a5b92018-08-15 16:01:53 -0700503 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800504 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800505 if (subId != null) {
506 this.subId = subId;
507 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700508 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510 }
511
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800512 private static final class IncomingThirdPartyCallArgs {
513 public final ComponentName component;
514 public final String callId;
515 public final String callerDisplayName;
516
517 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
518 String callerDisplayName) {
519 this.component = component;
520 this.callId = callId;
521 this.callerDisplayName = callerDisplayName;
522 }
523 }
524
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 /**
526 * A handler that processes messages on the main thread in the phone process. Since many
527 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
528 * inbound binder threads to the main thread in the phone process. The Binder thread
529 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
530 * on, which will be notified when the operation completes and will contain the result of the
531 * request.
532 *
533 * <p>If a MainThreadRequest object is provided in the msg.obj field,
534 * note that request.result must be set to something non-null for the calling thread to
535 * unblock.
536 */
537 private final class MainThreadHandler extends Handler {
538 @Override
539 public void handleMessage(Message msg) {
540 MainThreadRequest request;
541 Message onCompleted;
542 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000543 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700544 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800545 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546
547 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 case CMD_HANDLE_USSD_REQUEST: {
549 request = (MainThreadRequest) msg.obj;
550 final Phone phone = getPhoneFromRequest(request);
551 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800552 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700553 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700554
Pengquan Menga1bb6272018-09-06 09:59:22 -0700555 if (!isUssdApiAllowed(request.subId)) {
556 // Carrier does not support use of this API, return failure.
557 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
558 UssdResponse response = new UssdResponse(ussdRequest, null);
559 Bundle returnData = new Bundle();
560 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
561 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700562
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 request.result = true;
564 notifyRequester(request);
565 return;
566 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700567
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 try {
569 request.result = phone != null
570 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
571 } catch (CallStateException cse) {
572 request.result = false;
573 }
574 // Wake up the requesting thread
575 notifyRequester(request);
576 break;
pkanwar32d516d2016-10-14 19:37:38 -0700577 }
578
Yorke Lee716f67e2015-06-17 15:39:16 -0700579 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700580 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700581 final Phone phone = getPhoneFromRequest(request);
582 request.result = phone != null ?
583 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
584 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700585 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700586 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700587 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700589
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000593 uiccPort = getUiccPortFromRequest(request);
594 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800596 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800600 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000601 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800602 iccArgument.channel, iccArgument.cla, iccArgument.command,
603 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
604 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700605 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 break;
607
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700608 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 ar = (AsyncResult) msg.obj;
610 request = (MainThreadRequest) ar.userObj;
611 if (ar.exception == null && ar.result != null) {
612 request.result = ar.result;
613 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800614 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 if (ar.result == null) {
616 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800617 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800619 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 } else {
621 loge("iccTransmitApduLogicalChannel: Unknown exception");
622 }
623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 break;
626
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
628 request = (MainThreadRequest) msg.obj;
629 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000630 uiccPort = getUiccPortFromRequest(request);
631 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800633 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 } else {
636 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800637 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000638 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800639 iccArgument.cla, iccArgument.command, iccArgument.p1,
640 iccArgument.p2,
641 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 }
643 break;
644
645 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
646 ar = (AsyncResult) msg.obj;
647 request = (MainThreadRequest) ar.userObj;
648 if (ar.exception == null && ar.result != null) {
649 request.result = ar.result;
650 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800651 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 if (ar.result == null) {
653 loge("iccTransmitApduBasicChannel: Empty response");
654 } else if (ar.exception instanceof CommandException) {
655 loge("iccTransmitApduBasicChannel: CommandException: " +
656 ar.exception);
657 } else {
658 loge("iccTransmitApduBasicChannel: Unknown exception");
659 }
660 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700661 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 break;
663
664 case CMD_EXCHANGE_SIM_IO:
665 request = (MainThreadRequest) msg.obj;
666 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000667 uiccPort = getUiccPortFromRequest(request);
668 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800670 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700671 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 } else {
673 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
674 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000675 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
677 iccArgument.data, onCompleted);
678 }
679 break;
680
681 case EVENT_EXCHANGE_SIM_IO_DONE:
682 ar = (AsyncResult) msg.obj;
683 request = (MainThreadRequest) ar.userObj;
684 if (ar.exception == null && ar.result != null) {
685 request.result = ar.result;
686 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800687 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700689 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700690 break;
691
Derek Tan4d5e5c12014-02-04 11:54:58 -0800692 case CMD_SEND_ENVELOPE:
693 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000694 uiccPort = getUiccPortFromRequest(request);
695 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700696 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800697 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700698 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700699 } else {
700 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800701 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700702 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800703 break;
704
705 case EVENT_SEND_ENVELOPE_DONE:
706 ar = (AsyncResult) msg.obj;
707 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700708 if (ar.exception == null && ar.result != null) {
709 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800710 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800711 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700712 if (ar.result == null) {
713 loge("sendEnvelopeWithStatus: Empty response");
714 } else if (ar.exception instanceof CommandException) {
715 loge("sendEnvelopeWithStatus: CommandException: " +
716 ar.exception);
717 } else {
718 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
719 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800720 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700721 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800722 break;
723
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 case CMD_OPEN_CHANNEL:
725 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000726 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800727 IccLogicalChannelRequest openChannelRequest =
728 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000729 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700730 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800731 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800732 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700733 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700734 } else {
735 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800736 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
737 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700738 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 break;
740
741 case EVENT_OPEN_CHANNEL_DONE:
742 ar = (AsyncResult) msg.obj;
743 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700744 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700745 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700746 int[] result = (int[]) ar.result;
747 int channelId = result[0];
748 byte[] selectResponse = null;
749 if (result.length > 1) {
750 selectResponse = new byte[result.length - 1];
751 for (int i = 1; i < result.length; ++i) {
752 selectResponse[i - 1] = (byte) result[i];
753 }
754 }
755 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800756 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800757
758 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700759 if (uiccPort == null) {
760 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
761 } else {
762 IccLogicalChannelRequest channelRequest =
763 (IccLogicalChannelRequest) request.argument;
764 channelRequest.channel = channelId;
765 uiccPort.onLogicalChannelOpened(channelRequest);
766 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700767 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 if (ar.result == null) {
769 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700771 if (ar.exception != null) {
772 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
773 }
774
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700775 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700776 if (ar.exception instanceof CommandException) {
777 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800778 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700779 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700780 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700781 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700782 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700783 }
784 }
785 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800786 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700788 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700789 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 break;
791
792 case CMD_CLOSE_CHANNEL:
793 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000794 uiccPort = getUiccPortFromRequest(request);
795 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700796 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800797 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800798 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800799 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700800 } else {
801 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000802 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700803 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700804 break;
805
806 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800807 ar = (AsyncResult) msg.obj;
808 request = (MainThreadRequest) ar.userObj;
809 if (ar.exception == null) {
810 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800811 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700812 if (uiccPort == null) {
813 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
814 } else {
815 final int channelId = (Integer) request.argument;
816 uiccPort.onLogicalChannelClosed(channelId);
817 }
Chen Xu540470b2021-12-14 17:15:47 -0800818 } else {
819 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800820 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800821 if (ar.exception instanceof CommandException) {
822 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
823 CommandException.Error error =
824 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800825 if (error == CommandException.Error.INVALID_ARGUMENTS) {
826 // should only throw exceptions from the binder threads.
827 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800828 "iccCloseLogicalChannel: invalid argument ");
829 }
830 } else {
831 loge("iccCloseLogicalChannel: Unknown exception");
832 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800833 request.result = (exception != null) ? exception :
834 new IllegalStateException(
835 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800836 }
837 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800838 break;
839
840 case CMD_NV_READ_ITEM:
841 request = (MainThreadRequest) msg.obj;
842 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800843 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
844 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800845 break;
846
847 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 ar = (AsyncResult) msg.obj;
849 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800850 if (ar.exception == null && ar.result != null) {
851 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700852 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800853 request.result = "";
854 if (ar.result == null) {
855 loge("nvReadItem: Empty response");
856 } else if (ar.exception instanceof CommandException) {
857 loge("nvReadItem: CommandException: " +
858 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700859 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800860 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700861 }
862 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700863 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700864 break;
865
Jake Hambye994d462014-02-03 13:10:13 -0800866 case CMD_NV_WRITE_ITEM:
867 request = (MainThreadRequest) msg.obj;
868 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
869 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800870 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700871 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800872 break;
873
874 case EVENT_NV_WRITE_ITEM_DONE:
875 handleNullReturnEvent(msg, "nvWriteItem");
876 break;
877
878 case CMD_NV_WRITE_CDMA_PRL:
879 request = (MainThreadRequest) msg.obj;
880 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800881 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800882 break;
883
884 case EVENT_NV_WRITE_CDMA_PRL_DONE:
885 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
886 break;
887
chen xu6dac5ab2018-10-26 17:39:23 -0700888 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800889 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700890 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800891 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800892 break;
893
chen xu6dac5ab2018-10-26 17:39:23 -0700894 case EVENT_RESET_MODEM_CONFIG_DONE:
895 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800896 break;
897
Sooraj Sasindran37444802020-08-11 10:40:43 -0700898 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
901 request);
902 Phone phone = getPhoneFromRequest(request);
903 if (phone != null) {
904 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
905 } else {
906 loge("isNRDualConnectivityEnabled: No phone object");
907 request.result = false;
908 notifyRequester(request);
909 }
910 break;
911 }
912
913 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
916 if (ar.exception == null && ar.result != null) {
917 request.result = ar.result;
918 } else {
919 // request.result must be set to something non-null
920 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700921 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700922 request.result = ar.result;
923 } else {
924 request.result = false;
925 }
926 if (ar.result == null) {
927 loge("isNRDualConnectivityEnabled: Empty response");
928 } else if (ar.exception instanceof CommandException) {
929 loge("isNRDualConnectivityEnabled: CommandException: "
930 + ar.exception);
931 } else {
932 loge("isNRDualConnectivityEnabled: Unknown exception");
933 }
934 }
935 notifyRequester(request);
936 break;
937
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700938 case CMD_IS_VONR_ENABLED: {
939 request = (MainThreadRequest) msg.obj;
940 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
941 request);
942 Phone phone = getPhoneFromRequest(request);
943 if (phone != null) {
944 phone.isVoNrEnabled(onCompleted, request.workSource);
945 } else {
946 loge("isVoNrEnabled: No phone object");
947 request.result = false;
948 notifyRequester(request);
949 }
950 break;
951 }
952
953 case EVENT_IS_VONR_ENABLED_DONE:
954 ar = (AsyncResult) msg.obj;
955 request = (MainThreadRequest) ar.userObj;
956 if (ar.exception == null && ar.result != null) {
957 request.result = ar.result;
958 } else {
959 // request.result must be set to something non-null
960 // for the calling thread to unblock
961 if (ar.result != null) {
962 request.result = ar.result;
963 } else {
964 request.result = false;
965 }
966 if (ar.result == null) {
967 loge("isVoNrEnabled: Empty response");
968 } else if (ar.exception instanceof CommandException) {
969 loge("isVoNrEnabled: CommandException: "
970 + ar.exception);
971 } else {
972 loge("isVoNrEnabled: Unknown exception");
973 }
974 }
975 notifyRequester(request);
976 break;
977
Sooraj Sasindran37444802020-08-11 10:40:43 -0700978 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
979 request = (MainThreadRequest) msg.obj;
980 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
981 Phone phone = getPhoneFromRequest(request);
982 if (phone != null) {
983 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
984 request.workSource);
985 } else {
986 loge("enableNrDualConnectivity: No phone object");
987 request.result =
988 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
989 notifyRequester(request);
990 }
991 break;
992 }
993
994 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
997 if (ar.exception == null) {
998 request.result =
999 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1000 } else {
1001 request.result =
1002 TelephonyManager
1003 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1004 if (ar.exception instanceof CommandException) {
1005 CommandException.Error error =
1006 ((CommandException) (ar.exception)).getCommandError();
1007 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1008 request.result =
1009 TelephonyManager
1010 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001011 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1012 request.result =
1013 TelephonyManager
1014 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001015 }
1016 loge("enableNrDualConnectivity" + ": CommandException: "
1017 + ar.exception);
1018 } else {
1019 loge("enableNrDualConnectivity" + ": Unknown exception");
1020 }
1021 }
1022 notifyRequester(request);
1023 break;
1024 }
1025
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001026 case CMD_ENABLE_VONR: {
1027 request = (MainThreadRequest) msg.obj;
1028 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1029 Phone phone = getPhoneFromRequest(request);
1030 if (phone != null) {
1031 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1032 request.workSource);
1033 } else {
1034 loge("setVoNrEnabled: No phone object");
1035 request.result =
1036 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1037 notifyRequester(request);
1038 }
1039 break;
1040 }
1041
1042 case EVENT_ENABLE_VONR_DONE: {
1043 ar = (AsyncResult) msg.obj;
1044 request = (MainThreadRequest) ar.userObj;
1045 if (ar.exception == null) {
1046 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1047 } else {
1048 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1049 if (ar.exception instanceof CommandException) {
1050 CommandException.Error error =
1051 ((CommandException) (ar.exception)).getCommandError();
1052 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1053 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1054 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1055 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1056 } else {
1057 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1058 }
1059 loge("setVoNrEnabled" + ": CommandException: "
1060 + ar.exception);
1061 } else {
1062 loge("setVoNrEnabled" + ": Unknown exception");
1063 }
1064 }
1065 notifyRequester(request);
1066 break;
1067 }
1068
SongFerngWang3ef3e072020-12-21 16:41:52 +08001069 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001070 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001071 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1072 request);
1073 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001074 break;
1075
SongFerngWang3ef3e072020-12-21 16:41:52 +08001076 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001077 ar = (AsyncResult) msg.obj;
1078 request = (MainThreadRequest) ar.userObj;
1079 if (ar.exception == null && ar.result != null) {
1080 request.result = ar.result; // Integer
1081 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301082 // request.result must be set to something non-null
1083 // for the calling thread to unblock
1084 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001087 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001088 loge("getAllowedNetworkTypesBitmask: CommandException: "
1089 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001090 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001091 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001092 }
1093 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001094 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001095 break;
1096
SongFerngWang3ef3e072020-12-21 16:41:52 +08001097 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001098 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001099 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1100 request);
1101 Pair<Integer, Long> reasonWithNetworkTypes =
1102 (Pair<Integer, Long>) request.argument;
1103 getPhoneFromRequest(request).setAllowedNetworkTypes(
1104 reasonWithNetworkTypes.first,
1105 reasonWithNetworkTypes.second,
1106 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001107 break;
1108
SongFerngWang3ef3e072020-12-21 16:41:52 +08001109 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1110 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001111 break;
1112
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001113 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1114 request = (MainThreadRequest)msg.obj;
1115 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001116 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001117 break;
1118
1119 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1120 ar = (AsyncResult)msg.obj;
1121 request = (MainThreadRequest)ar.userObj;
1122 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001123 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001124 break;
1125
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001126 case CMD_SET_VOICEMAIL_NUMBER:
1127 request = (MainThreadRequest) msg.obj;
1128 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1129 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001130 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1131 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001132 break;
1133
1134 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1135 handleNullReturnEvent(msg, "setVoicemailNumber");
1136 break;
1137
Stuart Scott54788802015-03-30 13:18:01 -07001138 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1141 request);
1142 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1143 break;
1144
1145 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1146 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1147 break;
1148
Shishir Agrawal302c8692015-06-19 13:49:39 -07001149 case CMD_PERFORM_NETWORK_SCAN:
1150 request = (MainThreadRequest) msg.obj;
1151 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1152 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1153 break;
1154
Hall Liu27d24262020-09-18 19:04:59 -07001155 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001156 request = (MainThreadRequest) msg.obj;
1157 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001158 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1159 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1160 request.argument;
1161 int callForwardingReason = args.first;
1162 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001163 break;
Hall Liu27d24262020-09-18 19:04:59 -07001164 }
1165 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001166 ar = (AsyncResult) msg.obj;
1167 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001168 TelephonyManager.CallForwardingInfoCallback callback =
1169 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1170 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001171 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001172 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001173 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1174 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1175 // Service Class is a bit mask per 3gpp 27.007. Search for
1176 // any service for voice call.
1177 if ((callForwardInfo.serviceClass
1178 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001179 callForwardingInfo = new CallForwardingInfo(
1180 callForwardInfo.status
1181 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001182 callForwardInfo.reason,
1183 callForwardInfo.number,
1184 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001185 break;
1186 }
1187 }
1188 // Didn't find a call forward info for voice call.
1189 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001190 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1191 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001192 }
Hall Liu27d24262020-09-18 19:04:59 -07001193 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001194 } else {
1195 if (ar.result == null) {
1196 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1197 }
1198 if (ar.exception != null) {
1199 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1200 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001201 int errorCode = TelephonyManager
1202 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001203 if (ar.exception instanceof CommandException) {
1204 CommandException.Error error =
1205 ((CommandException) (ar.exception)).getCommandError();
1206 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001207 errorCode = TelephonyManager
1208 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001209 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001210 errorCode = TelephonyManager
1211 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001212 }
1213 }
Hall Liu27d24262020-09-18 19:04:59 -07001214 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001215 }
Shuo Qian4a594052020-01-23 11:59:30 -08001216 break;
Hall Liu27d24262020-09-18 19:04:59 -07001217 }
Shuo Qian4a594052020-01-23 11:59:30 -08001218
Hall Liu27d24262020-09-18 19:04:59 -07001219 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001220 request = (MainThreadRequest) msg.obj;
1221 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001222 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001223 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001224 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1225 request.argument).first;
1226 request.phone.setCallForwardingOption(
1227 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001228 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001229 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001230 callForwardingInfoToSet.getReason(),
1231 callForwardingInfoToSet.getNumber(),
1232 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1233 break;
Hall Liu27d24262020-09-18 19:04:59 -07001234 }
Shuo Qian4a594052020-01-23 11:59:30 -08001235
Hall Liu27d24262020-09-18 19:04:59 -07001236 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001237 ar = (AsyncResult) msg.obj;
1238 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001239 Consumer<Integer> callback =
1240 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1241 request.argument).second;
1242 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001243 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001244 int errorCode = TelephonyManager.CallForwardingInfoCallback
1245 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001246 if (ar.exception instanceof CommandException) {
1247 CommandException.Error error =
1248 ((CommandException) (ar.exception)).getCommandError();
1249 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001250 errorCode = TelephonyManager.CallForwardingInfoCallback
1251 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001252 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001253 errorCode = TelephonyManager.CallForwardingInfoCallback
1254 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001255 }
1256 }
1257 callback.accept(errorCode);
1258 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001259 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001260 }
Shuo Qian4a594052020-01-23 11:59:30 -08001261 break;
Hall Liu27d24262020-09-18 19:04:59 -07001262 }
Shuo Qian4a594052020-01-23 11:59:30 -08001263
Hall Liu27d24262020-09-18 19:04:59 -07001264 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001265 request = (MainThreadRequest) msg.obj;
1266 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1267 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1268 break;
Hall Liu27d24262020-09-18 19:04:59 -07001269 }
Shuo Qian4a594052020-01-23 11:59:30 -08001270
Hall Liu27d24262020-09-18 19:04:59 -07001271 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001272 ar = (AsyncResult) msg.obj;
1273 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001274 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001275 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001276 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001277 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001278 // Service Class is a bit mask per 3gpp 27.007.
1279 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001280 if (callForwardResults.length > 1
1281 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001282 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001283 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001284 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1285 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001286 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001287 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001288 }
1289 } else {
1290 if (ar.result == null) {
1291 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1292 }
1293 if (ar.exception != null) {
1294 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1295 }
1296 if (ar.exception instanceof CommandException) {
1297 CommandException.Error error =
1298 ((CommandException) (ar.exception)).getCommandError();
1299 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001300 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001301 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001302 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1303 callWaitingStatus =
1304 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001305 }
1306 }
1307 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001308 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001309 break;
Hall Liu27d24262020-09-18 19:04:59 -07001310 }
Shuo Qian4a594052020-01-23 11:59:30 -08001311
Hall Liu27d24262020-09-18 19:04:59 -07001312 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001313 request = (MainThreadRequest) msg.obj;
1314 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001315 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1316 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001317 break;
Hall Liu27d24262020-09-18 19:04:59 -07001318 }
Shuo Qian4a594052020-01-23 11:59:30 -08001319
Hall Liu27d24262020-09-18 19:04:59 -07001320 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001321 ar = (AsyncResult) msg.obj;
1322 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001323 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1324 Consumer<Integer> callback =
1325 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1326 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001327 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001328 if (ar.exception instanceof CommandException) {
1329 CommandException.Error error =
1330 ((CommandException) (ar.exception)).getCommandError();
1331 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1332 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001333 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1334 callback.accept(
1335 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001336 } else {
1337 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1338 }
1339 } else {
1340 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1341 }
1342 } else {
1343 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1344 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001345 }
Shuo Qian4a594052020-01-23 11:59:30 -08001346 break;
Hall Liu27d24262020-09-18 19:04:59 -07001347 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001348 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1349 ar = (AsyncResult) msg.obj;
1350 request = (MainThreadRequest) ar.userObj;
1351 CellNetworkScanResult cellScanResult;
1352 if (ar.exception == null && ar.result != null) {
1353 cellScanResult = new CellNetworkScanResult(
1354 CellNetworkScanResult.STATUS_SUCCESS,
1355 (List<OperatorInfo>) ar.result);
1356 } else {
1357 if (ar.result == null) {
1358 loge("getCellNetworkScanResults: Empty response");
1359 }
1360 if (ar.exception != null) {
1361 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1362 }
1363 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1364 if (ar.exception instanceof CommandException) {
1365 CommandException.Error error =
1366 ((CommandException) (ar.exception)).getCommandError();
1367 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1368 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1369 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1370 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1371 }
1372 }
1373 cellScanResult = new CellNetworkScanResult(errorCode, null);
1374 }
1375 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001376 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001377 break;
1378
1379 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1380 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001381 ManualNetworkSelectionArgument selArg =
1382 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001383 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1384 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001385 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1386 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001387 break;
1388
1389 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001390 ar = (AsyncResult) msg.obj;
1391 request = (MainThreadRequest) ar.userObj;
1392 if (ar.exception == null) {
1393 request.result = true;
1394 } else {
1395 request.result = false;
1396 loge("setNetworkSelectionModeManual " + ar.exception);
1397 }
1398 notifyRequester(request);
1399 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001400 break;
1401
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001402 case CMD_GET_MODEM_ACTIVITY_INFO:
1403 request = (MainThreadRequest) msg.obj;
1404 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001405 if (defaultPhone != null) {
1406 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001407 } else {
1408 ResultReceiver result = (ResultReceiver) request.argument;
1409 Bundle bundle = new Bundle();
1410 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001411 new ModemActivityInfo(0, 0, 0,
1412 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001413 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001414 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001415 break;
1416
Hall Liud0f208c2020-10-14 16:54:44 -07001417 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001418 ar = (AsyncResult) msg.obj;
1419 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001420 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001421 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001422 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001423 if (mLastModemActivityInfo == null) {
1424 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1425 mLastModemActivitySpecificInfo[0] =
1426 new ActivityStatsTechSpecificInfo(
1427 0,
1428 0,
1429 new int[ModemActivityInfo.getNumTxPowerLevels()],
1430 0);
1431 mLastModemActivityInfo =
1432 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1433 }
1434
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001435 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001436 // Update the last modem activity info and the result of the request.
1437 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1438 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001439 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001440 }
Kai Shi917fdc62022-11-28 14:01:02 -08001441 // This is needed to decouple ret from mLastModemActivityInfo
1442 // We don't want to return mLastModemActivityInfo which is updated
1443 // inside mergeModemActivityInfo()
1444 ret = new ModemActivityInfo(
1445 mLastModemActivityInfo.getTimestampMillis(),
1446 mLastModemActivityInfo.getSleepTimeMillis(),
1447 mLastModemActivityInfo.getIdleTimeMillis(),
1448 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001449
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001450 } else {
1451 if (ar.result == null) {
1452 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001453 error = TelephonyManager.ModemActivityInfoException
1454 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001455 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001456 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001457 error = TelephonyManager.ModemActivityInfoException
1458 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001459 } else {
1460 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001461 error = TelephonyManager.ModemActivityInfoException
1462 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001463 }
1464 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001466 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001467 bundle.putParcelable(
1468 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001469 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001470 } else {
1471 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1472 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001473 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001474 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001475 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001476 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001477
Meng Wang1a7c35a2016-05-05 20:56:15 -07001478 case CMD_SET_ALLOWED_CARRIERS:
1479 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001480 CarrierRestrictionRules argument =
1481 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001482 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001483 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001484 break;
1485
1486 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1487 ar = (AsyncResult) msg.obj;
1488 request = (MainThreadRequest) ar.userObj;
1489 if (ar.exception == null && ar.result != null) {
1490 request.result = ar.result;
1491 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001492 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1493 if (ar.exception instanceof CommandException) {
1494 loge("setAllowedCarriers: CommandException: " + ar.exception);
1495 CommandException.Error error =
1496 ((CommandException) (ar.exception)).getCommandError();
1497 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1498 request.result =
1499 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1500 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001501 } else {
1502 loge("setAllowedCarriers: Unknown exception");
1503 }
1504 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001505 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001506 break;
1507
1508 case CMD_GET_ALLOWED_CARRIERS:
1509 request = (MainThreadRequest) msg.obj;
1510 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001511 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001512 break;
1513
1514 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1515 ar = (AsyncResult) msg.obj;
1516 request = (MainThreadRequest) ar.userObj;
1517 if (ar.exception == null && ar.result != null) {
1518 request.result = ar.result;
1519 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001520 request.result = new IllegalStateException(
1521 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001522 if (ar.result == null) {
1523 loge("getAllowedCarriers: Empty response");
1524 } else if (ar.exception instanceof CommandException) {
1525 loge("getAllowedCarriers: CommandException: " +
1526 ar.exception);
1527 } else {
1528 loge("getAllowedCarriers: Unknown exception");
1529 }
1530 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001531 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001532 break;
1533
Nathan Haroldb3014052017-01-25 15:57:32 -08001534 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1535 ar = (AsyncResult) msg.obj;
1536 request = (MainThreadRequest) ar.userObj;
1537 if (ar.exception == null && ar.result != null) {
1538 request.result = ar.result;
1539 } else {
1540 request.result = new IllegalArgumentException(
1541 "Failed to retrieve Forbidden Plmns");
1542 if (ar.result == null) {
1543 loge("getForbiddenPlmns: Empty response");
1544 } else {
1545 loge("getForbiddenPlmns: Unknown exception");
1546 }
1547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001548 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001549 break;
1550
1551 case CMD_GET_FORBIDDEN_PLMNS:
1552 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001553 uiccPort = getUiccPortFromRequest(request);
1554 if (uiccPort == null) {
1555 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001556 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001557 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001558 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001559 break;
1560 }
1561 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001562 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001563 if (uiccApp == null) {
1564 loge("getForbiddenPlmns() no app with specified type -- "
1565 + appType);
1566 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001567 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001568 break;
1569 } else {
1570 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1571 + " specified type -- " + appType);
1572 }
1573 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1574 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1575 onCompleted);
1576 break;
1577
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001578 case CMD_SWITCH_SLOTS:
1579 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001580 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001581 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001582 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001583 break;
1584
1585 case EVENT_SWITCH_SLOTS_DONE:
1586 ar = (AsyncResult) msg.obj;
1587 request = (MainThreadRequest) ar.userObj;
1588 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001589 notifyRequester(request);
1590 break;
1591 case CMD_GET_NETWORK_SELECTION_MODE:
1592 request = (MainThreadRequest) msg.obj;
1593 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1594 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1595 break;
1596
1597 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1598 ar = (AsyncResult) msg.obj;
1599 request = (MainThreadRequest) ar.userObj;
1600 if (ar.exception != null) {
1601 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1602 } else {
1603 int mode = ((int[]) ar.result)[0];
1604 if (mode == 0) {
1605 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1606 } else {
1607 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1608 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001609 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001610 notifyRequester(request);
1611 break;
1612 case CMD_GET_CDMA_ROAMING_MODE:
1613 request = (MainThreadRequest) msg.obj;
1614 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1615 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1616 break;
1617 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1618 ar = (AsyncResult) msg.obj;
1619 request = (MainThreadRequest) ar.userObj;
1620 if (ar.exception != null) {
1621 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1622 } else {
1623 request.result = ((int[]) ar.result)[0];
1624 }
1625 notifyRequester(request);
1626 break;
1627 case CMD_SET_CDMA_ROAMING_MODE:
1628 request = (MainThreadRequest) msg.obj;
1629 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1630 int mode = (int) request.argument;
1631 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1632 break;
1633 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1634 ar = (AsyncResult) msg.obj;
1635 request = (MainThreadRequest) ar.userObj;
1636 request.result = ar.exception == null;
1637 notifyRequester(request);
1638 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001639 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1640 request = (MainThreadRequest) msg.obj;
1641 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1642 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1643 break;
1644 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1645 ar = (AsyncResult) msg.obj;
1646 request = (MainThreadRequest) ar.userObj;
1647 if (ar.exception != null) {
1648 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1649 } else {
1650 request.result = ((int[]) ar.result)[0];
1651 }
1652 notifyRequester(request);
1653 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001654 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1655 request = (MainThreadRequest) msg.obj;
1656 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1657 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001658 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1659 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001660 break;
1661 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1662 ar = (AsyncResult) msg.obj;
1663 request = (MainThreadRequest) ar.userObj;
1664 request.result = ar.exception == null;
1665 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001666 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001667 case CMD_GET_ALL_CELL_INFO:
1668 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001669 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001670 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001671 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001672 case EVENT_GET_ALL_CELL_INFO_DONE:
1673 ar = (AsyncResult) msg.obj;
1674 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001675 // If a timeout occurs, the response will be null
1676 request.result = (ar.exception == null && ar.result != null)
1677 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001678 synchronized (request) {
1679 request.notifyAll();
1680 }
1681 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001682 case CMD_REQUEST_CELL_INFO_UPDATE:
1683 request = (MainThreadRequest) msg.obj;
1684 request.phone.requestCellInfoUpdate(request.workSource,
1685 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1686 break;
1687 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1688 ar = (AsyncResult) msg.obj;
1689 request = (MainThreadRequest) ar.userObj;
1690 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1691 try {
1692 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001693 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001694 cb.onError(
1695 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1696 ar.exception.getClass().getName(),
1697 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001698 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001699 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001700 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001701 } else {
1702 // use the result as returned
1703 cb.onCellInfo((List<CellInfo>) ar.result);
1704 }
1705 } catch (RemoteException re) {
1706 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1707 }
1708 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001709 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001710 request = (MainThreadRequest) msg.obj;
1711 WorkSource ws = (WorkSource) request.argument;
1712 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001713 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001714 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001715 }
1716 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001717 ar = (AsyncResult) msg.obj;
1718 request = (MainThreadRequest) ar.userObj;
1719 if (ar.exception == null) {
1720 request.result = ar.result;
1721 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001722 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001723 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001724 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001725 }
1726
1727 synchronized (request) {
1728 request.notifyAll();
1729 }
1730 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001731 }
chen xu6dac5ab2018-10-26 17:39:23 -07001732 case CMD_MODEM_REBOOT:
1733 request = (MainThreadRequest) msg.obj;
1734 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001735 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001736 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001737 case EVENT_CMD_MODEM_REBOOT_DONE:
1738 handleNullReturnEvent(msg, "rebootModem");
1739 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001740 case CMD_REQUEST_ENABLE_MODEM:
1741 request = (MainThreadRequest) msg.obj;
1742 boolean enable = (boolean) request.argument;
1743 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001744 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001745 PhoneConfigurationManager.getInstance()
1746 .enablePhone(request.phone, enable, onCompleted);
1747 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001748 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001749 ar = (AsyncResult) msg.obj;
1750 request = (MainThreadRequest) ar.userObj;
1751 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001752 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001753 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001754 if ((boolean) request.result) {
1755 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1756 updateModemStateMetrics();
1757 } else {
1758 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1759 + ar.exception);
1760 }
1761 notifyRequester(request);
1762 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001763 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001764 case CMD_GET_MODEM_STATUS:
1765 request = (MainThreadRequest) msg.obj;
1766 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1767 PhoneConfigurationManager.getInstance()
1768 .getPhoneStatusFromModem(request.phone, onCompleted);
1769 break;
1770 case EVENT_GET_MODEM_STATUS_DONE:
1771 ar = (AsyncResult) msg.obj;
1772 request = (MainThreadRequest) ar.userObj;
1773 int id = request.phone.getPhoneId();
1774 if (ar.exception == null && ar.result != null) {
1775 request.result = ar.result;
1776 //update the cache as modem status has changed
1777 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1778 (boolean) request.result);
1779 } else {
1780 // Return true if modem status cannot be retrieved. For most cases,
1781 // modem status is on. And for older version modems, GET_MODEM_STATUS
1782 // and disable modem are not supported. Modem is always on.
1783 // TODO: this should be fixed in R to support a third
1784 // status UNKNOWN b/131631629
1785 request.result = true;
1786 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1787 + ar.exception);
1788 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001789 notifyRequester(request);
1790 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001791 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1792 request = (MainThreadRequest) msg.obj;
1793 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1794 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1795 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1796 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1797 break;
1798 }
1799 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1800 ar = (AsyncResult) msg.obj;
1801 request = (MainThreadRequest) ar.userObj;
1802 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1803 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1804 args.second.accept(ar.exception == null);
1805 notifyRequester(request);
1806 break;
1807 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001808 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1809 request = (MainThreadRequest) msg.obj;
1810 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1811 Phone phone = getPhoneFromRequest(request);
1812 if (phone != null) {
1813 phone.getSystemSelectionChannels(onCompleted);
1814 } else {
1815 loge("getSystemSelectionChannels: No phone object");
1816 request.result = new ArrayList<RadioAccessSpecifier>();
1817 notifyRequester(request);
1818 }
1819 break;
1820 }
1821 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1822 ar = (AsyncResult) msg.obj;
1823 request = (MainThreadRequest) ar.userObj;
1824 if (ar.exception == null && ar.result != null) {
1825 request.result = ar.result;
1826 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001827 request.result = new IllegalStateException(
1828 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001829 if (ar.result == null) {
1830 loge("getSystemSelectionChannels: Empty response");
1831 } else {
1832 loge("getSystemSelectionChannels: Unknown exception");
1833 }
1834 }
1835 notifyRequester(request);
1836 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001837 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1838 ar = (AsyncResult) msg.obj;
1839 request = (MainThreadRequest) ar.userObj;
1840 if (ar.exception == null && ar.result != null) {
1841 request.result = ar.result;
1842 } else {
1843 request.result = -1;
1844 loge("Failed to set Forbidden Plmns");
1845 if (ar.result == null) {
1846 loge("setForbidenPlmns: Empty response");
1847 } else if (ar.exception != null) {
1848 loge("setForbiddenPlmns: Exception: " + ar.exception);
1849 request.result = -1;
1850 } else {
1851 loge("setForbiddenPlmns: Unknown exception");
1852 }
1853 }
1854 notifyRequester(request);
1855 break;
1856 case CMD_SET_FORBIDDEN_PLMNS:
1857 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001858 uiccPort = getUiccPortFromRequest(request);
1859 if (uiccPort == null) {
1860 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001861 request.result = -1;
1862 notifyRequester(request);
1863 break;
1864 }
1865 Pair<Integer, List<String>> setFplmnsArgs =
1866 (Pair<Integer, List<String>>) request.argument;
1867 appType = setFplmnsArgs.first;
1868 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001869 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001870 if (uiccApp == null) {
1871 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1872 request.result = -1;
1873 loge("Failed to get UICC App");
1874 notifyRequester(request);
1875 } else {
1876 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1877 ((SIMRecords) uiccApp.getIccRecords())
1878 .setForbiddenPlmns(onCompleted, fplmns);
1879 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001880 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001881 case CMD_ERASE_MODEM_CONFIG:
1882 request = (MainThreadRequest) msg.obj;
1883 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1884 defaultPhone.eraseModemConfig(onCompleted);
1885 break;
1886 case EVENT_ERASE_MODEM_CONFIG_DONE:
1887 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001888 break;
zoey chene02881a2019-12-30 16:11:23 +08001889
Kai Shif70f46f2021-03-03 13:59:46 -08001890 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1891 request = (MainThreadRequest) msg.obj;
1892 request.result = defaultPhone.eraseDataInSharedPreferences();
1893 notifyRequester(request);
1894 break;
1895
zoey chene02881a2019-12-30 16:11:23 +08001896 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1897 request = (MainThreadRequest) msg.obj;
1898 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1899 Pair<String, String> changed = (Pair<String, String>) request.argument;
1900 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1901 changed.first, changed.second, onCompleted);
1902 break;
1903 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1904 ar = (AsyncResult) msg.obj;
1905 request = (MainThreadRequest) ar.userObj;
1906 if (ar.exception == null) {
1907 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001908 // If the operation is successful, update the PIN storage
1909 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1910 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001911 UiccController.getInstance().getPinStorage()
1912 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001913 } else {
1914 request.result = msg.arg1;
1915 }
1916 notifyRequester(request);
1917 break;
1918
Michele Berionne5e411512020-11-13 02:36:59 +00001919 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001920 request = (MainThreadRequest) msg.obj;
1921 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1922 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1923 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1924 enabled.first, enabled.second, onCompleted);
1925 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001926 }
zoey chene02881a2019-12-30 16:11:23 +08001927 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1928 ar = (AsyncResult) msg.obj;
1929 request = (MainThreadRequest) ar.userObj;
1930 if (ar.exception == null) {
1931 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001932 // If the operation is successful, update the PIN storage
1933 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1934 int phoneId = getPhoneFromRequest(request).getPhoneId();
1935 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001936 UiccController.getInstance().getPinStorage()
1937 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001938 } else {
1939 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1940 }
zoey chene02881a2019-12-30 16:11:23 +08001941 } else {
1942 request.result = msg.arg1;
1943 }
Michele Berionne5e411512020-11-13 02:36:59 +00001944
1945
zoey chene02881a2019-12-30 16:11:23 +08001946 notifyRequester(request);
1947 break;
1948
Peter Wangdafb9ac2020-01-15 14:13:38 -08001949 case MSG_NOTIFY_USER_ACTIVITY:
1950 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001951 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001952 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1953 getDefaultPhone().getContext().sendBroadcastAsUser(
1954 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1955 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001956
1957 case CMD_SET_DATA_THROTTLING: {
1958 request = (MainThreadRequest) msg.obj;
1959 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1960 DataThrottlingRequest dataThrottlingRequest =
1961 (DataThrottlingRequest) request.argument;
1962 Phone phone = getPhoneFromRequest(request);
1963 if (phone != null) {
1964 phone.setDataThrottling(onCompleted,
1965 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1966 dataThrottlingRequest.getCompletionDurationMillis());
1967 } else {
1968 loge("setDataThrottling: No phone object");
1969 request.result =
1970 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1971 notifyRequester(request);
1972 }
1973
1974 break;
1975 }
1976 case EVENT_SET_DATA_THROTTLING_DONE:
1977 ar = (AsyncResult) msg.obj;
1978 request = (MainThreadRequest) ar.userObj;
1979
1980 if (ar.exception == null) {
1981 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1982 } else if (ar.exception instanceof CommandException) {
1983 loge("setDataThrottling: CommandException: " + ar.exception);
1984 CommandException.Error error =
1985 ((CommandException) (ar.exception)).getCommandError();
1986
1987 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1988 request.result = TelephonyManager
1989 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1990 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1991 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001992 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1993 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001994 } else {
1995 request.result =
1996 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1997 }
1998 } else {
1999 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2000 }
2001 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2002 notifyRequester(request);
2003 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002004
2005 case CMD_SET_SIM_POWER: {
2006 request = (MainThreadRequest) msg.obj;
2007 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2008 request = (MainThreadRequest) msg.obj;
2009 int stateToSet =
2010 ((Pair<Integer, IIntegerConsumer>)
2011 request.argument).first;
2012 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2013 break;
2014 }
2015 case EVENT_SET_SIM_POWER_DONE: {
2016 ar = (AsyncResult) msg.obj;
2017 request = (MainThreadRequest) ar.userObj;
2018 IIntegerConsumer callback =
2019 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2020 if (ar.exception != null) {
2021 loge("setSimPower exception: " + ar.exception);
2022 int errorCode = TelephonyManager.CallForwardingInfoCallback
2023 .RESULT_ERROR_UNKNOWN;
2024 if (ar.exception instanceof CommandException) {
2025 CommandException.Error error =
2026 ((CommandException) (ar.exception)).getCommandError();
2027 if (error == CommandException.Error.SIM_ERR) {
2028 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2029 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2030 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2031 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2032 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2033 } else {
2034 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2035 }
2036 }
2037 try {
2038 callback.accept(errorCode);
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 } else {
2044 try {
2045 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2046 } catch (RemoteException e) {
2047 // Ignore if the remote process is no longer available to call back.
2048 Log.w(LOG_TAG, "setSimPower: callback not available.");
2049 }
2050 }
2051 break;
2052 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002053 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2054 request = (MainThreadRequest) msg.obj;
2055
2056 final Phone phone = getPhoneFromRequest(request);
2057 if (phone == null || phone.getServiceStateTracker() == null) {
2058 request.result = new IllegalStateException("Phone or SST is null");
2059 notifyRequester(request);
2060 break;
2061 }
2062
2063 Pair<Integer, SignalStrengthUpdateRequest> pair =
2064 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2065 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2066 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002067 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002068 request.subId, pair.first /*callingUid*/,
2069 pair.second /*request*/, onCompleted);
2070 break;
2071 }
2072 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2073 ar = (AsyncResult) msg.obj;
2074 request = (MainThreadRequest) ar.userObj;
2075 // request.result will be the exception of ar if present, true otherwise.
2076 // Be cautious not to leave result null which will wait() forever
2077 request.result = ar.exception != null ? ar.exception : true;
2078 notifyRequester(request);
2079 break;
2080 }
2081 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2082 request = (MainThreadRequest) msg.obj;
2083
2084 Phone phone = getPhoneFromRequest(request);
2085 if (phone == null || phone.getServiceStateTracker() == null) {
2086 request.result = new IllegalStateException("Phone or SST is null");
2087 notifyRequester(request);
2088 break;
2089 }
2090
2091 Pair<Integer, SignalStrengthUpdateRequest> pair =
2092 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2093 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2094 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002095 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002096 request.subId, pair.first /*callingUid*/,
2097 pair.second /*request*/, onCompleted);
2098 break;
2099 }
2100 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2101 ar = (AsyncResult) msg.obj;
2102 request = (MainThreadRequest) ar.userObj;
2103 request.result = ar.exception != null ? ar.exception : true;
2104 notifyRequester(request);
2105 break;
2106 }
Jordan Liu109698e2020-11-24 14:50:34 -08002107
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002108 case CMD_GET_SLICING_CONFIG: {
2109 request = (MainThreadRequest) msg.obj;
2110 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2111 request.phone.getSlicingConfig(onCompleted);
2112 break;
2113 }
2114 case EVENT_GET_SLICING_CONFIG_DONE: {
2115 ar = (AsyncResult) msg.obj;
2116 request = (MainThreadRequest) ar.userObj;
2117 ResultReceiver result = (ResultReceiver) request.argument;
2118
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002119 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002120 Bundle bundle = new Bundle();
2121 int resultCode = 0;
2122 if (ar.exception != null) {
2123 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2124 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002125 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002126 } else if (ar.result == null) {
2127 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002128 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002129 } else {
2130 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002131 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2132 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002133 }
2134
2135 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002136 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002137 }
2138 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2139 result.send(resultCode, bundle);
2140 notifyRequester(request);
2141 break;
2142 }
2143
Michele Berionne5e411512020-11-13 02:36:59 +00002144 case CMD_PREPARE_UNATTENDED_REBOOT:
2145 request = (MainThreadRequest) msg.obj;
2146 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002147 UiccController.getInstance().getPinStorage()
2148 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002149 notifyRequester(request);
2150 break;
2151
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 default:
2153 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2154 break;
2155 }
2156 }
Jake Hambye994d462014-02-03 13:10:13 -08002157
Pengquan Menga1bb6272018-09-06 09:59:22 -07002158 private void notifyRequester(MainThreadRequest request) {
2159 synchronized (request) {
2160 request.notifyAll();
2161 }
2162 }
2163
Jake Hambye994d462014-02-03 13:10:13 -08002164 private void handleNullReturnEvent(Message msg, String command) {
2165 AsyncResult ar = (AsyncResult) msg.obj;
2166 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2167 if (ar.exception == null) {
2168 request.result = true;
2169 } else {
2170 request.result = false;
2171 if (ar.exception instanceof CommandException) {
2172 loge(command + ": CommandException: " + ar.exception);
2173 } else {
2174 loge(command + ": Unknown exception");
2175 }
2176 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002177 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002178 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 }
2180
2181 /**
2182 * Posts the specified command to be executed on the main thread,
2183 * waits for the request to complete, and returns the result.
2184 * @see #sendRequestAsync
2185 */
2186 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002187 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2188 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002189 }
2190
2191 /**
2192 * Posts the specified command to be executed on the main thread,
2193 * waits for the request to complete, and returns the result.
2194 * @see #sendRequestAsync
2195 */
2196 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2197 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002198 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002199 }
2200
2201 /**
2202 * Posts the specified command to be executed on the main thread,
2203 * waits for the request to complete, and returns the result.
2204 * @see #sendRequestAsync
2205 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002206 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002207 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2208 }
2209
2210 /**
2211 * Posts the specified command to be executed on the main thread,
2212 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2213 * if not timeout or null otherwise.
2214 * @see #sendRequestAsync
2215 */
2216 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2217 long timeoutInMs) {
2218 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002219 }
2220
2221 /**
2222 * Posts the specified command to be executed on the main thread,
2223 * waits for the request to complete, and returns the result.
2224 * @see #sendRequestAsync
2225 */
Nathan Harold92bed182018-10-12 18:16:49 -07002226 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002227 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002228 }
2229
2230 /**
2231 * Posts the specified command to be executed on the main thread,
2232 * waits for the request to complete, and returns the result.
2233 * @see #sendRequestAsync
2234 */
2235 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002236 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2237 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002238 }
2239
2240 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002241 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2242 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2243 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002244 * @see #sendRequestAsync
2245 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002246 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2247 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2249 throw new RuntimeException("This method will deadlock if called from the main thread.");
2250 }
2251
Nathan Harold92bed182018-10-12 18:16:49 -07002252 MainThreadRequest request = null;
2253 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2254 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2255 } else if (phone != null) {
2256 request = new MainThreadRequest(argument, phone, workSource);
2257 } else {
2258 request = new MainThreadRequest(argument, subId, workSource);
2259 }
2260
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 Message msg = mMainThreadHandler.obtainMessage(command, request);
2262 msg.sendToTarget();
2263
Rambo Wang0f050d82021-02-12 11:43:36 -08002264
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002266 if (timeoutInMs >= 0) {
2267 // Wait for at least timeoutInMs before returning null request result
2268 long now = SystemClock.elapsedRealtime();
2269 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002270 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002271 try {
2272 request.wait(deadline - now);
2273 } catch (InterruptedException e) {
2274 // Do nothing, go back and check if request is completed or timeout
2275 } finally {
2276 now = SystemClock.elapsedRealtime();
2277 }
2278 }
2279 } else {
2280 // Wait for the request to complete
2281 while (request.result == null) {
2282 try {
2283 request.wait();
2284 } catch (InterruptedException e) {
2285 // Do nothing, go back and wait until the request is complete
2286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 }
2288 }
2289 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002290 if (request.result == null) {
2291 Log.wtf(LOG_TAG,
2292 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 return request.result;
2295 }
2296
2297 /**
2298 * Asynchronous ("fire and forget") version of sendRequest():
2299 * Posts the specified command to be executed on the main thread, and
2300 * returns immediately.
2301 * @see #sendRequest
2302 */
2303 private void sendRequestAsync(int command) {
2304 mMainThreadHandler.sendEmptyMessage(command);
2305 }
2306
2307 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002308 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002309 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002310 */
2311 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002312 sendRequestAsync(command, argument, null, null);
2313 }
2314
2315 /**
2316 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2317 * @see {@link #sendRequest(int,Object)}
2318 */
2319 private void sendRequestAsync(
2320 int command, Object argument, Phone phone, WorkSource workSource) {
2321 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002322 Message msg = mMainThreadHandler.obtainMessage(command, request);
2323 msg.sendToTarget();
2324 }
2325
2326 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 * Initialize the singleton PhoneInterfaceManager instance.
2328 * This is only done once, at startup, from PhoneApp.onCreate().
2329 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002330 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 synchronized (PhoneInterfaceManager.class) {
2332 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002333 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 } else {
2335 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2336 }
2337 return sInstance;
2338 }
2339 }
2340
2341 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002342 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002345 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002346 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002348 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 mMainThreadHandler = new MainThreadHandler();
Jack Yu5e360c42022-12-16 11:53:37 -08002350 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
2351 mSubscriptionController = SubscriptionController.getInstance();
2352 } else {
2353 mSubscriptionController = null;
2354 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002355 mTelephonySharedPreferences =
2356 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002357 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002358 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002359 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002360 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002361 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukiermand6cae882022-12-29 12:02:31 -05002362 mTelephony2gUpdater = new Telephony2gUpdater(mApp);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002363 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 publish();
2365 }
2366
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002367 private Phone getDefaultPhone() {
2368 Phone thePhone = getPhone(getDefaultSubscription());
2369 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2370 }
2371
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 private void publish() {
2373 if (DBG) log("publish: " + this);
2374
Peter Wangc035ce42020-01-08 21:00:22 -08002375 TelephonyFrameworkInitializer
2376 .getTelephonyServiceManager()
2377 .getTelephonyServiceRegisterer()
2378 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 }
2380
Stuart Scott584921c2015-01-15 17:10:34 -08002381 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002382 if (request.phone != null) {
2383 return request.phone;
2384 } else {
2385 return getPhoneFromSubId(request.subId);
2386 }
2387 }
2388
2389 private Phone getPhoneFromSubId(int subId) {
2390 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2391 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002392 }
2393
Rambo Wange53e07d2022-05-10 13:01:13 -07002394 @Nullable
2395 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002396 Phone phone = getPhoneFromRequest(request);
2397 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002398 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002399 }
2400
Wink Saville36469e72014-06-11 15:17:00 -07002401 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002402 private Phone getPhone(int subId) {
Jack Yudf049d72022-12-02 22:48:35 -08002403 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405
Kai Shif70f46f2021-03-03 13:59:46 -08002406 private void sendEraseModemConfig(@NonNull Phone phone) {
2407 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2408 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2409 }
2410
2411 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2412 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2413 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002414 }
2415
Peter Wang44b186e2020-01-13 23:33:09 -08002416 private boolean isImsAvailableOnDevice() {
2417 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2418 if (pm == null) {
2419 // For some reason package manger is not available.. This will fail internally anyway,
2420 // so do not throw error and allow.
2421 return true;
2422 }
2423 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2424 }
2425
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002427 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002428 }
2429
Wink Savilleb564aae2014-10-23 10:18:09 -07002430 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 if (DBG) log("dial: " + number);
2432 // No permission check needed here: This is just a wrapper around the
2433 // ACTION_DIAL intent, which is available to any app since it puts up
2434 // the UI before it does anything.
2435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002436 final long identity = Binder.clearCallingIdentity();
2437 try {
2438 String url = createTelUrl(number);
2439 if (url == null) {
2440 return;
2441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002443 // PENDING: should we just silently fail if phone is offhook or ringing?
2444 PhoneConstants.State state = mCM.getState(subId);
2445 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2446 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2447 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2448 mApp.startActivity(intent);
2449 }
2450 } finally {
2451 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 }
2453 }
2454
2455 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002456 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002457 }
2458
Wink Savilleb564aae2014-10-23 10:18:09 -07002459 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 if (DBG) log("call: " + number);
2461
2462 // This is just a wrapper around the ACTION_CALL intent, but we still
2463 // need to do a permission check since we're calling startActivity()
2464 // from the context of the phone app.
2465 enforceCallPermission();
2466
Jordan Liu1617b712019-07-10 15:06:26 -07002467 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 != AppOpsManager.MODE_ALLOWED) {
2469 return;
2470 }
2471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472 final long identity = Binder.clearCallingIdentity();
2473 try {
2474 String url = createTelUrl(number);
2475 if (url == null) {
2476 return;
2477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002479 boolean isValid = false;
2480 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2481 if (slist != null) {
2482 for (SubscriptionInfo subInfoRecord : slist) {
2483 if (subInfoRecord.getSubscriptionId() == subId) {
2484 isValid = true;
2485 break;
2486 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002487 }
Wink Saville08874612014-08-31 19:19:58 -07002488 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002489 if (!isValid) {
2490 return;
2491 }
Wink Saville08874612014-08-31 19:19:58 -07002492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2494 intent.putExtra(SUBSCRIPTION_KEY, subId);
2495 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2496 mApp.startActivity(intent);
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
2499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
Wink Savilleb564aae2014-10-23 10:18:09 -07002502 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002503 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002504 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2505 }
2506
Wink Savilleb564aae2014-10-23 10:18:09 -07002507 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002508 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002509 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2510 }
2511
Wink Savilleb564aae2014-10-23 10:18:09 -07002512 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002514
2515 final long identity = Binder.clearCallingIdentity();
2516 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002517 Phone phone = getPhone(subId);
2518 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519 checkSimPin.start();
2520 return checkSimPin.unlockSim(null, pin);
2521 } finally {
2522 Binder.restoreCallingIdentity(identity);
2523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002524 }
2525
Wink Savilleb564aae2014-10-23 10:18:09 -07002526 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002528
2529 final long identity = Binder.clearCallingIdentity();
2530 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002531 Phone phone = getPhone(subId);
2532 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533 checkSimPuk.start();
2534 return checkSimPuk.unlockSim(puk, pin);
2535 } finally {
2536 Binder.restoreCallingIdentity(identity);
2537 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002538 }
2539
2540 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002541 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542 * a synchronous one.
2543 */
2544 private static class UnlockSim extends Thread {
2545
2546 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002547 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002548
2549 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002550 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2551 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552
2553 // For replies from SimCard interface
2554 private Handler mHandler;
2555
2556 // For async handler to identify request type
2557 private static final int SUPPLY_PIN_COMPLETE = 100;
2558
Michele Berionne5e411512020-11-13 02:36:59 +00002559 UnlockSim(int phoneId, IccCard simCard) {
2560 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002561 mSimCard = simCard;
2562 }
2563
2564 @Override
2565 public void run() {
2566 Looper.prepare();
2567 synchronized (UnlockSim.this) {
2568 mHandler = new Handler() {
2569 @Override
2570 public void handleMessage(Message msg) {
2571 AsyncResult ar = (AsyncResult) msg.obj;
2572 switch (msg.what) {
2573 case SUPPLY_PIN_COMPLETE:
2574 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2575 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002576 mRetryCount = msg.arg1;
2577 if (ar.exception != null) {
2578 if (ar.exception instanceof CommandException &&
2579 ((CommandException)(ar.exception)).getCommandError()
2580 == CommandException.Error.PASSWORD_INCORRECT) {
2581 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002582 } //When UiccCardApp dispose,handle message and return exception
2583 else if (ar.exception instanceof CommandException &&
2584 ((CommandException) (ar.exception)).getCommandError()
2585 == CommandException.Error.ABORTED) {
2586 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002587 } else {
2588 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2589 }
2590 } else {
2591 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2592 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002593 mDone = true;
2594 UnlockSim.this.notifyAll();
2595 }
2596 break;
2597 }
2598 }
2599 };
2600 UnlockSim.this.notifyAll();
2601 }
2602 Looper.loop();
2603 }
2604
2605 /*
2606 * Use PIN or PUK to unlock SIM card
2607 *
2608 * If PUK is null, unlock SIM card with PIN
2609 *
2610 * If PUK is not null, unlock SIM card with PUK and set PIN code
2611 */
Wink Saville9de0f752013-10-22 19:04:03 -07002612 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613
2614 while (mHandler == null) {
2615 try {
2616 wait();
2617 } catch (InterruptedException e) {
2618 Thread.currentThread().interrupt();
2619 }
2620 }
2621 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2622
2623 if (puk == null) {
2624 mSimCard.supplyPin(pin, callback);
2625 } else {
2626 mSimCard.supplyPuk(puk, pin, callback);
2627 }
2628
2629 while (!mDone) {
2630 try {
2631 Log.d(LOG_TAG, "wait for done");
2632 wait();
2633 } catch (InterruptedException e) {
2634 // Restore the interrupted status
2635 Thread.currentThread().interrupt();
2636 }
2637 }
2638 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002639 int[] resultArray = new int[2];
2640 resultArray[0] = mResult;
2641 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002642
2643 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002644 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002645 }
2646
Wink Saville9de0f752013-10-22 19:04:03 -07002647 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648 }
2649 }
2650
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002651 /**
2652 * This method has been removed due to privacy and stability concerns.
2653 */
2654 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002656 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2657 return;
Wink Saville36469e72014-06-11 15:17:00 -07002658 }
2659
Nathan Harold1f889d82020-06-04 17:05:26 -07002660 @Override
2661 public void updateServiceLocationWithPackageName(String callingPackage) {
2662 mApp.getSystemService(AppOpsManager.class)
2663 .checkPackage(Binder.getCallingUid(), callingPackage);
2664
Nathan Haroldf096d982020-11-18 17:18:06 -08002665 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002666 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2667 // Callers targeting S have no business invoking this method.
2668 return;
2669 }
2670
2671 LocationAccessPolicy.LocationPermissionResult locationResult =
2672 LocationAccessPolicy.checkLocationPermission(mApp,
2673 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2674 .setCallingPackage(callingPackage)
2675 .setCallingFeatureId(null)
2676 .setCallingPid(Binder.getCallingPid())
2677 .setCallingUid(Binder.getCallingUid())
2678 .setMethod("updateServiceLocation")
2679 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2680 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2681 .build());
2682 // Apps that lack location permission have no business calling this method;
2683 // however, because no permission was declared in the public API, denials must
2684 // all be "soft".
2685 switch (locationResult) {
2686 case DENIED_HARD: /* fall through */
2687 case DENIED_SOFT:
2688 return;
2689 }
2690
2691 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692 final long identity = Binder.clearCallingIdentity();
2693 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002694 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002696 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697 }
2698 } finally {
2699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 }
2702
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002703 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002704 @Override
2705 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002706 return isRadioOnWithFeature(callingPackage, null);
2707 }
2708
2709
2710 @Override
2711 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2712 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2713 callingFeatureId);
2714 }
2715
2716 @Deprecated
2717 @Override
2718 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2719 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002720 }
2721
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002722 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002723 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2724 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002726 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002727 return false;
2728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729
2730 final long identity = Binder.clearCallingIdentity();
2731 try {
2732 return isRadioOnForSubscriber(subId);
2733 } finally {
2734 Binder.restoreCallingIdentity(identity);
2735 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002736 }
2737
2738 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 final Phone phone = getPhone(subId);
2742 if (phone != null) {
2743 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2744 } else {
2745 return false;
2746 }
2747 } finally {
2748 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002750 }
2751
2752 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002753 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 }
Wink Saville36469e72014-06-11 15:17:00 -07002755
Wink Savilleb564aae2014-10-23 10:18:09 -07002756 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758
2759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 final Phone phone = getPhone(subId);
2762 if (phone != null) {
2763 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2764 }
2765 } finally {
2766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002767 }
Wink Saville36469e72014-06-11 15:17:00 -07002768 }
2769
2770 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002771 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002772 }
2773
Wink Savilleb564aae2014-10-23 10:18:09 -07002774 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002775 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002776
2777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 final Phone phone = getPhone(subId);
2780 if (phone == null) {
2781 return false;
2782 }
2783 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2784 toggleRadioOnOffForSubscriber(subId);
2785 }
2786 return true;
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 }
Wink Saville36469e72014-06-11 15:17:00 -07002791
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002792 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002793 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002794 /*
2795 * If any of the Radios are available, it will need to be
2796 * shutdown. So return true if any Radio is available.
2797 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798 final long identity = Binder.clearCallingIdentity();
2799 try {
2800 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2801 Phone phone = PhoneFactory.getPhone(i);
2802 if (phone != null && phone.isRadioAvailable()) return true;
2803 }
2804 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2805 return false;
2806 } finally {
2807 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002808 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002809 }
2810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002812 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002813 enforceModifyPermission();
2814
2815 final long identity = Binder.clearCallingIdentity();
2816 try {
2817 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2818 logv("Shutting down Phone " + i);
2819 shutdownRadioUsingPhoneId(i);
2820 }
2821 } finally {
2822 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002823 }
2824 }
2825
2826 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002827 Phone phone = PhoneFactory.getPhone(phoneId);
2828 if (phone != null && phone.isRadioAvailable()) {
2829 phone.shutdownRadio();
2830 }
2831 }
2832
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002833 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002834 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835
2836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2839 if (defaultPhone != null) {
2840 defaultPhone.setRadioPower(turnOn);
2841 return true;
2842 } else {
2843 loge("There's no default phone.");
2844 return false;
2845 }
2846 } finally {
2847 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002848 }
Wink Saville36469e72014-06-11 15:17:00 -07002849 }
2850
Wink Savilleb564aae2014-10-23 10:18:09 -07002851 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002852 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853
2854 final long identity = Binder.clearCallingIdentity();
2855 try {
2856 final Phone phone = getPhone(subId);
2857 if (phone != null) {
2858 phone.setRadioPower(turnOn);
2859 return true;
2860 } else {
2861 return false;
2862 }
2863 } finally {
2864 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002865 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002866 }
2867
Wink Saville36469e72014-06-11 15:17:00 -07002868 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002869 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002870 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002871 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872
2873 final long identity = Binder.clearCallingIdentity();
2874 try {
Jack Yudf049d72022-12-02 22:48:35 -08002875 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 final Phone phone = getPhone(subId);
2877 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002878 phone.getDataSettingsManager().setDataEnabled(
2879 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880 return true;
2881 } else {
2882 return false;
2883 }
2884 } finally {
2885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002887 }
2888
Wink Saville36469e72014-06-11 15:17:00 -07002889 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002890 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002891 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002892 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002893
2894 final long identity = Binder.clearCallingIdentity();
2895 try {
Jack Yudf049d72022-12-02 22:48:35 -08002896 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897 final Phone phone = getPhone(subId);
2898 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002899 phone.getDataSettingsManager().setDataEnabled(
2900 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 return true;
2902 } else {
2903 return false;
2904 }
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002908 }
2909
Sanket Padawe356d7632015-06-22 14:03:32 -07002910 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002911 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002912 final long identity = Binder.clearCallingIdentity();
2913 try {
2914 final Phone phone = getPhone(subId);
2915 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07002916 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917 } else {
2918 return false;
2919 }
2920 } finally {
2921 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002923 }
2924
2925 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002926 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002927 }
2928
pkanwarae03a6b2016-11-06 20:37:09 -08002929 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930 enforceCallPermission();
2931
2932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2935 return;
2936 }
2937 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2938 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2939 } finally {
2940 Binder.restoreCallingIdentity(identity);
2941 }
pkanwar32d516d2016-10-14 19:37:38 -07002942 };
2943
Wink Savilleb564aae2014-10-23 10:18:09 -07002944 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002945 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946
2947 final long identity = Binder.clearCallingIdentity();
2948 try {
2949 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2950 return false;
2951 }
2952 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2953 } finally {
2954 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002955 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002956 }
2957
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002958 /**
2959 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2960 * tag on getCallState Binder call.
2961 */
2962 @Deprecated
2963 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002964 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002965 if (CompatChanges.isChangeEnabled(
2966 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2967 Binder.getCallingUid())) {
2968 // Do not allow this API to be called on API version 31+, it should only be
2969 // called on old apps using this Binder call directly.
2970 throw new SecurityException("This method can only be used for applications "
2971 + "targeting API version 30 or less.");
2972 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002973 final long identity = Binder.clearCallingIdentity();
2974 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002975 Phone phone = getPhone(getDefaultSubscription());
2976 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2977 PhoneConstantConversions.convertCallState(phone.getState());
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
2981 }
2982
2983 @Override
2984 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2985 if (CompatChanges.isChangeEnabled(
2986 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2987 Binder.getCallingUid())) {
2988 // Check READ_PHONE_STATE for API version 31+
2989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2990 featureId, "getCallStateForSubscription")) {
2991 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2992 + "targeting API level 31+.");
2993 }
2994 }
2995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2999 PhoneConstantConversions.convertCallState(phone.getState());
3000 } finally {
3001 Binder.restoreCallingIdentity(identity);
3002 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003003 }
3004
Sanket Padawe356d7632015-06-22 14:03:32 -07003005 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003006 public int getDataState() {
Jack Yudf049d72022-12-02 22:48:35 -08003007 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003008 }
3009
3010 @Override
3011 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003012 final long identity = Binder.clearCallingIdentity();
3013 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003014 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07003016 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017 } 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() {
Jack Yudf049d72022-12-02 22:48:35 -08003028 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003029 }
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");
Jack Yudf049d72022-12-02 22:48:35 -08003074 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
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 }
Jack Yudf049d72022-12-02 22:48:35 -08003091 final int subId = SubscriptionManager.getSubscriptionId(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) {
Jack Yudf049d72022-12-02 22:48:35 -08005016 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005017 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
Jack Yudf049d72022-12-02 22:48:35 -08005081 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005082 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() {
Jack Yudf049d72022-12-02 22:48:35 -08005146 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005147 }
5148
Shishir Agrawala9f32182016-04-12 12:00:16 -07005149 private int getSlotForDefaultSubscription() {
Jack Yudf049d72022-12-02 22:48:35 -08005150 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005151 }
5152
Wink Savilleb564aae2014-10-23 10:18:09 -07005153 private int getPreferredVoiceSubscription() {
Jack Yudf049d72022-12-02 22:48:35 -08005154 return SubscriptionManager.getDefaultVoiceSubscriptionId();
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) {
Jack Yudf049d72022-12-02 22:48:35 -08005158 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5159 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5160 mApp.getOpPackageName(), mApp.getFeatureId());
5161 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005162 return mSubscriptionController.isActiveSubId(subId);
5163 }
5164
Ihab Awadf2177b72013-11-25 13:33:23 -08005165 /**
5166 * @see android.telephony.TelephonyManager.WifiCallingChoices
5167 */
5168 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005169 final long identity = Binder.clearCallingIdentity();
5170 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005171 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5173 getWhenToMakeWifiCallsDefaultPreference());
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005177 }
5178
5179 /**
5180 * @see android.telephony.TelephonyManager.WifiCallingChoices
5181 */
5182 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005183 final long identity = Binder.clearCallingIdentity();
5184 try {
5185 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005186 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5188 } finally {
5189 Binder.restoreCallingIdentity(identity);
5190 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005191 }
5192
Sailesh Nepald1e68152013-12-12 19:08:02 -08005193 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005194 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005195 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005196 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005197
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005198 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5199 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5200 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005201 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005202 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5203 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005204 }
5205 return PhoneFactory.getPhone(phoneId);
5206 }
5207
Shishir Agrawal566b7612013-10-28 14:41:00 -07005208 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005209 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005210 @NonNull IccLogicalChannelRequest request) {
5211 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5212 /*message=*/ "iccOpenLogicalChannel");
5213
5214 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5215 // Verify that the callingPackage in the request belongs to the calling UID
5216 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5217
5218 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005219 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005220
Rambo Wanga1782702021-11-10 20:15:19 -08005221 private Phone getPhoneFromValidIccLogicalChannelRequest(
5222 @NonNull IccLogicalChannelRequest request, String message) {
5223 Phone phone;
5224 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5226 mApp, request.subId, message);
5227 phone = getPhoneFromSubId(request.subId);
5228 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5229 enforceModifyPermission();
5230 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5231 } else {
5232 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005233 }
Rambo Wanga1782702021-11-10 20:15:19 -08005234 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005235 }
5236
5237 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005238 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 final long identity = Binder.clearCallingIdentity();
5240 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005241 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005243 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5244 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005245 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5246 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 loge("The calling package is not allowed to access ISD-R.");
5248 throw new SecurityException(
5249 "The calling package is not allowed to access ISD-R.");
5250 }
Derek Tan740e1672017-06-27 14:56:27 -07005251 }
Derek Tan740e1672017-06-27 14:56:27 -07005252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005253 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005254 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5255 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005256 return response;
5257 } finally {
5258 Binder.restoreCallingIdentity(identity);
5259 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005260 }
5261
5262 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005263 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5264 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5265 /*message=*/"iccCloseLogicalChannel");
5266
5267 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5268
5269 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005270 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005271
Rambo Wanga1782702021-11-10 20:15:19 -08005272 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5273 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005274 // before this feature is enabled, this API should only return false if
5275 // the operation fails instead of throwing runtime exception for
5276 // backward-compatibility.
5277 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5278 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 final long identity = Binder.clearCallingIdentity();
5280 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005281 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005282 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 }
Chen Xue9d737e2022-01-01 23:41:31 -08005284 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005285 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005286 Boolean success = false;
5287 if (result instanceof RuntimeException) {
5288 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005289 if (shouldThrowExceptionOnFailure) {
5290 throw (RuntimeException) result;
5291 } else {
5292 return false;
5293 }
Chen Xue9d737e2022-01-01 23:41:31 -08005294 } else if (result instanceof Boolean) {
5295 success = (Boolean) result;
5296 } else {
5297 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5298 }
Rambo Wanga1782702021-11-10 20:15:19 -08005299 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 return success;
5301 } finally {
5302 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005303 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005304 }
5305
5306 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005307 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005308 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5310 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005311 if (DBG) {
5312 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5313 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5314 + p3 + " data=" + data);
5315 }
5316 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5317 command, p1, p2, p3, data);
5318 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005319
Jordan Liu4c733742019-02-28 12:03:40 -08005320 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005321 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5322 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005323 enforceModifyPermission();
5324 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005325 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5326 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5327 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005328 }
5329 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005330 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5331 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005332 }
5333
5334 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5335 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 final long identity = Binder.clearCallingIdentity();
5337 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005338 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005339 return "";
5340 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005342 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005343 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5344 null /* workSource */);
5345 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005347 // Append the returned status code to the end of the response payload.
5348 String s = Integer.toHexString(
5349 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5350 if (response.payload != null) {
5351 s = IccUtils.bytesToHexString(response.payload) + s;
5352 }
5353 return s;
5354 } finally {
5355 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005356 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005357 }
Jake Hambye994d462014-02-03 13:10:13 -08005358
Evan Charltonc66da362014-05-16 14:06:40 -07005359 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005360 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5361 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5363 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005365 if (DBG) {
5366 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5367 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5368 }
5369 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5370 cla, command, p1, p2, p3, data);
5371 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005372
Jordan Liu4c733742019-02-28 12:03:40 -08005373 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005374 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5375 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005376 enforceModifyPermission();
5377 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5378 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005379 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5380 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5381 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005382 }
5383
5384 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005385 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5386 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005387 }
5388
5389 // open APDU basic channel assuming the caller has sufficient permissions
5390 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5391 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005392 final long identity = Binder.clearCallingIdentity();
5393 try {
5394 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5395 && TextUtils.equals(ISDR_AID, data)) {
5396 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005397 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5398 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 if (bestComponent == null
5400 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5401 loge("The calling package is not allowed to select ISD-R.");
5402 throw new SecurityException(
5403 "The calling package is not allowed to select ISD-R.");
5404 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005405 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005408 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5409 null /* workSource */);
5410 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005411
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005412 // Append the returned status code to the end of the response payload.
5413 String s = Integer.toHexString(
5414 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5415 if (response.payload != null) {
5416 s = IccUtils.bytesToHexString(response.payload) + s;
5417 }
5418 return s;
5419 } finally {
5420 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005421 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005422 }
5423
5424 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005425 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005426 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5428 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 final long identity = Binder.clearCallingIdentity();
5431 try {
5432 if (DBG) {
5433 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5434 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5435 }
5436
5437 IccIoResult response =
5438 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5439 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5440 subId);
5441
5442 if (DBG) {
5443 log("Exchange SIM_IO [R]" + response);
5444 }
5445
5446 byte[] result = null;
5447 int length = 2;
5448 if (response.payload != null) {
5449 length = 2 + response.payload.length;
5450 result = new byte[length];
5451 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5452 } else {
5453 result = new byte[length];
5454 }
5455
5456 result[length - 1] = (byte) response.sw2;
5457 result[length - 2] = (byte) response.sw1;
5458 return result;
5459 } finally {
5460 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005461 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005462 }
5463
Nathan Haroldb3014052017-01-25 15:57:32 -08005464 /**
5465 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5466 * on a particular subscription
5467 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005468 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5469 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005471 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005472 return null;
5473 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474
5475 final long identity = Binder.clearCallingIdentity();
5476 try {
5477 if (appType != TelephonyManager.APPTYPE_USIM
5478 && appType != TelephonyManager.APPTYPE_SIM) {
5479 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5480 return null;
5481 }
5482 Object response = sendRequest(
5483 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5484 if (response instanceof String[]) {
5485 return (String[]) response;
5486 }
yincheng zhao2737e882019-09-06 17:06:54 -07005487 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005488 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005489 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 } finally {
5491 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005492 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005493 }
5494
yincheng zhao2737e882019-09-06 17:06:54 -07005495 /**
5496 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5497 * subscription.
5498 *
5499 * @param subId the id of the subscription.
5500 * @param appType the uicc app type, must be USIM or SIM.
5501 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5502 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005503 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005504 * @return number of fplmns that is successfully written to the SIM.
5505 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005506 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5507 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5509 mApp, subId, "setForbiddenPlmns");
5510
yincheng zhao2737e882019-09-06 17:06:54 -07005511 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5512 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5513 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5514 }
5515 if (fplmns == null) {
5516 throw new IllegalArgumentException("Fplmn List provided is null");
5517 }
5518 for (String fplmn : fplmns) {
5519 if (!CellIdentity.isValidPlmn(fplmn)) {
5520 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5521 }
5522 }
5523 final long identity = Binder.clearCallingIdentity();
5524 try {
5525 Object response = sendRequest(
5526 CMD_SET_FORBIDDEN_PLMNS,
5527 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5528 subId);
5529 return (int) response;
5530 } finally {
5531 Binder.restoreCallingIdentity(identity);
5532 }
5533 }
5534
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005535 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005536 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5538 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005540 final long identity = Binder.clearCallingIdentity();
5541 try {
5542 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5543 if (response.payload == null) {
5544 return "";
5545 }
Evan Charltonc66da362014-05-16 14:06:40 -07005546
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547 // Append the returned status code to the end of the response payload.
5548 String s = Integer.toHexString(
5549 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5550 s = IccUtils.bytesToHexString(response.payload) + s;
5551 return s;
5552 } finally {
5553 Binder.restoreCallingIdentity(identity);
5554 }
Evan Charltonc66da362014-05-16 14:06:40 -07005555 }
5556
Jake Hambye994d462014-02-03 13:10:13 -08005557 /**
5558 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5559 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5560 *
5561 * @param itemID the ID of the item to read
5562 * @return the NV item as a String, or null on error.
5563 */
5564 @Override
5565 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005566 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5568 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005569
5570 final long identity = Binder.clearCallingIdentity();
5571 try {
5572 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005573 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5575 return value;
5576 } finally {
5577 Binder.restoreCallingIdentity(identity);
5578 }
Jake Hambye994d462014-02-03 13:10:13 -08005579 }
5580
5581 /**
5582 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5583 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5584 *
5585 * @param itemID the ID of the item to read
5586 * @param itemValue the value to write, as a String
5587 * @return true on success; false on any failure
5588 */
5589 @Override
5590 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005591 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5593 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594
5595 final long identity = Binder.clearCallingIdentity();
5596 try {
5597 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5598 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005599 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005600 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5601 return success;
5602 } finally {
5603 Binder.restoreCallingIdentity(identity);
5604 }
Jake Hambye994d462014-02-03 13:10:13 -08005605 }
5606
5607 /**
5608 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5609 * Used for device configuration by some CDMA operators.
5610 *
5611 * @param preferredRoamingList byte array containing the new PRL
5612 * @return true on success; false on any failure
5613 */
5614 @Override
5615 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5617 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618
5619 final long identity = Binder.clearCallingIdentity();
5620 try {
5621 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5622 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5623 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5624 return success;
5625 } finally {
5626 Binder.restoreCallingIdentity(identity);
5627 }
Jake Hambye994d462014-02-03 13:10:13 -08005628 }
5629
5630 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005631 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005632 * Used for device configuration by some CDMA operators.
5633 *
chen xu6dac5ab2018-10-26 17:39:23 -07005634 * @param slotIndex - device slot.
5635 *
Jake Hambye994d462014-02-03 13:10:13 -08005636 * @return true on success; false on any failure
5637 */
5638 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005639 public boolean resetModemConfig(int slotIndex) {
5640 Phone phone = PhoneFactory.getPhone(slotIndex);
5641 if (phone != null) {
5642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5643 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644
chen xu6dac5ab2018-10-26 17:39:23 -07005645 final long identity = Binder.clearCallingIdentity();
5646 try {
5647 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5648 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5649 return success;
5650 } finally {
5651 Binder.restoreCallingIdentity(identity);
5652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653 }
chen xu6dac5ab2018-10-26 17:39:23 -07005654 return false;
5655 }
5656
5657 /**
5658 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5659 *
5660 * @param slotIndex - device slot.
5661 *
5662 * @return true on success; false on any failure
5663 */
5664 @Override
5665 public boolean rebootModem(int slotIndex) {
5666 Phone phone = PhoneFactory.getPhone(slotIndex);
5667 if (phone != null) {
5668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5669 mApp, phone.getSubId(), "rebootModem");
5670
5671 final long identity = Binder.clearCallingIdentity();
5672 try {
5673 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5674 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5675 return success;
5676 } finally {
5677 Binder.restoreCallingIdentity(identity);
5678 }
5679 }
5680 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005681 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005682
Brad Ebinger51f743a2017-01-23 13:50:20 -08005683 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005684 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5685 * {@link #disableIms(int)}.
5686 * @param slotIndex device slot.
5687 */
5688 public void resetIms(int slotIndex) {
5689 enforceModifyPermission();
5690
5691 final long identity = Binder.clearCallingIdentity();
5692 try {
5693 if (mImsResolver == null) {
5694 // may happen if the does not support IMS.
5695 return;
5696 }
5697 mImsResolver.disableIms(slotIndex);
5698 mImsResolver.enableIms(slotIndex);
5699 } finally {
5700 Binder.restoreCallingIdentity(identity);
5701 }
5702 }
5703
5704 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005705 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5706 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005707 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005708 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005709 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710
5711 final long identity = Binder.clearCallingIdentity();
5712 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005713 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005714 // may happen if the device does not support IMS.
5715 return;
5716 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005717 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718 } finally {
5719 Binder.restoreCallingIdentity(identity);
5720 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005721 }
5722
5723 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005724 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5725 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005726 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005727 public void disableIms(int slotId) {
5728 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729
5730 final long identity = Binder.clearCallingIdentity();
5731 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005732 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005733 // may happen if the device does not support IMS.
5734 return;
5735 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005736 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005740 }
5741
5742 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005743 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5744 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005745 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005746 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005747 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005748 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005749
5750 final long identity = Binder.clearCallingIdentity();
5751 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005752 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005753 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5754 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005755 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005756 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005757 } finally {
5758 Binder.restoreCallingIdentity(identity);
5759 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005760 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005761 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005762 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5763 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005764 @Override
5765 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005766 enforceModifyPermission();
5767
5768 final long identity = Binder.clearCallingIdentity();
5769 try {
5770 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005771 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005772 } finally {
5773 Binder.restoreCallingIdentity(identity);
5774 }
5775 }
5776
5777 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005778 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005779 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005780 */
5781 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5782 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783
5784 final long identity = Binder.clearCallingIdentity();
5785 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005786 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005787 // may happen if the device does not support IMS.
5788 return null;
5789 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005790 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 } finally {
5792 Binder.restoreCallingIdentity(identity);
5793 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005794 }
5795
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005796 /**
5797 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005798 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005799 */
5800 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5801 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005802
5803 final long identity = Binder.clearCallingIdentity();
5804 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005805 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005806 // may happen if the device does not support IMS.
5807 return null;
5808 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005809 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005810 } finally {
5811 Binder.restoreCallingIdentity(identity);
5812 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005813 }
5814
Brad Ebinger884c07b2018-02-15 16:17:40 -08005815 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005816 * Sets the ImsService Package Name that Telephony will bind to.
5817 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005818 * @param slotIndex the slot ID that the ImsService should bind for.
5819 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005820 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005821 * @param featureTypes An integer array of feature types associated with a packageName.
5822 * @param packageName The name of the package that the current configuration will be replaced
5823 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005824 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005825 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005826 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5827 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005828 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yude40a3f2022-11-19 22:29:12 -08005830 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005831
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832 final long identity = Binder.clearCallingIdentity();
5833 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005834 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005835 // may happen if the device does not support IMS.
5836 return false;
5837 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005838 Map<Integer, String> featureConfig = new HashMap<>();
5839 for (int featureType : featureTypes) {
5840 featureConfig.put(featureType, packageName);
5841 }
5842 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5843 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005844 } finally {
5845 Binder.restoreCallingIdentity(identity);
5846 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005847 }
5848
5849 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005850 * Clears any carrier ImsService overrides for the slot index specified that were previously
5851 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5852 *
5853 * This should only be used for testing.
5854 *
5855 * @param slotIndex the slot ID that the ImsService should bind for.
5856 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5857 */
5858 @Override
5859 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08005860 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5861 "clearCarrierImsServiceOverride");
5862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yude40a3f2022-11-19 22:29:12 -08005863 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08005864
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 Ebinger24c29992019-12-05 13:03:21 -08005888 TelephonyPermissions
Jack Yude40a3f2022-11-19 22:29:12 -08005889 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
5890 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892 final long identity = Binder.clearCallingIdentity();
5893 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005894 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005895 // may happen if the device does not support IMS.
5896 return "";
5897 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005898 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005899 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5900 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901 } finally {
5902 Binder.restoreCallingIdentity(identity);
5903 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005904 }
5905
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005906 /**
5907 * Get the MmTelFeature state associated with the requested subscription id.
5908 * @param subId The subscription that the MmTelFeature is associated with.
5909 * @param callback A callback with an integer containing the
5910 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5911 */
5912 @Override
5913 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5914 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005915 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5916 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5917 "IMS not available on device.");
5918 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005919 final long token = Binder.clearCallingIdentity();
5920 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005921 int slotId = getSlotIndex(subId);
5922 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5923 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5924 + subId + "'");
5925 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5926 }
5927 verifyImsMmTelConfiguredOrThrow(slotId);
5928 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5929 try {
5930 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5931 } catch (RemoteException e) {
5932 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5933 + "Ignore");
5934 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005935 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005936 } catch (ImsException e) {
5937 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005938 } finally {
5939 Binder.restoreCallingIdentity(token);
5940 }
5941 }
5942
Daniel Brightbb5840b2021-01-12 15:48:18 -08005943 /**
5944 * Sets the ims registration state on all valid {@link Phone}s.
5945 */
5946 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005947 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948
5949 final long identity = Binder.clearCallingIdentity();
5950 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005951 // NOTE: Before S, this method only set the default phone.
5952 for (final Phone phone : PhoneFactory.getPhones()) {
5953 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5954 phone.setImsRegistrationState(registered);
5955 }
5956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957 } finally {
5958 Binder.restoreCallingIdentity(identity);
5959 }
Wink Saville36469e72014-06-11 15:17:00 -07005960 }
5961
5962 /**
Stuart Scott54788802015-03-30 13:18:01 -07005963 * Set the network selection mode to automatic.
5964 *
5965 */
5966 @Override
5967 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5969 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970
5971 final long identity = Binder.clearCallingIdentity();
5972 try {
shilufc958392020-01-20 11:36:01 -08005973 if (!isActiveSubscription(subId)) {
5974 return;
5975 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005977 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5978 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 } finally {
5980 Binder.restoreCallingIdentity(identity);
5981 }
Stuart Scott54788802015-03-30 13:18:01 -07005982 }
5983
Jack Yud10cdd42020-09-28 20:28:01 -07005984 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005985 * Ask the radio to connect to the input network and change selection mode to manual.
5986 *
5987 * @param subId the id of the subscription.
5988 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5989 * the operator to attach to.
5990 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5991 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5992 * normal network selection next time.
5993 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005994 */
5995 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005996 public boolean setNetworkSelectionModeManual(
5997 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5999 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006000
Jack Yudf049d72022-12-02 22:48:35 -08006001 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006002 if (!isActiveSubscription(subId)) {
6003 return false;
6004 }
6005
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006007 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006009 if (DBG) {
6010 log("setNetworkSelectionModeManual: subId: " + subId
6011 + " operator: " + operatorInfo);
6012 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6014 } finally {
6015 Binder.restoreCallingIdentity(identity);
6016 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006017 }
shilu84f6e8b2019-12-19 13:58:01 -08006018 /**
6019 * Get the manual network selection
6020 *
6021 * @param subId the id of the subscription.
6022 *
6023 * @return the previously saved user selected PLMN
6024 */
6025 @Override
6026 public String getManualNetworkSelectionPlmn(int subId) {
6027 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006028 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006029 mApp, subId, "getManualNetworkSelectionPlmn");
6030
6031 final long identity = Binder.clearCallingIdentity();
6032 try {
6033 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006034 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006035 }
6036
6037 final Phone phone = getPhone(subId);
6038 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006039 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006040 }
6041 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6042 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6043 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6044 } finally {
6045 Binder.restoreCallingIdentity(identity);
6046 }
6047 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006048
6049 /**
6050 * Scans for available networks.
6051 */
6052 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006053 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6054 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6056 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006057 LocationAccessPolicy.LocationPermissionResult locationResult =
6058 LocationAccessPolicy.checkLocationPermission(mApp,
6059 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6060 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006061 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006062 .setCallingPid(Binder.getCallingPid())
6063 .setCallingUid(Binder.getCallingUid())
6064 .setMethod("getCellNetworkScanResults")
6065 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006066 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6067 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006068 .build());
6069 switch (locationResult) {
6070 case DENIED_HARD:
6071 throw new SecurityException("Not allowed to access scan results -- location");
6072 case DENIED_SOFT:
6073 return null;
6074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075
Pengquan Menga1bb6272018-09-06 09:59:22 -07006076 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 try {
6078 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006079 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 } finally {
6082 Binder.restoreCallingIdentity(identity);
6083 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006084 }
6085
6086 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006087 * Get the call forwarding info, given the call forwarding reason.
6088 */
6089 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006090 public void getCallForwarding(int subId, int callForwardingReason,
6091 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006092 enforceReadPrivilegedPermission("getCallForwarding");
6093 long identity = Binder.clearCallingIdentity();
6094 try {
6095 if (DBG) {
6096 log("getCallForwarding: subId " + subId
6097 + " callForwardingReason" + callForwardingReason);
6098 }
Hall Liu27d24262020-09-18 19:04:59 -07006099
6100 Phone phone = getPhone(subId);
6101 if (phone == null) {
6102 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006103 callback.onError(
6104 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006105 } catch (RemoteException e) {
6106 // ignore
6107 }
6108 return;
6109 }
6110
6111 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6112 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6113 @Override
6114 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6115 try {
6116 callback.onCallForwardingInfoAvailable(info);
6117 } catch (RemoteException e) {
6118 // ignore
6119 }
6120 }
6121
6122 @Override
6123 public void onError(int error) {
6124 try {
6125 callback.onError(error);
6126 } catch (RemoteException e) {
6127 // ignore
6128 }
6129 }
6130 });
6131 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006132 } finally {
6133 Binder.restoreCallingIdentity(identity);
6134 }
6135 }
6136
6137 /**
6138 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6139 * reason, the number to forward, and the timeout before the forwarding is attempted.
6140 */
6141 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006142 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6143 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006144 enforceModifyPermission();
6145 long identity = Binder.clearCallingIdentity();
6146 try {
6147 if (DBG) {
6148 log("setCallForwarding: subId " + subId
6149 + " callForwardingInfo" + callForwardingInfo);
6150 }
Hall Liu27d24262020-09-18 19:04:59 -07006151
6152 Phone phone = getPhone(subId);
6153 if (phone == null) {
6154 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006155 callback.accept(
6156 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006157 } catch (RemoteException e) {
6158 // ignore
6159 }
6160 return;
6161 }
6162
6163 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6164 FunctionalUtils.ignoreRemoteException(callback::accept));
6165
6166 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169 }
6170 }
6171
6172 /**
Hall Liu27d24262020-09-18 19:04:59 -07006173 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006174 */
6175 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006176 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006177 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006178 long identity = Binder.clearCallingIdentity();
6179 try {
Hall Liu27d24262020-09-18 19:04:59 -07006180 Phone phone = getPhone(subId);
6181 if (phone == null) {
6182 try {
6183 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6184 } catch (RemoteException e) {
6185 // ignore
6186 }
6187 return;
6188 }
SongFerngWang0e767992021-03-31 22:08:45 +08006189 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6190 PersistableBundle c = configManager.getConfigForSubId(subId);
6191 boolean requireUssd = c.getBoolean(
6192 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006193
Shuo Qian4a594052020-01-23 11:59:30 -08006194 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006195 if (requireUssd) {
6196 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6197 getSubscriptionCarrierId(subId));
6198 String newUssdCommand = "";
6199 try {
6200 newUssdCommand = carrierXmlParser.getFeature(
6201 CarrierXmlParser.FEATURE_CALL_WAITING)
6202 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6203 } catch (NullPointerException e) {
6204 loge("Failed to generate USSD number" + e);
6205 }
6206 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6207 mMainThreadHandler, callback, carrierXmlParser,
6208 CarrierXmlParser.SsEntry.SSAction.QUERY);
6209 final String ussdCommand = newUssdCommand;
6210 Executors.newSingleThreadExecutor().execute(() -> {
6211 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6212 });
6213 } else {
6214 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6215 callback::accept);
6216 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6217 }
Shuo Qian4a594052020-01-23 11:59:30 -08006218 } finally {
6219 Binder.restoreCallingIdentity(identity);
6220 }
6221 }
6222
6223 /**
Hall Liu27d24262020-09-18 19:04:59 -07006224 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006225 */
6226 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006227 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006228 enforceModifyPermission();
6229 long identity = Binder.clearCallingIdentity();
6230 try {
Hall Liu27d24262020-09-18 19:04:59 -07006231 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6232
6233 Phone phone = getPhone(subId);
6234 if (phone == null) {
6235 try {
6236 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6237 } catch (RemoteException e) {
6238 // ignore
6239 }
6240 return;
6241 }
6242
SongFerngWang0e767992021-03-31 22:08:45 +08006243 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6244 PersistableBundle c = configManager.getConfigForSubId(subId);
6245 boolean requireUssd = c.getBoolean(
6246 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006247
SongFerngWang0e767992021-03-31 22:08:45 +08006248 if (DBG) log("getCallWaitingStatus: subId " + subId);
6249 if (requireUssd) {
6250 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6251 getSubscriptionCarrierId(subId));
6252 CarrierXmlParser.SsEntry.SSAction ssAction =
6253 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6254 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6255 String newUssdCommand = "";
6256 try {
6257 newUssdCommand = carrierXmlParser.getFeature(
6258 CarrierXmlParser.FEATURE_CALL_WAITING)
6259 .makeCommand(ssAction, null);
6260 } catch (NullPointerException e) {
6261 loge("Failed to generate USSD number" + e);
6262 }
6263 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6264 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6265 final String ussdCommand = newUssdCommand;
6266 Executors.newSingleThreadExecutor().execute(() -> {
6267 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6268 });
6269 } else {
6270 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6271 FunctionalUtils.ignoreRemoteException(callback::accept));
6272
6273 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6274 }
Shuo Qian4a594052020-01-23 11:59:30 -08006275 } finally {
6276 Binder.restoreCallingIdentity(identity);
6277 }
6278 }
6279
6280 /**
yinxub1bed742017-04-17 11:45:04 -07006281 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006282 *
yinxub1bed742017-04-17 11:45:04 -07006283 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006284 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6285 * location related information which will be sent if the caller already possess
6286 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006287 * @param request contains the radio access networks with bands/channels to scan
6288 * @param messenger callback messenger for scan results or errors
6289 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006290 * @return the id of the requested scan which can be used to stop the scan.
6291 */
6292 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006293 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6294 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006295 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6297 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006298 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006299 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6300 if (!renounceFineLocationAccess) {
6301 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6302 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6303 .setCallingPackage(callingPackage)
6304 .setCallingFeatureId(callingFeatureId)
6305 .setCallingPid(Binder.getCallingPid())
6306 .setCallingUid(Binder.getCallingUid())
6307 .setMethod("requestNetworkScan")
6308 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6309 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6310 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6311 .build());
6312 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006313 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006314 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6315 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006316 if (e != null) {
6317 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6318 throw e;
6319 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006320 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006321 return TelephonyScanManager.INVALID_SCAN_ID;
6322 }
6323 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324 }
Hall Liu912dfd32019-04-25 14:02:26 -07006325 int callingUid = Binder.getCallingUid();
6326 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006327 final long identity = Binder.clearCallingIdentity();
6328 try {
6329 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006330 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006331 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006332 } finally {
6333 Binder.restoreCallingIdentity(identity);
6334 }
yinxu504e1392017-04-12 16:03:22 -07006335 }
6336
Hall Liub2ac8ef2019-02-28 15:56:23 -08006337 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006338 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wangaccdabf2022-10-20 16:52:29 +00006339 boolean hasCarrierPriv;
6340 final long identity = Binder.clearCallingIdentity();
6341 try {
6342 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6343 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6344 } finally {
6345 Binder.restoreCallingIdentity(identity);
6346 }
Hall Liu558027f2019-05-15 19:14:05 -07006347 boolean hasNetworkScanPermission =
6348 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6349 == PERMISSION_GRANTED;
6350
6351 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6352 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6353 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006354 }
6355
6356 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6357 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006358 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6359 return new SecurityException("Specific channels must not be"
6360 + " scanned without location access.");
6361 }
6362 }
6363 }
6364
Hall Liub2ac8ef2019-02-28 15:56:23 -08006365 return null;
6366 }
6367
yinxu504e1392017-04-12 16:03:22 -07006368 /**
6369 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006370 *
6371 * @param subId id of the subscription
6372 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006373 */
6374 @Override
6375 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6377 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378
Hall Liu912dfd32019-04-25 14:02:26 -07006379 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380 final long identity = Binder.clearCallingIdentity();
6381 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006382 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383 } finally {
6384 Binder.restoreCallingIdentity(identity);
6385 }
yinxu504e1392017-04-12 16:03:22 -07006386 }
6387
6388 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006389 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006390 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006391 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006392 */
6393 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006394 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006395 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006396 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006397 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006398
6399 final long identity = Binder.clearCallingIdentity();
6400 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006401 if (DBG) log("getAllowedNetworkTypesBitmask");
6402 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6403 int networkTypesBitmask = (result != null ? result[0] : -1);
6404 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6405 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406 } finally {
6407 Binder.restoreCallingIdentity(identity);
6408 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006409 }
6410
6411 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006412 * Get the allowed network types for certain reason.
6413 *
6414 * @param subId the id of the subscription.
6415 * @param reason the reason the allowed network type change is taking place
6416 * @return the allowed network types.
6417 */
6418 @Override
6419 public long getAllowedNetworkTypesForReason(int subId,
6420 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006421 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006422 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006423 final long identity = Binder.clearCallingIdentity();
6424 try {
6425 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6426 } finally {
6427 Binder.restoreCallingIdentity(identity);
6428 }
6429 }
6430
6431 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006432 * Enable/Disable E-UTRA-NR Dual Connectivity
6433 * @param subId subscription id of the sim card
6434 * @param nrDualConnectivityState expected NR dual connectivity state
6435 * This can be passed following states
6436 * <ol>
6437 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6438 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6439 * <li>Disable NR dual connectivity and force secondary cell to be released
6440 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6441 * </ol>
6442 * @return operation result.
6443 */
6444 @Override
6445 public int setNrDualConnectivityState(int subId,
6446 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6448 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006449 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006450 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6451 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6452 }
6453
Sooraj Sasindran37444802020-08-11 10:40:43 -07006454 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6455 final long identity = Binder.clearCallingIdentity();
6456 try {
6457 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6458 nrDualConnectivityState, subId,
6459 workSource);
6460 if (DBG) log("enableNRDualConnectivity result: " + result);
6461 return result;
6462 } finally {
6463 Binder.restoreCallingIdentity(identity);
6464 }
6465 }
6466
6467 /**
6468 * Is E-UTRA-NR Dual Connectivity enabled
6469 * @return true if dual connectivity is enabled else false
6470 */
6471 @Override
6472 public boolean isNrDualConnectivityEnabled(int subId) {
6473 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006474 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006475 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006476 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006477 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6478 return false;
6479 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006480 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6481 final long identity = Binder.clearCallingIdentity();
6482 try {
6483 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6484 null, subId, workSource);
6485 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6486 return isEnabled;
6487 } finally {
6488 Binder.restoreCallingIdentity(identity);
6489 }
6490 }
6491
6492 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006493 * Set the allowed network types of the device and
6494 * provide the reason triggering the allowed network change.
6495 *
6496 * @param subId the id of the subscription.
6497 * @param reason the reason the allowed network type change is taking place
6498 * @param allowedNetworkTypes the allowed network types.
6499 * @return true on success; false on any failure.
6500 */
6501 @Override
6502 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006503 @TelephonyManager.AllowedNetworkTypesReason int reason,
6504 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6506 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006507 // If the caller only has carrier privileges, then they should not be able to override
6508 // any network types which were set for security reasons.
6509 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6510 != PERMISSION_GRANTED
6511 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6512 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6513 throw new SecurityException(
6514 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6515 + " reason "
6516 + reason);
6517 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006518 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006519 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6520 return false;
6521 }
6522 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6523 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006524 return false;
6525 }
6526
Jack Yu5e360c42022-12-16 11:53:37 -08006527 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006528 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6529
Jack Yu5e360c42022-12-16 11:53:37 -08006530 Phone phone = getPhone(subId);
6531 if (phone == null) {
6532 return false;
6533 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006534
Jack Yu5e360c42022-12-16 11:53:37 -08006535 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006536 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6537 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006538 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006539
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006540 final long identity = Binder.clearCallingIdentity();
6541 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006542 Boolean success = (Boolean) sendRequest(
6543 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6544 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6545
6546 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6547 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006548 } finally {
6549 Binder.restoreCallingIdentity(identity);
6550 }
6551 }
6552
6553 /**
Miaoa84611c2019-03-15 09:21:10 +08006554 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006555 *
Miaoa84611c2019-03-15 09:21:10 +08006556 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006557 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006558 * @hide
6559 */
6560 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006561 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006562 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006564 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565 try {
Miaoa84611c2019-03-15 09:21:10 +08006566 if (phone != null) {
6567 return phone.hasMatchedTetherApnSetting();
6568 } else {
6569 return false;
6570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006571 } finally {
6572 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006573 }
Junda Liu475951f2014-11-07 16:45:03 -08006574 }
6575
6576 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006577 * Get the user enabled state of Mobile Data.
6578 *
6579 * TODO: remove and use isUserDataEnabled.
6580 * This can't be removed now because some vendor codes
6581 * calls through ITelephony directly while they should
6582 * use TelephonyManager.
6583 *
6584 * @return true on enabled
6585 */
6586 @Override
6587 public boolean getDataEnabled(int subId) {
6588 return isUserDataEnabled(subId);
6589 }
6590
6591 /**
6592 * Get whether mobile data is enabled per user setting.
6593 *
6594 * There are other factors deciding whether mobile data is actually enabled, but they are
6595 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006596 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006597 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6598 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006599 *
6600 * @return {@code true} if data is enabled else {@code false}
6601 */
6602 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006603 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006604 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006605 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006606 try {
6607 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6608 functionName);
6609 } catch (Exception e) {
6610 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6611 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006612 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006614 mApp, subId, functionName);
6615
Robert Greenwalt646120a2014-05-23 11:54:03 -07006616 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006617
6618 final long identity = Binder.clearCallingIdentity();
6619 try {
Jack Yudf049d72022-12-02 22:48:35 -08006620 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006621 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6622 Phone phone = PhoneFactory.getPhone(phoneId);
6623 if (phone != null) {
6624 boolean retVal = phone.isUserDataEnabled();
6625 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6626 return retVal;
6627 } else {
6628 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6629 return false;
6630 }
6631 } finally {
6632 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006633 }
6634 }
6635
6636 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006637 * Checks if the device is capable of mobile data by considering whether whether the
6638 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6639 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006640 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006641 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006642 */
6643 @Override
6644 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006645 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006646 try {
6647 try {
6648 mApp.enforceCallingOrSelfPermission(
6649 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006650 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006651 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006652 try {
6653 mApp.enforceCallingOrSelfPermission(
6654 android.Manifest.permission.READ_PHONE_STATE,
6655 functionName);
6656 } catch (Exception e2) {
6657 mApp.enforceCallingOrSelfPermission(
6658 permission.READ_BASIC_PHONE_STATE, functionName);
6659 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006660 }
6661 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006662 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006664
6665 final long identity = Binder.clearCallingIdentity();
6666 try {
Jack Yudf049d72022-12-02 22:48:35 -08006667 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668 Phone phone = PhoneFactory.getPhone(phoneId);
6669 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006670 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006671 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006672 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006673 return retVal;
6674 } else {
6675 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6676 return false;
6677 }
6678 } finally {
6679 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006680 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006681 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006682
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006683 /**
6684 * Check if data is enabled for a specific reason
6685 * @param subId Subscription index
6686 * @param reason the reason the data enable change is taking place
6687 * @return {@code true} if the overall data is enabled; {@code false} if not.
6688 */
6689 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006690 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006691 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006692 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006693 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006694 try {
6695 mApp.enforceCallingOrSelfPermission(
6696 android.Manifest.permission.ACCESS_NETWORK_STATE,
6697 functionName);
6698 } catch (Exception e) {
6699 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6700 functionName);
6701 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006702 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006703 try {
6704 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006705 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006706 } catch (Exception e2) {
6707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006708 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006709 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006710 }
6711
6712
6713 final long identity = Binder.clearCallingIdentity();
6714 try {
Jack Yudf049d72022-12-02 22:48:35 -08006715 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006716 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006717 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006718 + " reason=" + reason);
6719 }
6720 Phone phone = PhoneFactory.getPhone(phoneId);
6721 if (phone != null) {
6722 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006723 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006724 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006725 return retVal;
6726 } else {
6727 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006728 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006729 + subId + " retVal=false");
6730 }
6731 return false;
6732 }
6733 } finally {
6734 Binder.restoreCallingIdentity(identity);
6735 }
6736 }
6737
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006738 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006739 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006740 // No permission needed; this only lets the caller inspect their own status.
6741 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006742 }
Junda Liu29340342014-07-10 15:23:27 -07006743
6744 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006745 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006746 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006747 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6748 }
6749
6750 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6751 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006752 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006753 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006754 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6755 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006756 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6757 if (cpt == null) {
6758 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006759 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6760 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006761 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006762 }
6763
6764 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006765 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006766 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006767 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006768 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006769 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006770 Phone phone = getPhone(subId);
6771 if (phone == null) {
6772 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6773 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6774 }
6775 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6776 if (cpt == null) {
6777 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006778 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6779 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006780 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006781 }
6782
6783 @Override
6784 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006785 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006786 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6787 }
6788
6789 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006790 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006791 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006792 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006793 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006794 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6795 Phone phone = PhoneFactory.getPhone(phoneId);
6796 if (phone == null) {
6797 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006798 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006799 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6800 if (cpt == null) {
6801 continue;
6802 }
6803 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006804 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6805 break;
6806 }
6807 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006808 return result;
Junda Liu29340342014-07-10 15:23:27 -07006809 }
Derek Tan89e89d42014-07-08 17:00:10 -07006810
6811 @Override
Junda Liue64de782015-04-16 17:19:16 -07006812 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006813 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006814 Phone phone = PhoneFactory.getPhone(phoneId);
6815 if (phone == null) {
6816 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006817 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006818 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6819 if (cpt == null) {
6820 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006821 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006822 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006823 }
6824
Amith Yamasani6e118872016-02-19 12:53:51 -08006825 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006826 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006827 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006828 Phone phone = PhoneFactory.getPhone(phoneId);
6829 if (phone == null) {
6830 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006831 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006832 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6833 if (cpt == null) {
6834 return Collections.emptyList();
6835 }
6836 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006837 }
6838
chen xuf7e9fe82019-05-09 19:31:02 -07006839 @Override
6840 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006841 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006842 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006843 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006844 try {
6845 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6846 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6847 }
6848 } finally {
6849 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006850 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006851 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006852 }
6853
Rambo Wang6812ffb2022-03-15 16:54:17 -07006854 @Override
6855 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6856 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6857
6858 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6859 if (phone == null) {
6860 return null;
6861 }
6862 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6863 if (cpt == null) {
6864 return null;
6865 }
6866 return cpt.getCarrierServicePackageName();
6867 }
6868
Wink Savilleb564aae2014-10-23 10:18:09 -07006869 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006870 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006871 UiccPort port = phone == null ? null : phone.getUiccPort();
6872 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006873 return null;
6874 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006875 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006876 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006877 return null;
6878 }
6879 return iccId;
6880 }
6881
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006882 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006883 public void setCallComposerStatus(int subId, int status) {
6884 enforceModifyPermission();
6885
6886 final long identity = Binder.clearCallingIdentity();
6887 try {
6888 Phone phone = getPhone(subId);
6889 if (phone != null) {
6890 Phone defaultPhone = phone.getImsPhone();
6891 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6892 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6893 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006894 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6895 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006896 }
6897 }
Shuo Qian284ae752020-12-22 19:10:14 -08006898 } catch (ImsException e) {
6899 throw new ServiceSpecificException(e.getCode());
6900 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006901 Binder.restoreCallingIdentity(identity);
6902 }
6903 }
6904
6905 @Override
6906 public int getCallComposerStatus(int subId) {
6907 enforceReadPrivilegedPermission("getCallComposerStatus");
6908
6909 final long identity = Binder.clearCallingIdentity();
6910 try {
6911 Phone phone = getPhone(subId);
6912 if (phone != null) {
6913 Phone defaultPhone = phone.getImsPhone();
6914 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6915 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6916 return imsPhone.getCallComposerStatus();
6917 }
6918 }
6919 } finally {
6920 Binder.restoreCallingIdentity(identity);
6921 }
6922 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6923 }
6924
6925 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006926 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6927 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006928 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006929 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006931 final long identity = Binder.clearCallingIdentity();
6932 try {
6933 final String iccId = getIccId(subId);
6934 final Phone phone = getPhone(subId);
6935 if (phone == null) {
6936 return false;
6937 }
6938 final String subscriberId = phone.getSubscriberId();
6939
6940 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006941 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006942 + subscriberId + " to " + number);
6943 }
6944
6945 if (TextUtils.isEmpty(iccId)) {
6946 return false;
6947 }
6948
6949 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6950
6951 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6952 if (alphaTag == null) {
6953 editor.remove(alphaTagPrefKey);
6954 } else {
6955 editor.putString(alphaTagPrefKey, alphaTag);
6956 }
6957
6958 // Record both the line number and IMSI for this ICCID, since we need to
6959 // track all merged IMSIs based on line number
6960 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6961 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6962 if (number == null) {
6963 editor.remove(numberPrefKey);
6964 editor.remove(subscriberPrefKey);
6965 } else {
6966 editor.putString(numberPrefKey, number);
6967 editor.putString(subscriberPrefKey, subscriberId);
6968 }
6969
6970 editor.commit();
6971 return true;
6972 } finally {
6973 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006974 }
Derek Tan7226c842014-07-02 17:42:23 -07006975 }
6976
6977 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006978 public String getLine1NumberForDisplay(int subId, String callingPackage,
6979 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006980 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006982 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006983 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006984 return null;
6985 }
Derek Tan97ebb422014-09-05 16:55:38 -07006986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006987 final long identity = Binder.clearCallingIdentity();
6988 try {
6989 String iccId = getIccId(subId);
6990 if (iccId != null) {
6991 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6992 if (DBG_MERGE) {
6993 log("getLine1NumberForDisplay returning "
6994 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6995 }
6996 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006998 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6999 return null;
7000 } finally {
7001 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007002 }
Derek Tan7226c842014-07-02 17:42:23 -07007003 }
7004
7005 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007006 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7007 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007009 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007010 return null;
7011 }
Derek Tan97ebb422014-09-05 16:55:38 -07007012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007013 final long identity = Binder.clearCallingIdentity();
7014 try {
7015 String iccId = getIccId(subId);
7016 if (iccId != null) {
7017 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7018 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7019 }
7020 return null;
7021 } finally {
7022 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007023 }
Derek Tan7226c842014-07-02 17:42:23 -07007024 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007025
7026 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007027 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7028 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007029 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7030 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007031 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007032 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007033 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007034 return null;
7035 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007036
Jordan Liub49b04b2019-05-06 14:45:15 -07007037 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7038 // the process, where TelephonyManager was instantiated.
7039 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007040 final long identity = Binder.clearCallingIdentity();
7041 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007042 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 final TelephonyManager tele = TelephonyManager.from(context);
7044 final SubscriptionManager sub = SubscriptionManager.from(context);
7045
7046 // Figure out what subscribers are currently active
7047 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048
Jordan Liub49b04b2019-05-06 14:45:15 -07007049 // Only consider subs which match the current subId
7050 // This logic can be simplified. See b/131189269 for progress.
7051 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007052 activeSubscriberIds.add(tele.getSubscriberId(subId));
7053 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007054
7055 // First pass, find a number override for an active subscriber
7056 String mergeNumber = null;
7057 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7058 for (String key : prefs.keySet()) {
7059 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7060 final String subscriberId = (String) prefs.get(key);
7061 if (activeSubscriberIds.contains(subscriberId)) {
7062 final String iccId = key.substring(
7063 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7064 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7065 mergeNumber = (String) prefs.get(numberKey);
7066 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007067 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007068 + " for active subscriber " + subscriberId);
7069 }
7070 if (!TextUtils.isEmpty(mergeNumber)) {
7071 break;
7072 }
7073 }
7074 }
7075 }
7076
7077 // Shortcut when no active merged subscribers
7078 if (TextUtils.isEmpty(mergeNumber)) {
7079 return null;
7080 }
7081
7082 // Second pass, find all subscribers under that line override
7083 final ArraySet<String> result = new ArraySet<>();
7084 for (String key : prefs.keySet()) {
7085 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7086 final String number = (String) prefs.get(key);
7087 if (mergeNumber.equals(number)) {
7088 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7089 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7090 final String subscriberId = (String) prefs.get(subscriberKey);
7091 if (!TextUtils.isEmpty(subscriberId)) {
7092 result.add(subscriberId);
7093 }
7094 }
7095 }
7096 }
7097
7098 final String[] resultArray = result.toArray(new String[result.size()]);
7099 Arrays.sort(resultArray);
7100 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007101 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007102 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7103 }
7104 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007105 } finally {
7106 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007107 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007108 }
7109
7110 @Override
zoey chen38003472019-12-13 17:16:31 +08007111 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7112 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007113
7114 final long identity = Binder.clearCallingIdentity();
7115 try {
7116 final TelephonyManager telephonyManager = mApp.getSystemService(
7117 TelephonyManager.class);
7118 String subscriberId = telephonyManager.getSubscriberId(subId);
7119 if (subscriberId == null) {
7120 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007121 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007122 + subId);
7123 }
7124 return null;
7125 }
7126
Jack Yudf049d72022-12-02 22:48:35 -08007127 ParcelUuid groupUuid;
7128 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7129 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7130 .getSubscriptionInfo(subId);
7131 groupUuid = info.getGroupUuid();
7132 } else {
7133 final SubscriptionInfo info = mSubscriptionController
7134 .getSubscriptionInfo(subId);
7135 groupUuid = info.getGroupUuid();
7136 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007137 // If it doesn't belong to any group, return just subscriberId of itself.
7138 if (groupUuid == null) {
7139 return new String[]{subscriberId};
7140 }
7141
7142 // Get all subscriberIds from the group.
7143 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yudf049d72022-12-02 22:48:35 -08007144 List<SubscriptionInfo> groupInfos;
7145 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7146 groupInfos = SubscriptionManagerService.getInstance()
7147 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7148 mApp.getAttributionTag());
7149 } else {
7150 groupInfos = mSubscriptionController
7151 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7152 mApp.getAttributionTag());
7153 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007154 for (SubscriptionInfo subInfo : groupInfos) {
7155 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7156 if (subscriberId != null) {
7157 mergedSubscriberIds.add(subscriberId);
7158 }
7159 }
7160
7161 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7162 } finally {
7163 Binder.restoreCallingIdentity(identity);
7164
7165 }
7166 }
7167
7168 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007169 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007170 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007171 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007172
7173 final long identity = Binder.clearCallingIdentity();
7174 try {
7175 final Phone phone = getPhone(subId);
7176 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7177 } finally {
7178 Binder.restoreCallingIdentity(identity);
7179 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007180 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007181
7182 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007183 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007184 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7185 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007186 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7187 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007188
7189 final long identity = Binder.clearCallingIdentity();
7190 try {
7191 final Phone phone = getPhone(subId);
7192 if (phone == null) {
7193 return false;
7194 }
7195 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7196 cdmaNonRoamingList);
7197 } finally {
7198 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007199 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007200 }
7201
7202 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007203 @Deprecated
7204 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7205 enforceModifyPermission();
7206
7207 int returnValue = 0;
7208 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007209 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007210 if(result.exception == null) {
7211 if (result.result != null) {
7212 byte[] responseData = (byte[])(result.result);
7213 if(responseData.length > oemResp.length) {
7214 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7215 responseData.length + "bytes. Buffer Size is " +
7216 oemResp.length + "bytes.");
7217 }
7218 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7219 returnValue = responseData.length;
7220 }
7221 } else {
7222 CommandException ex = (CommandException) result.exception;
7223 returnValue = ex.getCommandError().ordinal();
7224 if(returnValue > 0) returnValue *= -1;
7225 }
7226 } catch (RuntimeException e) {
7227 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7228 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7229 if(returnValue > 0) returnValue *= -1;
7230 }
7231
7232 return returnValue;
7233 }
7234
7235 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007236 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007237 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007238 try {
7239 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007240 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007241 mApp, phone.getSubId(), "getRadioAccessFamily");
7242 } catch (SecurityException e) {
7243 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7244 throw e;
7245 }
chen xub97461a2018-10-26 14:17:57 -07007246 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007247 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007248 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007249 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250 final long identity = Binder.clearCallingIdentity();
7251 try {
chen xub97461a2018-10-26 14:17:57 -07007252 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007253 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007254 mApp, phone.getSubId(), "getRadioAccessFamily");
7255 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007256 } finally {
7257 Binder.restoreCallingIdentity(identity);
7258 }
chen xub97461a2018-10-26 14:17:57 -07007259 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007260 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007261
7262 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007263 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007264 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007265 try {
7266 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7267 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007268 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007269 }
7270 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007271 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007272 }
7273 RoleManager rm = mApp.getSystemService(RoleManager.class);
7274 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7275 if (!dialerRoleHolders.contains(callingPackage)) {
7276 throw new SecurityException("App must be the dialer role holder to"
7277 + " upload a call composer pic");
7278 }
7279
7280 Executors.newSingleThreadExecutor().execute(() -> {
7281 ByteArrayOutputStream output = new ByteArrayOutputStream(
7282 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7283 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7284 boolean readUntilEnd = false;
7285 int totalBytesRead = 0;
7286 byte[] buffer = new byte[16 * 1024];
7287 while (true) {
7288 int numRead;
7289 try {
7290 numRead = input.read(buffer);
7291 } catch (IOException e) {
7292 try {
7293 fd.checkError();
7294 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7295 null);
7296 } catch (IOException e1) {
7297 // This means that the other side closed explicitly with an error. If this
7298 // happens, log and ignore.
7299 loge("Remote end of call composer picture pipe closed: " + e1);
7300 }
7301 break;
7302 }
7303 if (numRead == -1) {
7304 readUntilEnd = true;
7305 break;
7306 }
7307 totalBytesRead += numRead;
7308 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7309 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7310 try {
7311 input.close();
7312 } catch (IOException e) {
7313 // ignore
7314 }
7315 break;
7316 }
7317 output.write(buffer, 0, numRead);
7318 }
7319 // Generally, the remote end will close the file descriptors. The only case where we
7320 // close is above, where the picture size is too big.
7321
7322 try {
7323 fd.checkError();
7324 } catch (IOException e) {
7325 loge("Remote end for call composer closed with an error: " + e);
7326 return;
7327 }
7328
Hall Liuaa4211e2021-01-20 15:43:39 -08007329 if (!readUntilEnd) {
7330 loge("Did not finish reading entire image; aborting");
7331 return;
7332 }
Hall Liu82694d52020-12-11 18:22:04 -08007333
Hall Liuaa4211e2021-01-20 15:43:39 -08007334 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7335 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7336 new CallComposerPictureTransfer.Factory() {},
7337 imageData,
7338 (result) -> {
7339 if (result.first != null) {
7340 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7341 Bundle outputResult = new Bundle();
7342 outputResult.putParcelable(
7343 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7344 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7345 outputResult);
7346 } else {
7347 callback.send(result.second, null);
7348 }
7349 }
7350 );
Hall Liu82694d52020-12-11 18:22:04 -08007351 });
7352 }
7353
7354 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007355 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007356 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007357 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007358
7359 final long identity = Binder.clearCallingIdentity();
7360 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007361 ImsManager.getInstance(defaultPhone.getContext(),
7362 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363 } finally {
7364 Binder.restoreCallingIdentity(identity);
7365 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007366 }
7367
7368 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007369 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007370 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007371 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7372 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007373 return false;
7374 }
Svet Ganovb320e182015-04-16 12:30:10 -07007375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376 final long identity = Binder.clearCallingIdentity();
7377 try {
7378 // Check the user preference and the system-level IMS setting. Even if the user has
7379 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7380 // In the long run, we may instead need to check if there exists a connection service
7381 // which can support video calling.
7382 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007383 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384 return imsManager.isVtEnabledByPlatform()
7385 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7386 && imsManager.isVtEnabledByUser();
7387 } finally {
7388 Binder.restoreCallingIdentity(identity);
7389 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007390 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007391
Andrew Leea1239f22015-03-02 17:44:07 -08007392 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007393 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7394 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007396 mApp, subId, callingPackage, callingFeatureId,
7397 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 return false;
7399 }
7400
7401 final long identity = Binder.clearCallingIdentity();
7402 try {
7403 CarrierConfigManager configManager =
7404 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007405 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7407 } finally {
7408 Binder.restoreCallingIdentity(identity);
7409 }
Andrew Leea1239f22015-03-02 17:44:07 -08007410 }
7411
7412 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007413 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007415 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007416 return false;
7417 }
7418
7419 final long identity = Binder.clearCallingIdentity();
7420 try {
7421 CarrierConfigManager configManager =
7422 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007423 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7425 } finally {
7426 Binder.restoreCallingIdentity(identity);
7427 }
Andrew Leea1239f22015-03-02 17:44:07 -08007428 }
7429
Andrew Lee9431b832015-03-09 18:46:45 -07007430 @Override
7431 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007432 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007433 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007434 }
7435
7436 @Override
7437 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 final long identity = Binder.clearCallingIdentity();
7439 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007440 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 } finally {
7442 Binder.restoreCallingIdentity(identity);
7443 }
Andrew Lee9431b832015-03-09 18:46:45 -07007444 }
7445
Hall Liuf6668912018-10-31 17:05:23 -07007446 /**
7447 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7448 * support for the feature and device firmware support.
7449 *
7450 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7451 */
7452 @Override
7453 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007454 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007455 final Phone phone = getPhone(subscriptionId);
7456 if (phone == null) {
7457 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7458 return false;
7459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007461 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7463 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007464 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 return isCarrierSupported && isDeviceSupported;
7466 } finally {
7467 Binder.restoreCallingIdentity(identity);
7468 }
Hall Liu98187582018-01-22 19:15:32 -08007469 }
7470
Hall Liuf6668912018-10-31 17:05:23 -07007471 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007472 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7473 * RTT setting, will return true if the device and carrier both support RTT.
7474 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007475 */
7476 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 final long identity = Binder.clearCallingIdentity();
7478 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007479 boolean isRttSupported = isRttSupported(subscriptionId);
7480 boolean isUserRttSettingOn = Settings.Secure.getInt(
7481 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7482 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7483 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7484 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 } finally {
7486 Binder.restoreCallingIdentity(identity);
7487 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007488 }
7489
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007490 @Deprecated
7491 @Override
7492 public String getDeviceId(String callingPackage) {
7493 return getDeviceIdWithFeature(callingPackage, null);
7494 }
7495
Sanket Padawe7310cc72015-01-14 09:53:20 -08007496 /**
7497 * Returns the unique device ID of phone, for example, the IMEI for
7498 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7499 *
7500 * <p>Requires Permission:
7501 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7502 */
7503 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007504 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007505 try {
7506 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7507 } catch (SecurityException se) {
7508 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7509 throw new SecurityException("Package " + callingPackage + " does not belong to "
7510 + Binder.getCallingUid());
7511 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007512 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007513 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007514 return null;
7515 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007516 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007517 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007518 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007519 return null;
7520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521
7522 final long identity = Binder.clearCallingIdentity();
7523 try {
7524 return phone.getDeviceId();
7525 } finally {
7526 Binder.restoreCallingIdentity(identity);
7527 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007528 }
7529
Ping Sunc67b7c22016-03-02 19:16:45 +08007530 /**
7531 * {@hide}
7532 * Returns the IMS Registration Status on a particular subid
7533 *
7534 * @param subId
7535 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007536 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007537 Phone phone = getPhone(subId);
7538 if (phone != null) {
7539 return phone.isImsRegistered();
7540 } else {
7541 return false;
7542 }
7543 }
7544
Santos Cordon7a1885b2015-02-03 11:15:19 -08007545 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007546 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007547 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007549 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007550 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7551 }
7552 final long identity = Binder.clearCallingIdentity();
7553 try {
7554 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7555 } finally {
7556 Binder.restoreCallingIdentity(identity);
7557 }
7558 }
7559
7560 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007561 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007562 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007563 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007564 mApp,
7565 subscriptionId,
7566 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007567 final long identity = Binder.clearCallingIdentity();
7568 try {
7569 Phone phone = getPhone(subscriptionId);
7570 if (phone == null) {
7571 return null;
7572 }
7573 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7574 } finally {
7575 Binder.restoreCallingIdentity(identity);
7576 }
7577 }
7578
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007579 /**
7580 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007581 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007582 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583 final long identity = Binder.clearCallingIdentity();
7584 try {
7585 Phone phone = getPhone(subId);
7586 if (phone != null) {
7587 return phone.isWifiCallingEnabled();
7588 } else {
7589 return false;
7590 }
7591 } finally {
7592 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007593 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007594 }
7595
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007596 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007597 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007598 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007599 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 final long identity = Binder.clearCallingIdentity();
7601 try {
7602 Phone phone = getPhone(subId);
7603 if (phone != null) {
7604 return phone.isVideoEnabled();
7605 } else {
7606 return false;
7607 }
7608 } finally {
7609 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007610 }
7611 }
7612
7613 /**
7614 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7615 * defined in {@link ImsRegistrationImplBase}.
7616 */
7617 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007618 final long identity = Binder.clearCallingIdentity();
7619 try {
7620 Phone phone = getPhone(subId);
7621 if (phone != null) {
7622 return phone.getImsRegistrationTech();
7623 } else {
7624 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7625 }
7626 } finally {
7627 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007628 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007629 }
7630
Stuart Scott8eef64f2015-04-08 15:13:54 -07007631 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007632 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007633 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007634 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7635 return;
7636 }
Kai Shif70f46f2021-03-03 13:59:46 -08007637 Phone defaultPhone = getDefaultPhone();
7638 if (defaultPhone != null) {
7639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7640 mApp, getDefaultPhone().getSubId(), "factoryReset");
7641 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007642 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007643
Svet Ganovcc087f82015-05-12 20:35:54 -07007644 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007645 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7646 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007647 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007648 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007649 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007650 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007651 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007652 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007653 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007654 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007655 // There has been issues when Sms raw table somehow stores orphan
7656 // fragments. They lead to garbled message when new fragments come
7657 // in and combined with those stale ones. In case this happens again,
7658 // user can reset all network settings which will clean up this table.
7659 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007660 // Clean up IMS settings as well here.
7661 int slotId = getSlotIndex(subId);
7662 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7663 ImsManager.getInstance(mApp, slotId).factoryReset();
7664 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007665
Kai Shif70f46f2021-03-03 13:59:46 -08007666 if (defaultPhone == null) {
7667 return;
7668 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007669 // Erase modem config if erase modem on network setting is enabled.
7670 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7671 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7672 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007673 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007674 }
Kai Shif70f46f2021-03-03 13:59:46 -08007675
7676 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007677 } finally {
7678 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007679 }
7680 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007681
SongFerngWangfd89b102021-05-27 22:44:54 +08007682 @VisibleForTesting
7683 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7684 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7685 return;
7686 }
7687 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7688 RILConstants.PREFERRED_NETWORK_MODE);
7689 SubscriptionManager.setSubscriptionProperty(subId,
7690 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7691 "user=" + defaultNetworkType);
7692 phone.loadAllowedNetworksFromSubscriptionDatabase();
7693 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7694 defaultNetworkType, null);
7695 }
7696
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007697 private void cleanUpSmsRawTable(Context context) {
7698 ContentResolver resolver = context.getContentResolver();
7699 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7700 resolver.delete(uri, null, null);
7701 }
7702
Narayan Kamath1c496c22015-04-16 14:40:19 +01007703 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007704 public String getSimLocaleForSubscriber(int subId) {
7705 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7706 final Phone phone = getPhone(subId);
7707 if (phone == null) {
7708 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007709 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007710 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007711 final long identity = Binder.clearCallingIdentity();
7712 try {
Jack Yudf049d72022-12-02 22:48:35 -08007713 SubscriptionInfo info;
7714 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7715 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
7716 phone.getContext().getOpPackageName(),
7717 phone.getContext().getAttributionTag());
7718 if (info == null) {
7719 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7720 return null;
7721 }
7722 } else {
7723 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
7724 phone.getContext().getOpPackageName(),
7725 phone.getContext().getAttributionTag());
7726 if (info == null) {
7727 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7728 return null;
7729 }
chen xu6291c472019-02-04 12:55:53 -08007730 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731 // Try and fetch the locale from the carrier properties or from the SIM language
7732 // preferences (EF-PL and EF-LI)...
7733 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007735 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7736 if (localeFromDefaultSim != null) {
7737 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7738 if (DBG) log("Using locale from subId: " + subId + " locale: "
7739 + localeFromDefaultSim);
tom hsu22b7c3e2022-10-27 00:10:04 +08007740 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007741 } else {
7742 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007743 }
7744 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746 // The SIM language preferences only store a language (e.g. fr = French), not an
7747 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7748 // the SIM and carrier preferences does not include a country we add the country
7749 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007750 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007752 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu22b7c3e2022-10-27 00:10:04 +08007753 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007754 }
7755
7756 if (DBG) log("No locale found - returning null");
7757 return null;
7758 } finally {
7759 Binder.restoreCallingIdentity(identity);
7760 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007761 }
7762
tom hsue9360cd2022-09-29 23:49:21 +08007763 @VisibleForTesting
tom hsu22b7c3e2022-10-27 00:10:04 +08007764 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsue9360cd2022-09-29 23:49:21 +08007765 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu22b7c3e2022-10-27 00:10:04 +08007766 phone.getContext());
tom hsue9360cd2022-09-29 23:49:21 +08007767 for (String localeTag : supportedLocale) {
tom hsu22b7c3e2022-10-27 00:10:04 +08007768 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7769 && TextUtils.equals(inputLocale.getCountry(),
tom hsue9360cd2022-09-29 23:49:21 +08007770 Locale.forLanguageTag(localeTag).getCountry())) {
7771 return localeTag;
7772 }
7773 }
7774 return inputLocale.toLanguageTag();
7775 }
7776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007777 /**
7778 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7779 */
7780 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yudf049d72022-12-02 22:48:35 -08007781 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7782 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
7783 mApp.getOpPackageName(), mApp.getAttributionTag());
7784 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007785 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007786 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007787 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007788
Gary Jian3aa9a762022-01-24 16:41:19 +08007789 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7790 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007791
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007792 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007793 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7794 * representing the state of the modem.
7795 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007796 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7797 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007798 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007799 */
7800 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007801 public void requestModemActivityInfo(ResultReceiver result) {
7802 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007803 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007804
7805 final long identity = Binder.clearCallingIdentity();
7806 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007807 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808 } finally {
7809 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007810 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007811 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007812
Siddharth Rayb8114062018-06-17 15:02:38 -07007813 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7814 // less than total activity duration.
7815 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7816 if (info == null) {
7817 return false;
7818 }
7819 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007820 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7821 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7822
Siddharth Rayb8114062018-06-17 15:02:38 -07007823 return (info.isValid()
7824 && (info.getSleepTimeMillis() <= activityDurationMs)
7825 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007826 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007827 && (totalTxTimeMs <= activityDurationMs));
7828 }
7829
Gary Jian3aa9a762022-01-24 16:41:19 +08007830 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7831 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7832 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7833 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7834
7835 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7836 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7837 }
7838
7839 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7840 mLastModemActivityInfo.setReceiveTimeMillis(
7841 rat,
7842 freq,
7843 info.getReceiveTimeMillis(rat, freq)
7844 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7845 }
7846
7847 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7848 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7849 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7850 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7851
7852 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7853 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7854 }
7855 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7856 mLastModemActivityInfo.setReceiveTimeMillis(
7857 rat,
7858 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7859 }
7860
7861 /**
7862 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7863 * @param info recent ModemActivityInfo
7864 */
7865 private void mergeModemActivityInfo(ModemActivityInfo info) {
7866 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08007867 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08007868 boolean matched;
7869 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7870 matched = false;
7871 int rat = info.getSpecificInfoRat(i);
7872 int freq = info.getSpecificInfoFrequencyRange(i);
7873 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7874 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7875 //if it already exists
7876 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7877 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7878 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7879 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7880 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7881 updateLastModemActivityInfo(info, rat, freq);
7882 matched = true;
7883 }
7884 } else {
7885 updateLastModemActivityInfo(info, rat);
7886 matched = true;
7887 }
7888 }
7889 }
7890
7891 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08007892 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08007893 new ActivityStatsTechSpecificInfo(
7894 rat,
7895 freq,
7896 info.getTransmitTimeMillis(rat, freq),
7897 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08007898 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08007899 }
7900 }
7901 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7902 mLastModemActivitySpecificInfo =
7903 new ActivityStatsTechSpecificInfo[merged.size()];
7904 merged.toArray(mLastModemActivitySpecificInfo);
7905
7906 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7907 mLastModemActivityInfo.setSleepTimeMillis(
7908 info.getSleepTimeMillis()
7909 + mLastModemActivityInfo.getSleepTimeMillis());
7910 mLastModemActivityInfo.setIdleTimeMillis(
7911 info.getIdleTimeMillis()
7912 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08007913
7914 mLastModemActivityInfo =
7915 new ModemActivityInfo(
7916 mLastModemActivityInfo.getTimestampMillis(),
7917 mLastModemActivityInfo.getSleepTimeMillis(),
7918 mLastModemActivityInfo.getIdleTimeMillis(),
7919 mLastModemActivitySpecificInfo);
7920 }
7921
7922 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
7923 ActivityStatsTechSpecificInfo[] info) {
7924 int infoSize = info.length;
7925 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
7926 for (int i = 0; i < infoSize; i++) {
7927 ret[i] = new ActivityStatsTechSpecificInfo(
7928 info[i].getRat(), info[i].getFrequencyRange(),
7929 info[i].getTransmitTimeMillis(),
7930 (int) info[i].getReceiveTimeMillis());
7931 }
7932 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08007933 }
7934
Jack Yu85bd38a2015-11-09 11:34:32 -08007935 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007936 * Returns the service state information on specified subscription.
7937 */
7938 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007939 public ServiceState getServiceStateForSubscriber(int subId,
7940 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7941 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007942 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007943 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007944 return null;
7945 }
7946
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007947 boolean hasFinePermission = false;
7948 boolean hasCoarsePermission = false;
7949 if (!renounceFineLocationAccess) {
7950 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7951 LocationAccessPolicy.checkLocationPermission(mApp,
7952 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7953 .setCallingPackage(callingPackage)
7954 .setCallingFeatureId(callingFeatureId)
7955 .setCallingPid(Binder.getCallingPid())
7956 .setCallingUid(Binder.getCallingUid())
7957 .setMethod("getServiceStateForSubscriber")
7958 .setLogAsInfo(true)
7959 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7960 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7961 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7962 .build());
7963 hasFinePermission =
7964 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7965 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007966
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007967 if (!renounceCoarseLocationAccess) {
7968 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7969 LocationAccessPolicy.checkLocationPermission(mApp,
7970 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7971 .setCallingPackage(callingPackage)
7972 .setCallingFeatureId(callingFeatureId)
7973 .setCallingPid(Binder.getCallingPid())
7974 .setCallingUid(Binder.getCallingUid())
7975 .setMethod("getServiceStateForSubscriber")
7976 .setLogAsInfo(true)
7977 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7978 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7979 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7980 .build());
7981 hasCoarsePermission =
7982 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7983 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007984
Jack Yu479f40e2020-10-27 21:29:25 -07007985 final Phone phone = getPhone(subId);
7986 if (phone == null) {
7987 return null;
7988 }
7989
Jordan Liu0f2bc442020-11-18 16:47:37 -08007990 final long identity = Binder.clearCallingIdentity();
7991
Jack Yu479f40e2020-10-27 21:29:25 -07007992 boolean isCallingPackageDataService = phone.getDataServicePackages()
7993 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007994 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007995 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yudf049d72022-12-02 22:48:35 -08007996 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7997 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
7998 .getSubscriptionInfoInternal(subId);
7999 if (subInfo == null || !subInfo.isActive()) {
8000 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8001 + "subId=" + subId);
8002 return null;
8003 }
8004 } else {
8005 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8006 callingFeatureId)) {
8007 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8008 + "subId=" + subId);
8009 return null;
8010 }
Jordan Liuc437b192020-08-17 10:59:12 -07008011 }
8012
Hall Liuf19c44f2018-11-27 14:38:17 -08008013 ServiceState ss = phone.getServiceState();
8014
8015 // Scrub out the location info in ServiceState depending on what level of access
8016 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008017 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008018 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8019 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008020 } finally {
8021 Binder.restoreCallingIdentity(identity);
8022 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008023 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008024
8025 /**
8026 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8027 *
8028 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8029 * voicemail ringtone.
8030 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8031 * PhoneAccount.
8032 */
8033 @Override
8034 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035 final long identity = Binder.clearCallingIdentity();
8036 try {
8037 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8038 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008039 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008040 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008042 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8043 } finally {
8044 Binder.restoreCallingIdentity(identity);
8045 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008046 }
8047
8048 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008049 * Sets the per-account voicemail ringtone.
8050 *
8051 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8052 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8053 *
8054 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8055 * voicemail ringtone.
8056 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8057 * PhoneAccount.
8058 */
8059 @Override
8060 public void setVoicemailRingtoneUri(String callingPackage,
8061 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008062 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008063 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008064 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8065 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8067 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8068 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070
8071 final long identity = Binder.clearCallingIdentity();
8072 try {
8073 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8074 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008075 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076 }
8077 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8078 } finally {
8079 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008080 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008081 }
8082
8083 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008084 * Returns whether vibration is set for voicemail notification in Phone settings.
8085 *
8086 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8087 * voicemail vibration setting.
8088 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8089 */
8090 @Override
8091 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008092 final long identity = Binder.clearCallingIdentity();
8093 try {
8094 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8095 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008096 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008099 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8100 } finally {
8101 Binder.restoreCallingIdentity(identity);
8102 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008103 }
8104
Youhan Wange64578a2016-05-02 15:32:42 -07008105 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008106 * Sets the per-account voicemail vibration.
8107 *
8108 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8109 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8110 *
8111 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8112 * voicemail vibration setting.
8113 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8114 * specific PhoneAccount.
8115 */
8116 @Override
8117 public void setVoicemailVibrationEnabled(String callingPackage,
8118 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008119 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008120 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008121 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8122 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8124 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8125 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008126 }
8127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008128 final long identity = Binder.clearCallingIdentity();
8129 try {
8130 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8131 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008132 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133 }
8134 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8135 } finally {
8136 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008137 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008138 }
8139
8140 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008141 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8142 *
8143 * @throws SecurityException if the caller does not have the required permission
8144 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008145 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008146 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008147 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008148 }
8149
8150 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008151 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8152 * permission.
8153 *
8154 * @throws SecurityException if the caller does not have the required permission
8155 */
8156 private void enforceSendSmsPermission() {
8157 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8158 }
8159
8160 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008161 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008162 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008163 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008164 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008165 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008166 final long identity = Binder.clearCallingIdentity();
8167 try {
8168 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008169 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008170 if (componentName == null) {
8171 throw new SecurityException(
8172 "Caller not current active visual voicemail package[null]");
8173 }
8174 String vvmPackage = componentName.getPackageName();
8175 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008176 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008177 }
8178 } finally {
8179 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008180 }
8181 }
8182
8183 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008184 * Return the application ID for the app type.
8185 *
8186 * @param subId the subscription ID that this request applies to.
8187 * @param appType the uicc app type.
8188 * @return Application ID for specificied app type, or null if no uicc.
8189 */
8190 @Override
8191 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008192 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008193 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008194
8195 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008196 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008197 if (phone == null) {
8198 return null;
8199 }
8200 String aid = null;
8201 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008202 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008203 .getApplicationByType(appType).getAid();
8204 } catch (Exception e) {
8205 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8206 }
8207 return aid;
8208 } finally {
8209 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008210 }
Youhan Wange64578a2016-05-02 15:32:42 -07008211 }
8212
Youhan Wang4001d252016-05-11 10:29:41 -07008213 /**
8214 * Return the Electronic Serial Number.
8215 *
8216 * @param subId the subscription ID that this request applies to.
8217 * @return ESN or null if error.
8218 */
8219 @Override
8220 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008221 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008222 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008223
8224 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008225 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008226 if (phone == null) {
8227 return null;
8228 }
8229 String esn = null;
8230 try {
8231 esn = phone.getEsn();
8232 } catch (Exception e) {
8233 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8234 }
8235 return esn;
8236 } finally {
8237 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008238 }
Youhan Wang4001d252016-05-11 10:29:41 -07008239 }
8240
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008241 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008242 * Return the Preferred Roaming List Version.
8243 *
8244 * @param subId the subscription ID that this request applies to.
8245 * @return PRLVersion or null if error.
8246 */
8247 @Override
8248 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008249 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008250 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008251
8252 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008253 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008254 if (phone == null) {
8255 return null;
8256 }
8257 String cdmaPrlVersion = null;
8258 try {
8259 cdmaPrlVersion = phone.getCdmaPrlVersion();
8260 } catch (Exception e) {
8261 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8262 }
8263 return cdmaPrlVersion;
8264 } finally {
8265 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008266 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008267 }
8268
8269 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008270 * Get snapshot of Telephony histograms
8271 * @return List of Telephony histograms
8272 * @hide
8273 */
8274 @Override
8275 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8277 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278
8279 final long identity = Binder.clearCallingIdentity();
8280 try {
8281 return RIL.getTelephonyRILTimingHistograms();
8282 } finally {
8283 Binder.restoreCallingIdentity(identity);
8284 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008285 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008286
8287 /**
8288 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008289 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8290 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008291 * Require system privileges. In the future we may add this to carrier APIs.
8292 *
Michele Berionne482f8202018-11-27 18:57:59 -08008293 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008294 */
8295 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008296 @TelephonyManager.SetCarrierRestrictionResult
8297 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008298 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008299 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008300
Michele Berionne482f8202018-11-27 18:57:59 -08008301 if (carrierRestrictionRules == null) {
8302 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008303 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008305 final long identity = Binder.clearCallingIdentity();
8306 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008307 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008308 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309 } finally {
8310 Binder.restoreCallingIdentity(identity);
8311 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008312 }
8313
8314 /**
8315 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008316 * Get the allowed carrier list and the excluded carrier list, including the priority between
8317 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008318 * Require system privileges. In the future we may add this to carrier APIs.
8319 *
Michele Berionne482f8202018-11-27 18:57:59 -08008320 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008321 */
8322 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008323 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008324 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008325 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008326
8327 final long identity = Binder.clearCallingIdentity();
8328 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008329 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8330 if (response instanceof CarrierRestrictionRules) {
8331 return (CarrierRestrictionRules) response;
8332 }
8333 // Response is an Exception of some kind,
8334 // which is signalled to the user as a NULL retval
8335 return null;
8336 } catch (Exception e) {
8337 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8338 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008339 } finally {
8340 Binder.restoreCallingIdentity(identity);
8341 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008342 }
8343
fionaxu59545b42016-05-25 15:53:37 -07008344 /**
fionaxu59545b42016-05-25 15:53:37 -07008345 * Action set from carrier signalling broadcast receivers to enable/disable radio
8346 * @param subId the subscription ID that this action applies to.
8347 * @param enabled control enable or disable radio.
8348 * {@hide}
8349 */
8350 @Override
8351 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8352 enforceModifyPermission();
8353 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008354
8355 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008356 if (phone == null) {
8357 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8358 return;
8359 }
8360 try {
8361 phone.carrierActionSetRadioEnabled(enabled);
8362 } catch (Exception e) {
8363 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008364 } finally {
8365 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008366 }
8367 }
8368
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008369 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008370 * Enable or disable Voice over NR (VoNR)
8371 * @param subId the subscription ID that this action applies to.
8372 * @param enabled enable or disable VoNR.
8373 * @return operation result.
8374 */
8375 @Override
8376 public int setVoNrEnabled(int subId, boolean enabled) {
8377 enforceModifyPermission();
8378 final Phone phone = getPhone(subId);
8379
8380 final long identity = Binder.clearCallingIdentity();
8381 if (phone == null) {
8382 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8383 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8384 }
8385
8386 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8387 try {
8388 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8389 workSource);
8390 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008391
8392 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8393 if (DBG) {
8394 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8395 }
8396 SubscriptionManager.setSubscriptionProperty(
8397 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8398 (enabled ? "1" : "0"));
8399 }
8400
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008401 return result;
8402 } finally {
8403 Binder.restoreCallingIdentity(identity);
8404 }
8405 }
8406
8407 /**
8408 * Is voice over NR enabled
8409 * @return true if VoNR is enabled else false
8410 */
8411 @Override
8412 public boolean isVoNrEnabled(int subId) {
8413 enforceReadPrivilegedPermission("isVoNrEnabled");
8414 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8415 final long identity = Binder.clearCallingIdentity();
8416 try {
8417 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8418 null, subId, workSource);
8419 if (DBG) log("isVoNrEnabled: " + isEnabled);
8420 return isEnabled;
8421 } finally {
8422 Binder.restoreCallingIdentity(identity);
8423 }
8424 }
8425
8426 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008427 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8428 * network status based on which carrier apps could apply actions accordingly,
8429 * enable/disable default url handler for example.
8430 *
8431 * @param subId the subscription ID that this action applies to.
8432 * @param report control start/stop reporting the default network status.
8433 * {@hide}
8434 */
8435 @Override
8436 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8437 enforceModifyPermission();
8438 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008439
8440 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008441 if (phone == null) {
8442 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8443 return;
8444 }
8445 try {
8446 phone.carrierActionReportDefaultNetworkStatus(report);
8447 } catch (Exception e) {
8448 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008449 } finally {
8450 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008451 }
8452 }
8453
8454 /**
fionaxud9622282017-07-17 17:51:30 -07008455 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8456 * @param subId the subscription ID that this action applies to.
8457 * {@hide}
8458 */
8459 @Override
8460 public void carrierActionResetAll(int subId) {
8461 enforceModifyPermission();
8462 final Phone phone = getPhone(subId);
8463 if (phone == null) {
8464 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8465 return;
8466 }
8467 try {
8468 phone.carrierActionResetAll();
8469 } catch (Exception e) {
8470 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8471 }
8472 }
8473
8474 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008475 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8476 * bug report is being generated.
8477 */
8478 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008479 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008480 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8481 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008482 writer.println("Permission Denial: can't dump Phone from pid="
8483 + Binder.getCallingPid()
8484 + ", uid=" + Binder.getCallingUid()
8485 + "without permission "
8486 + android.Manifest.permission.DUMP);
8487 return;
8488 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008489 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008490 }
Jack Yueb89b242016-06-22 13:27:47 -07008491
Brad Ebingerdac2f002018-04-03 15:17:52 -07008492 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008493 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8494 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8495 @NonNull String[] args) {
8496 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8497 this, in.getFileDescriptor(), out.getFileDescriptor(),
8498 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008499 }
8500
Jack Yueb89b242016-06-22 13:27:47 -07008501 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008502 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008503 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008504 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008505 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008506 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008507 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008508 */
8509 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008510 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008511 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008512 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8513 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8514 try {
8515 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008516 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008517 } catch (SecurityException se) {
8518 enforceModifyPermission();
8519 }
8520 } else {
8521 enforceModifyPermission();
8522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008523
8524 final long identity = Binder.clearCallingIdentity();
8525 try {
8526 Phone phone = getPhone(subId);
8527 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008528 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8529 phone.carrierActionSetMeteredApnsEnabled(enabled);
8530 } else {
Jack Yuabb10902022-07-31 00:43:21 -07008531 phone.getDataSettingsManager().setDataEnabled(
8532 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008534 }
8535 } finally {
8536 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008537 }
8538 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008539
8540 /**
8541 * Get Client request stats
8542 * @return List of Client Request Stats
8543 * @hide
8544 */
8545 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008546 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8547 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008549 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008550 return null;
8551 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008552 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008554 final long identity = Binder.clearCallingIdentity();
8555 try {
8556 if (phone != null) {
8557 return phone.getClientRequestStats();
8558 }
8559
8560 return null;
8561 } finally {
8562 Binder.restoreCallingIdentity(identity);
8563 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008564 }
8565
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008566 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008567 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008568 if (uid == Process.ROOT_UID && packageName == null) {
8569 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8570 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8571 // exception. ROOT_UID seems not to have a valid package name returned by
8572 // PackageManager, so just fake it here to avoid issues when running telephony shell
8573 // commands that plumb through the RIL as root, like so:
8574 // $ adb root
8575 // $ adb shell cmd phone ...
8576 packageName = "root";
8577 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008578 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008579 }
Jack Yueb4124c2017-02-16 15:32:43 -08008580
8581 /**
Grace Chen70990072017-03-24 17:21:30 -07008582 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008583 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008584 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008585 * @param state State of SIM (power down, power up, pass through)
8586 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8587 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8588 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008589 *
8590 **/
8591 @Override
Grace Chen70990072017-03-24 17:21:30 -07008592 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008593 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008594 Phone phone = PhoneFactory.getPhone(slotIndex);
8595
vagdeviaf9a5b92018-08-15 16:01:53 -07008596 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8597
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008598 final long identity = Binder.clearCallingIdentity();
8599 try {
8600 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008601 phone.setSimPowerState(state, null, workSource);
8602 }
8603 } finally {
8604 Binder.restoreCallingIdentity(identity);
8605 }
8606 }
8607
8608 /**
8609 * Set SIM card power state.
8610 *
8611 * @param slotIndex SIM slot id.
8612 * @param state State of SIM (power down, power up, pass through)
8613 * @param callback callback to trigger after success or failure
8614 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8615 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8616 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8617 *
8618 **/
8619 @Override
8620 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8621 IIntegerConsumer callback) {
8622 enforceModifyPermission();
8623 Phone phone = PhoneFactory.getPhone(slotIndex);
8624
8625 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8626
8627 final long identity = Binder.clearCallingIdentity();
8628 try {
8629 if (phone != null) {
8630 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8631 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008632 }
8633 } finally {
8634 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008635 }
8636 }
Shuo Qiandd210312017-04-12 22:11:33 +00008637
Tyler Gunn65d45c22017-06-05 11:22:26 -07008638 private boolean isUssdApiAllowed(int subId) {
8639 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008640 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008641 if (configManager == null) {
8642 return false;
8643 }
8644 PersistableBundle pb = configManager.getConfigForSubId(subId);
8645 if (pb == null) {
8646 return false;
8647 }
8648 return pb.getBoolean(
8649 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8650 }
8651
Shuo Qiandd210312017-04-12 22:11:33 +00008652 /**
8653 * Check if phone is in emergency callback mode
8654 * @return true if phone is in emergency callback mode
8655 * @param subId sub id
8656 */
goneil9c5f4872017-12-05 14:07:56 -08008657 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008658 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008659 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008660 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008661
8662 final long identity = Binder.clearCallingIdentity();
8663 try {
8664 if (phone != null) {
8665 return phone.isInEcm();
8666 } else {
8667 return false;
8668 }
8669 } finally {
8670 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008671 }
8672 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008673
8674 /**
8675 * Get the current signal strength information for the given subscription.
8676 * Because this information is not updated when the device is in a low power state
8677 * it should not be relied-upon to be current.
8678 * @param subId Subscription index
8679 * @return the most recent cached signal strength info from the modem
8680 */
8681 @Override
8682 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008683 final long identity = Binder.clearCallingIdentity();
8684 try {
8685 Phone p = getPhone(subId);
8686 if (p == null) {
8687 return null;
8688 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008690 return p.getSignalStrength();
8691 } finally {
8692 Binder.restoreCallingIdentity(identity);
8693 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008694 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008695
Pengquan Meng77b7f132018-08-22 14:49:57 -07008696 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008697 * Get the current modem radio state for the given slot.
8698 * @param slotIndex slot index.
8699 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008700 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008701 * @return the current radio power state from the modem
8702 */
8703 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008704 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008705 Phone phone = PhoneFactory.getPhone(slotIndex);
8706 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008707 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8708 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008709 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8710 }
8711
8712 final long identity = Binder.clearCallingIdentity();
8713 try {
8714 return phone.getRadioPowerState();
8715 } finally {
8716 Binder.restoreCallingIdentity(identity);
8717 }
8718 }
8719 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8720 }
8721
8722 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008723 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8724 *
8725 * <p>Requires one of the following permissions:
8726 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008727 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008728 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8729 * privileges.
8730 *
8731 * @param subId subscription id
8732 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8733 * {@code false}.
8734 */
8735 @Override
8736 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008737 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008738 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008739 try {
8740 mApp.enforceCallingOrSelfPermission(
8741 android.Manifest.permission.ACCESS_NETWORK_STATE,
8742 functionName);
8743 } catch (Exception e) {
8744 mApp.enforceCallingOrSelfPermission(
8745 permission.READ_BASIC_PHONE_STATE, functionName);
8746 }
Shuo Qian093013d2020-08-13 15:42:55 -07008747 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008748 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008749 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008750 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008751
Pengquan Menga1bb6272018-09-06 09:59:22 -07008752 boolean isEnabled = false;
8753 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008754 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008755 Phone phone = getPhone(subId);
8756 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008757 } finally {
8758 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008759 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008760 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008761 }
8762
8763
8764 /**
8765 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8766 *
8767 * <p> Requires permission:
8768 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8769 * privileges.
8770 *
8771 * @param subId subscription id
8772 * @param isEnabled {@code true} means enable, {@code false} means disable.
8773 */
8774 @Override
8775 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8777 mApp, subId, "setDataRoamingEnabled");
8778
Pengquan Menga1bb6272018-09-06 09:59:22 -07008779 final long identity = Binder.clearCallingIdentity();
8780 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008781 Phone phone = getPhone(subId);
8782 if (phone != null) {
8783 phone.setDataRoamingEnabled(isEnabled);
8784 }
8785 } finally {
8786 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008787 }
8788 }
8789
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008790 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008791 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008792 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008793 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008794 mApp, subId, "isManualNetworkSelectionAllowed");
8795
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008796 boolean isAllowed = true;
8797 final long identity = Binder.clearCallingIdentity();
8798 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008799 Phone phone = getPhone(subId);
8800 if (phone != null) {
8801 isAllowed = phone.isCspPlmnEnabled();
8802 }
8803 } finally {
8804 Binder.restoreCallingIdentity(identity);
8805 }
8806 return isAllowed;
8807 }
8808
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008809 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8810 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008811 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008812 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008813 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008814 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8815 if (phone == null) {
8816 return false;
8817 }
8818 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8819 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8820 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008821 }
8822
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008823 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008824 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008825 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008826 mApp.getSystemService(AppOpsManager.class)
8827 .checkPackage(Binder.getCallingUid(), callingPackage);
8828
Jordan Liu1e142fc2019-04-22 15:10:43 -07008829 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008830 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008831 try {
8832 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008833 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008834 } catch (SecurityException e) {
8835 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8836 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008837 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008838 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008839 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008840 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008841 }
sandeepjsb6c87872021-09-27 15:34:44 +00008842 // checking compatibility, if calling app's target SDK is T and beyond.
8843 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8844 Binder.getCallingUid())) {
8845 isIccIdAccessRestricted = true;
8846 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008847 final long identity = Binder.clearCallingIdentity();
8848 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008849 UiccController uiccController = UiccController.getInstance();
8850 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008851 if (hasReadPermission) {
8852 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008853 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008854
8855 // Remove private info if the caller doesn't have access
8856 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8857 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008858 //setting the value after compatibility check
8859 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008860 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8861 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008862 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008863 if (card == null) {
8864 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008865 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008866 continue;
8867 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008868 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8869 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008870 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008871 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008872 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008873 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8874 for (UiccPortInfo portInfo : portInfos) {
8875 UiccPort port = uiccController.getUiccPortForSlot(
8876 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8877 if (port == null) {
8878 // assume no access if port is null
8879 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8880 continue;
8881 }
8882 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8883 uiccPortInfos.add(portInfo);
8884 } else {
8885 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8886 }
8887 }
8888 filteredInfos.add(new UiccCardInfo(
8889 cardInfo.isEuicc(),
8890 cardInfo.getCardId(),
8891 null,
8892 cardInfo.getPhysicalSlotIndex(),
8893 cardInfo.isRemovable(),
8894 cardInfo.isMultipleEnabledProfilesSupported(),
8895 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008896 }
8897 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008898 } finally {
8899 Binder.restoreCallingIdentity(identity);
8900 }
8901 }
8902
sandeepjsb6c87872021-09-27 15:34:44 +00008903 /**
8904 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8905 * generally private and require carrier privileges to view.
8906 *
8907 * @hide
8908 */
8909 @NonNull
8910 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8911 List<UiccPortInfo> portinfo = new ArrayList<>();
8912 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8913 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8914 }
8915 return new UiccCardInfo(
8916 cardInfo.isEuicc(),
8917 cardInfo.getCardId(),
8918 null,
8919 cardInfo.getPhysicalSlotIndex(),
8920 cardInfo.isRemovable(),
8921 cardInfo.isMultipleEnabledProfilesSupported(),
8922 portinfo
8923 );
8924 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008925
sandeepjsb6c87872021-09-27 15:34:44 +00008926 /**
8927 * @hide
8928 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8929 * These values are generally private and require carrier privileges to view.
8930 */
8931 @NonNull
8932 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8933 return new UiccPortInfo(
8934 UiccPortInfo.ICCID_REDACTED,
8935 portInfo.getPortIndex(),
8936 portInfo.getLogicalSlotIndex(),
8937 portInfo.isActive()
8938 );
8939 }
8940 @Override
8941 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008942 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008943 mApp.getSystemService(AppOpsManager.class)
8944 .checkPackage(Binder.getCallingUid(), callingPackage);
8945
sandeepjsb6c87872021-09-27 15:34:44 +00008946 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008947
Aman Guptaf3c90b32022-03-17 04:54:16 +00008948 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8949 // we are reading iccId which is PII data.
8950 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008951
8952 // checking compatibility, if calling app's target SDK is T and beyond.
8953 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8954 Binder.getCallingUid())) {
8955 isLogicalSlotAccessRestricted = true;
8956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008957 final long identity = Binder.clearCallingIdentity();
8958 try {
8959 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008960 if (slots == null || slots.length == 0) {
8961 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008962 return null;
8963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008964 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8965 for (int i = 0; i < slots.length; i++) {
8966 UiccSlot slot = slots[i];
8967 if (slot == null) {
8968 continue;
8969 }
8970
Jordan Liu7be7e652019-05-06 18:55:02 +00008971 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008972 UiccCard card = slot.getUiccCard();
8973 if (card != null) {
8974 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008975 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008976 cardId = slot.getEid();
8977 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00008978 // If cardId is null, use iccId of default port as cardId.
8979 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07008980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008981 }
8982
Jordan Liu857451f2019-05-09 16:35:35 -07008983 if (cardId != null) {
8984 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8985 // if cardId is an EID, it's all digits so this is fine
8986 cardId = IccUtils.stripTrailingFs(cardId);
8987 }
8988
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008989 int cardState = 0;
8990 switch (slot.getCardState()) {
8991 case CARDSTATE_ABSENT:
8992 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8993 break;
8994 case CARDSTATE_PRESENT:
8995 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8996 break;
8997 case CARDSTATE_ERROR:
8998 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8999 break;
9000 case CARDSTATE_RESTRICTED:
9001 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9002 break;
9003 default:
9004 break;
9005
9006 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009007 List<UiccPortInfo> portInfos = new ArrayList<>();
9008 int[] portIndexes = slot.getPortList();
9009 for (int portIdx : portIndexes) {
9010 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009011 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009012 portInfos.add(new UiccPortInfo(iccId, portIdx,
9013 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009014 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009015 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009016 slot.isEuicc(),
9017 cardId,
9018 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009019 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009020 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009021 //setting the value after compatibility check
9022 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009023 }
9024 return infos;
9025 } finally {
9026 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009027 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009028 }
9029
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009030 /* Returns null if doesn't have read permission or carrier privilege access. */
9031 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9032 boolean hasReadPermission) {
9033 String iccId = slot.getIccId(portIndex);
9034 if (hasReadPermission) { // if has read permission
9035 return iccId;
9036 } else {
9037 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9038 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9039 // if no read permission, checking carrier privilege access
9040 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9041 return iccId;
9042 }
9043 }
9044 }
9045 // No read permission or carrier privilege access.
9046 return UiccPortInfo.ICCID_REDACTED;
9047 }
9048
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009049 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009050 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009051 public boolean switchSlots(int[] physicalSlots) {
9052 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009053
9054 final long identity = Binder.clearCallingIdentity();
9055 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009056 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9057 for (int i = 0; i < physicalSlots.length; i++) {
9058 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9059 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9060 physicalSlots[i], i));
9061 }
9062 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009063 } finally {
9064 Binder.restoreCallingIdentity(identity);
9065 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009066 }
Jack Yu4c988042018-02-27 15:30:01 -08009067
9068 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009069 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9070 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9071 enforceModifyPermission();
9072
9073 final long identity = Binder.clearCallingIdentity();
9074 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009075 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009076 } finally {
9077 Binder.restoreCallingIdentity(identity);
9078 }
9079 }
9080
9081 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009082 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009083 final long identity = Binder.clearCallingIdentity();
9084 try {
9085 return UiccController.getInstance().getCardIdForDefaultEuicc();
9086 } finally {
9087 Binder.restoreCallingIdentity(identity);
9088 }
9089 }
9090
Pengquan Meng85728fb2018-03-12 16:31:21 -07009091 /**
goneil47ffb6e2018-04-06 15:40:58 -07009092 * A test API to reload the UICC profile.
9093 *
9094 * <p>Requires that the calling app has permission
9095 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9096 * @hide
9097 */
9098 @Override
9099 public void refreshUiccProfile(int subId) {
9100 enforceModifyPermission();
9101
9102 final long identity = Binder.clearCallingIdentity();
9103 try {
9104 Phone phone = getPhone(subId);
9105 if (phone == null) {
9106 return;
9107 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009108 UiccPort uiccPort = phone.getUiccPort();
9109 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009110 return;
9111 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009112 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009113 if (uiccProfile == null) {
9114 return;
9115 }
9116 uiccProfile.refresh();
9117 } finally {
9118 Binder.restoreCallingIdentity(identity);
9119 }
9120 }
9121
9122 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009123 * Returns false if the mobile data is disabled by default, otherwise return true.
9124 */
9125 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009126 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009127 }
9128
9129 /**
9130 * Returns true if the data roaming is enabled by default, i.e the system property
9131 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9132 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9133 */
9134 private boolean getDefaultDataRoamingEnabled(int subId) {
9135 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009136 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009137 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009138 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9139 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9140 return isDataRoamingEnabled;
9141 }
9142
9143 /**
9144 * Returns the default network type for the given {@code subId}, if the default network type is
9145 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9146 */
9147 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009148 List<Integer> list = TelephonyProperties.default_network();
Jack Yudf049d72022-12-02 22:48:35 -08009149 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009150 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9151 return list.get(phoneId);
9152 }
9153 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009154 }
fionaxua13278b2018-03-21 00:08:13 -07009155
9156 @Override
9157 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009158 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009159 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009160
9161 final long identity = Binder.clearCallingIdentity();
9162 try {
9163 final Phone phone = getPhone(subId);
9164 if (phone == null) {
9165 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9166 return;
9167 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009168 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9169 if (cpt != null) {
9170 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9171 }
9172 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009173 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9174 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009175 if (carrierPrivilegeRules == null) {
9176 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9177 } else {
9178 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009180 } finally {
9181 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009182 }
fionaxua13278b2018-03-21 00:08:13 -07009183 }
9184
9185 @Override
Benedict Wong45280102023-02-03 23:30:57 +00009186 public void setCarrierServicePackageOverride(
9187 int subId, String carrierServicePackage, String callingPackage) {
9188 TelephonyPermissions.enforceShellOnly(
9189 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9190
9191 // Verify that the callingPackage belongs to the calling UID
9192 mApp.getSystemService(AppOpsManager.class)
9193 .checkPackage(Binder.getCallingUid(), callingPackage);
9194
9195 final long identity = Binder.clearCallingIdentity();
9196 try {
9197 final Phone phone = getPhone(subId);
9198 if (phone == null || phone.getSubId() != subId) {
9199 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9200 throw new IllegalArgumentException("No phone for subid");
9201 }
9202 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9203 if (cpt == null) {
9204 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9205 throw new IllegalStateException("No CPT for phone");
9206 }
9207 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9208 } finally {
9209 Binder.restoreCallingIdentity(identity);
9210 }
9211 }
9212
9213 @Override
fionaxua13278b2018-03-21 00:08:13 -07009214 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009215 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009216
9217 final long identity = Binder.clearCallingIdentity();
9218 try {
9219 final Phone phone = getPhone(subId);
9220 if (phone == null) {
9221 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9222 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9223 }
9224 return phone.getCarrierIdListVersion();
9225 } finally {
9226 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009227 }
fionaxua13278b2018-03-21 00:08:13 -07009228 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009229
9230 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009231 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9232 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009233 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009234 mApp, subId, callingPackage, callingFeatureId,
9235 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009236 return -1;
9237 }
9238
9239 final long identity = Binder.clearCallingIdentity();
9240 try {
9241 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9242 } finally {
9243 Binder.restoreCallingIdentity(identity);
9244 }
9245 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009246
9247 @Override
9248 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009249 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009250 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009251 mApp, subId, "getCdmaRoamingMode");
9252
9253 final long identity = Binder.clearCallingIdentity();
9254 try {
9255 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9256 } finally {
9257 Binder.restoreCallingIdentity(identity);
9258 }
9259 }
9260
9261 @Override
9262 public boolean setCdmaRoamingMode(int subId, int mode) {
9263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9264 mApp, subId, "setCdmaRoamingMode");
9265
9266 final long identity = Binder.clearCallingIdentity();
9267 try {
9268 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9269 } finally {
9270 Binder.restoreCallingIdentity(identity);
9271 }
9272 }
9273
9274 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009275 public int getCdmaSubscriptionMode(int subId) {
9276 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009277 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009278 mApp, subId, "getCdmaSubscriptionMode");
9279
9280 final long identity = Binder.clearCallingIdentity();
9281 try {
9282 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9283 } finally {
9284 Binder.restoreCallingIdentity(identity);
9285 }
9286 }
9287
9288 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009289 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9291 mApp, subId, "setCdmaSubscriptionMode");
9292
9293 final long identity = Binder.clearCallingIdentity();
9294 try {
9295 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9296 } finally {
9297 Binder.restoreCallingIdentity(identity);
9298 }
9299 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009300
sqianc5eccab2018-10-19 18:46:41 -07009301 @Override
sqian8c685422019-02-22 15:55:18 -08009302 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009303 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009304 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009305 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9306 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009307 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9308 }
9309 final long identity = Binder.clearCallingIdentity();
9310 try {
sqian854d44b2018-12-12 16:48:18 -08009311 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9312 for (Phone phone: PhoneFactory.getPhones()) {
9313 if (phone.getEmergencyNumberTracker() != null
9314 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9315 emergencyNumberListInternal.put(
9316 phone.getSubId(),
9317 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9318 }
sqian11b7a0e2018-12-05 18:48:28 -08009319 }
sqian854d44b2018-12-12 16:48:18 -08009320 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009321 } finally {
9322 Binder.restoreCallingIdentity(identity);
9323 }
sqianc5eccab2018-10-19 18:46:41 -07009324 }
9325
9326 @Override
sqian8c685422019-02-22 15:55:18 -08009327 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009328 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009329 if (!exactMatch) {
9330 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009331 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009332 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009333 }
9334 final long identity = Binder.clearCallingIdentity();
9335 try {
sqian854d44b2018-12-12 16:48:18 -08009336 for (Phone phone: PhoneFactory.getPhones()) {
9337 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009338 && phone.getEmergencyNumberTracker()
9339 .isEmergencyNumber(number, exactMatch)) {
9340 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009341 }
sqian11b7a0e2018-12-05 18:48:28 -08009342 }
9343 return false;
9344 } finally {
9345 Binder.restoreCallingIdentity(identity);
9346 }
9347 }
9348
sqianf4ca7ed2019-01-15 18:32:07 -08009349 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009350 * Start emergency callback mode for GsmCdmaPhone for testing.
9351 */
9352 @Override
9353 public void startEmergencyCallbackMode() {
9354 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9355 "startEmergencyCallbackMode");
9356 enforceModifyPermission();
9357 final long identity = Binder.clearCallingIdentity();
9358 try {
9359 for (Phone phone : PhoneFactory.getPhones()) {
9360 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9361 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9362 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9363 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9364 gsmCdmaPhone.obtainMessage(
9365 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9366 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9367 }
9368 }
9369 } finally {
9370 Binder.restoreCallingIdentity(identity);
9371 }
9372 }
9373
9374 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009375 * Update emergency number list for test mode.
9376 */
9377 @Override
9378 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9379 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9380 "updateEmergencyNumberListTestMode");
9381
9382 final long identity = Binder.clearCallingIdentity();
9383 try {
9384 for (Phone phone: PhoneFactory.getPhones()) {
9385 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9386 if (tracker != null) {
9387 tracker.executeEmergencyNumberTestModeCommand(action, num);
9388 }
9389 }
9390 } finally {
9391 Binder.restoreCallingIdentity(identity);
9392 }
9393 }
9394
9395 /**
9396 * Get the full emergency number list for test mode.
9397 */
9398 @Override
9399 public List<String> getEmergencyNumberListTestMode() {
9400 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9401 "getEmergencyNumberListTestMode");
9402
9403 final long identity = Binder.clearCallingIdentity();
9404 try {
9405 Set<String> emergencyNumbers = new HashSet<>();
9406 for (Phone phone: PhoneFactory.getPhones()) {
9407 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9408 if (tracker != null) {
9409 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9410 emergencyNumbers.add(num.getNumber());
9411 }
9412 }
9413 }
9414 return new ArrayList<>(emergencyNumbers);
9415 } finally {
9416 Binder.restoreCallingIdentity(identity);
9417 }
9418 }
9419
chen xud6b45bd2018-10-30 22:27:10 -07009420 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009421 public int getEmergencyNumberDbVersion(int subId) {
9422 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9423
9424 final long identity = Binder.clearCallingIdentity();
9425 try {
9426 final Phone phone = getPhone(subId);
9427 if (phone == null) {
9428 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9429 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9430 }
9431 return phone.getEmergencyNumberDbVersion();
9432 } finally {
9433 Binder.restoreCallingIdentity(identity);
9434 }
9435 }
9436
9437 @Override
9438 public void notifyOtaEmergencyNumberDbInstalled() {
9439 enforceModifyPermission();
9440
9441 final long identity = Binder.clearCallingIdentity();
9442 try {
9443 for (Phone phone: PhoneFactory.getPhones()) {
9444 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9445 if (tracker != null) {
9446 tracker.updateOtaEmergencyNumberDatabase();
9447 }
9448 }
9449 } finally {
9450 Binder.restoreCallingIdentity(identity);
9451 }
9452 }
9453
9454 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009455 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009456 enforceActiveEmergencySessionPermission();
9457
9458 final long identity = Binder.clearCallingIdentity();
9459 try {
9460 for (Phone phone: PhoneFactory.getPhones()) {
9461 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9462 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009463 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9464 }
9465 }
9466 } finally {
9467 Binder.restoreCallingIdentity(identity);
9468 }
9469 }
9470
9471 @Override
9472 public void resetOtaEmergencyNumberDbFilePath() {
9473 enforceActiveEmergencySessionPermission();
9474
9475 final long identity = Binder.clearCallingIdentity();
9476 try {
9477 for (Phone phone: PhoneFactory.getPhones()) {
9478 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9479 if (tracker != null) {
9480 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009481 }
9482 }
9483 } finally {
9484 Binder.restoreCallingIdentity(identity);
9485 }
9486 }
9487
9488 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009489 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9490 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9491 Phone phone = getPhone(subId);
9492 if (phone == null) {
9493 return null;
9494 }
9495 final long identity = Binder.clearCallingIdentity();
9496 try {
9497 UiccProfile profile = UiccController.getInstance()
9498 .getUiccProfileForPhone(phone.getPhoneId());
9499 if (profile != null) {
9500 return profile.getCertsFromCarrierPrivilegeAccessRules();
9501 }
9502 } finally {
9503 Binder.restoreCallingIdentity(identity);
9504 }
9505 return null;
9506 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009507
9508 /**
9509 * Enable or disable a modem stack.
9510 */
9511 @Override
9512 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9513 enforceModifyPermission();
9514
9515 final long identity = Binder.clearCallingIdentity();
9516 try {
9517 Phone phone = PhoneFactory.getPhone(slotIndex);
9518 if (phone == null) {
9519 return false;
9520 } else {
9521 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9522 }
9523 } finally {
9524 Binder.restoreCallingIdentity(identity);
9525 }
9526 }
Michelecea4cf22018-12-21 15:00:11 -08009527
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009528 /**
9529 * Whether a modem stack is enabled or not.
9530 */
9531 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009532 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9533 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009534 Phone phone = PhoneFactory.getPhone(slotIndex);
9535 if (phone == null) return false;
9536
9537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009538 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9539 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009540 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9541 }
9542
9543 final long identity = Binder.clearCallingIdentity();
9544 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009545 try {
9546 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9547 } catch (NoSuchElementException ex) {
9548 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9549 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009550 } finally {
9551 Binder.restoreCallingIdentity(identity);
9552 }
9553 }
9554
Michelecea4cf22018-12-21 15:00:11 -08009555 @Override
Michele0ea7d782019-03-19 14:58:42 -07009556 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009557 enforceModifyPermission();
9558
9559 final long identity = Binder.clearCallingIdentity();
9560 try {
9561 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009562 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009563 .commit();
9564 } finally {
9565 Binder.restoreCallingIdentity(identity);
9566 }
9567 }
9568
9569 @Override
Michele0ea7d782019-03-19 14:58:42 -07009570 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009571 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009572 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009573 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9574 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009575 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009576 }
Michelecea4cf22018-12-21 15:00:11 -08009577
9578 final long identity = Binder.clearCallingIdentity();
9579 try {
Michele0ea7d782019-03-19 14:58:42 -07009580 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009581 } finally {
9582 Binder.restoreCallingIdentity(identity);
9583 }
9584 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009585
Michele0ea7d782019-03-19 14:58:42 -07009586 @TelephonyManager.IsMultiSimSupportedResult
9587 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009588 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9589 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9590 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009591 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9592 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009593 }
9594 // Check if the hardware supports multisim functionality. If usage of multisim is not
9595 // supported by the modem, indicate that it is restricted.
9596 PhoneCapability staticCapability =
9597 mPhoneConfigurationManager.getStaticPhoneCapability();
9598 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009599 loge("isMultiSimSupportedInternal: no static configuration available");
9600 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009601 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009602 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009603 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9604 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009605 }
9606 // Check if support of multiple SIMs is restricted by carrier
9607 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009608 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009609 }
9610
Michele0ea7d782019-03-19 14:58:42 -07009611 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009612 }
9613
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009614 /**
9615 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009616 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9617 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9618 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009619 * @param numOfSims number of active sims we want to switch to
9620 */
9621 @Override
9622 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009623 if (numOfSims == 1) {
9624 enforceModifyPermission();
9625 } else {
9626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9627 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9628 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009629 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009630
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009631 try {
Michele30b57b22019-03-01 12:01:14 -08009632 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009633 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009634 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9635 return;
9636 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009637 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9638 } finally {
9639 Binder.restoreCallingIdentity(identity);
9640 }
9641 }
9642
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009643 @Override
9644 public boolean isApplicationOnUicc(int subId, int appType) {
9645 enforceReadPrivilegedPermission("isApplicationOnUicc");
9646 Phone phone = getPhone(subId);
9647 if (phone == null) {
9648 return false;
9649 }
9650 final long identity = Binder.clearCallingIdentity();
9651 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009652 UiccPort uiccPort = phone.getUiccPort();
9653 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009654 return false;
9655 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009656 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009657 if (uiccProfile == null) {
9658 return false;
9659 }
9660 if (TelephonyManager.APPTYPE_SIM <= appType
9661 && appType <= TelephonyManager.APPTYPE_ISIM) {
9662 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9663 }
9664 return false;
9665 } finally {
9666 Binder.restoreCallingIdentity(identity);
9667 }
9668 }
9669
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009670 /**
chen xub4baa772019-04-03 10:23:41 -07009671 * Get whether making changes to modem configurations will trigger reboot.
9672 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009673 */
9674 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009675 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9676 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009677 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009678 mApp, subId, callingPackage, callingFeatureId,
9679 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009680 return false;
9681 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009682 final long identity = Binder.clearCallingIdentity();
9683 try {
9684 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9685 } finally {
9686 Binder.restoreCallingIdentity(identity);
9687 }
9688 }
9689
Nathan Harold29f5f052019-02-15 13:41:57 -08009690 private void updateModemStateMetrics() {
9691 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9692 // TODO: check the state for each modem if the api is ready.
9693 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9694 }
9695
Pengquan Meng3889a572019-01-23 11:16:29 -08009696 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009697 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009698 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009699 // Verify that the callingPackage belongs to the calling UID
9700 mApp.getSystemService(AppOpsManager.class)
9701 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009702 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009703 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009704 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009705 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9706 if (slotInfos != null) {
9707 for (int i = 0; i < slotInfos.length; i++) {
9708 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9709 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9710 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9711 portInfo.getLogicalSlotIndex()));
9712 }
9713 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009714 }
9715 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009716 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009717 } finally {
9718 Binder.restoreCallingIdentity(identity);
9719 }
9720 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009721
9722 /**
9723 * Get the IRadio HAL Version
9724 */
9725 @Override
9726 public int getRadioHalVersion() {
9727 Phone phone = getDefaultPhone();
9728 if (phone == null) return -1;
9729 HalVersion hv = phone.getHalVersion();
9730 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9731 return hv.major * 100 + hv.minor;
9732 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009733
9734 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009735 * Get the current calling package name.
9736 * @return the current calling package name
9737 */
9738 @Override
9739 public String getCurrentPackageName() {
9740 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9741 }
9742
9743 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009744 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9745 * corresponding network requests on a subId.
9746 *
9747 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009748 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009749 * 2) APN is un-metered for this subscription, or
9750 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009751 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009752 *
9753 * @return whether data is allowed for a apn type.
9754 *
9755 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009756 */
9757 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009758 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009759 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9760 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009761
9762 // Now that all security checks passes, perform the operation as ourselves.
9763 final long identity = Binder.clearCallingIdentity();
9764 try {
9765 Phone phone = getPhone(subId);
9766 if (phone == null) return false;
9767
Jack Yu27422a52022-03-21 10:38:05 -07009768 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009769 boolean isDataEnabled;
Jack Yuabb10902022-07-31 00:43:21 -07009770 isMetered = phone.getDataNetworkController().getDataConfigManager()
9771 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9772 phone.getServiceState().getDataRoaming());
9773 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009774 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009775 } finally {
9776 Binder.restoreCallingIdentity(identity);
9777 }
9778 }
9779
9780 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009781 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009782 enforceReadPrivilegedPermission("isApnMetered");
9783
9784 // Now that all security checks passes, perform the operation as ourselves.
9785 final long identity = Binder.clearCallingIdentity();
9786 try {
9787 Phone phone = getPhone(subId);
9788 if (phone == null) return true; // By default return true.
Jack Yuabb10902022-07-31 00:43:21 -07009789 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9790 DataUtils.apnTypeToNetworkCapability(apnType),
9791 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009792 } finally {
9793 Binder.restoreCallingIdentity(identity);
9794 }
9795 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009796
9797 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009798 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9799 int subscriptionId, IBooleanConsumer resultCallback) {
9800 enforceModifyPermission();
9801 long token = Binder.clearCallingIdentity();
9802 try {
9803 Phone phone = getPhone(subscriptionId);
9804 if (phone == null) {
9805 try {
9806 if (resultCallback != null) {
9807 resultCallback.accept(false);
9808 }
9809 } catch (RemoteException e) {
9810 // ignore
9811 }
9812 return;
9813 }
9814 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9815 Pair.create(specifiers, (x) -> {
9816 try {
9817 if (resultCallback != null) {
9818 resultCallback.accept(x);
9819 }
9820 } catch (RemoteException e) {
9821 // ignore
9822 }
9823 });
9824 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9825 } finally {
9826 Binder.restoreCallingIdentity(token);
9827 }
9828 }
9829
9830 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009831 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9832 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009833 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009834 mApp, subId, "getSystemSelectionChannels");
9835 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9836 final long identity = Binder.clearCallingIdentity();
9837 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009838 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9839 if (result instanceof IllegalStateException) {
9840 throw (IllegalStateException) result;
9841 }
9842 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009843 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9844 return specifiers;
9845 } finally {
9846 Binder.restoreCallingIdentity(identity);
9847 }
9848 }
9849
9850 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009851 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009852 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009853 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009854 }
9855
9856 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009857 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9858 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009859 if (callingPackage == null) {
9860 callingPackage = getCurrentPackageName();
9861 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009862 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9863 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009864 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9865 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009866 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9867 }
9868 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9869 Intent intent = new Intent();
9870 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9871 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9872 // Bring up choose default SMS subscription dialog right now
9873 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9874 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9875 mApp.startActivity(intent);
9876 }
chen xud5ca2d52019-05-28 15:20:57 -07009877
9878 @Override
9879 public String getMmsUAProfUrl(int subId) {
9880 //TODO investigate if this API should require proper permission check in R b/133791609
9881 final long identity = Binder.clearCallingIdentity();
9882 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009883 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9884 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9885 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9886 return carrierUAProfUrl;
9887 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009888 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9889 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009890 } finally {
9891 Binder.restoreCallingIdentity(identity);
9892 }
9893 }
9894
9895 @Override
9896 public String getMmsUserAgent(int subId) {
9897 //TODO investigate if this API should require proper permission check in R b/133791609
9898 final long identity = Binder.clearCallingIdentity();
9899 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009900 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9901 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9902 if (!TextUtils.isEmpty(carrierUserAgent)) {
9903 return carrierUserAgent;
9904 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009905 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9906 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009907 } finally {
9908 Binder.restoreCallingIdentity(identity);
9909 }
9910 }
Jack Yub07d4972019-05-28 16:12:25 -07009911
9912 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009913 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9914 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009915
Jack Yub07d4972019-05-28 16:12:25 -07009916 final long identity = Binder.clearCallingIdentity();
9917 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009918 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009919 if (phone == null) return false;
9920
Ling Ma58448e42022-09-16 15:22:36 -07009921 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -07009922 } finally {
9923 Binder.restoreCallingIdentity(identity);
9924 }
9925 }
9926
9927 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009928 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009929 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009930 enforceModifyPermission();
9931
changbettyd5c246e2019-12-24 15:40:37 +08009932 final long identity = Binder.clearCallingIdentity();
9933 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009934 Phone phone = getPhone(subscriptionId);
9935 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009936
Ling Ma58448e42022-09-16 15:22:36 -07009937 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +08009938 } finally {
9939 Binder.restoreCallingIdentity(identity);
9940 }
9941 }
9942
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009943 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009944 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009945 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9946 * otherwise.
9947 */
9948 @Override
9949 public void setCepEnabled(boolean isCepEnabled) {
9950 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9951
9952 final long identity = Binder.clearCallingIdentity();
9953 try {
9954 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9955 for (Phone phone : PhoneFactory.getPhones()) {
9956 Phone defaultPhone = phone.getImsPhone();
9957 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9958 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9959 ImsPhoneCallTracker imsPhoneCallTracker =
9960 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9961 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9962 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9963 + imsPhone.getMsisdn());
9964 }
9965 }
9966 } finally {
9967 Binder.restoreCallingIdentity(identity);
9968 }
9969 }
allenwtsu46dcc572020-01-08 18:24:03 +08009970
9971 /**
9972 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9973 *
9974 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9975 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9976 * before being read.
9977 */
9978 @Override
9979 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9980 isCompressed) {
9981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9982 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009983 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9984 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9985 }
9986 if (!isImsAvailableOnDevice()) {
9987 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9988 "IMS not available on device.");
9989 }
9990
9991 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009992 try {
Hui Wang761a6682020-10-31 05:12:53 +00009993 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9994 } finally {
9995 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009996 }
9997 }
zoey chene02881a2019-12-30 16:11:23 +08009998
9999 @Override
10000 public boolean isIccLockEnabled(int subId) {
10001 enforceReadPrivilegedPermission("isIccLockEnabled");
10002
10003 // Now that all security checks passes, perform the operation as ourselves.
10004 final long identity = Binder.clearCallingIdentity();
10005 try {
10006 Phone phone = getPhone(subId);
10007 if (phone != null && phone.getIccCard() != null) {
10008 return phone.getIccCard().getIccLockEnabled();
10009 } else {
10010 return false;
10011 }
10012 } finally {
10013 Binder.restoreCallingIdentity(identity);
10014 }
10015 }
10016
10017 /**
10018 * Set the ICC pin lock enabled or disabled.
10019 *
10020 * @return an integer representing the status of IccLock enabled or disabled in the following
10021 * three cases:
10022 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10023 * successfully.
10024 * - Positive number and zero for remaining password attempts.
10025 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10026 *
10027 */
10028 @Override
10029 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10030 enforceModifyPermission();
10031
10032 Phone phone = getPhone(subId);
10033 if (phone == null) {
10034 return 0;
10035 }
10036 // Now that all security checks passes, perform the operation as ourselves.
10037 final long identity = Binder.clearCallingIdentity();
10038 try {
10039 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10040 new Pair<Boolean, String>(enabled, password), phone, null);
10041 return attemptsRemaining;
10042
10043 } catch (Exception e) {
10044 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10045 } finally {
10046 Binder.restoreCallingIdentity(identity);
10047 }
10048 return 0;
10049 }
10050
10051 /**
10052 * Change the ICC password used in ICC pin lock.
10053 *
10054 * @return an integer representing the status of IccLock changed in the following three cases:
10055 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10056 * - Positive number and zero for remaining password attempts.
10057 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10058 *
10059 */
10060 @Override
10061 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10062 enforceModifyPermission();
10063
10064 Phone phone = getPhone(subId);
10065 if (phone == null) {
10066 return 0;
10067 }
10068 // Now that all security checks passes, perform the operation as ourselves.
10069 final long identity = Binder.clearCallingIdentity();
10070 try {
10071 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10072 new Pair<String, String>(oldPassword, newPassword), phone, null);
10073 return attemptsRemaining;
10074
10075 } catch (Exception e) {
10076 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10077 } finally {
10078 Binder.restoreCallingIdentity(identity);
10079 }
10080 return 0;
10081 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010082
10083 /**
10084 * Request for receiving user activity notification
10085 */
10086 @Override
10087 public void requestUserActivityNotification() {
10088 if (!mNotifyUserActivity.get()
10089 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10090 mNotifyUserActivity.set(true);
10091 }
10092 }
10093
10094 /**
10095 * Called when userActivity is signalled in the power manager.
10096 * This is safe to call from any thread, with any window manager locks held or not.
10097 */
10098 @Override
10099 public void userActivity() {
10100 // ***************************************
10101 // * Inherited from PhoneWindowManager *
10102 // ***************************************
10103 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10104 // WITH ITS LOCKS HELD.
10105 //
10106 // This code must be VERY careful about the locks
10107 // it acquires.
10108 // In fact, the current code acquires way too many,
10109 // and probably has lurking deadlocks.
10110
10111 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10112 throw new SecurityException("Only the OS may call notifyUserActivity()");
10113 }
10114
10115 if (mNotifyUserActivity.getAndSet(false)) {
10116 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10117 USER_ACTIVITY_NOTIFICATION_DELAY);
10118 }
10119 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010120
10121 @Override
10122 public boolean canConnectTo5GInDsdsMode() {
10123 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10124 }
Jack Yud10cdd42020-09-28 20:28:01 -070010125
10126 @Override
10127 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10128 String callingFeatureId) {
10129 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10130 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10131 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10132 }
10133
10134 Phone phone = getPhone(subId);
10135 if (phone == null) {
10136 throw new RuntimeException("phone is not available");
10137 }
10138 // Now that all security checks passes, perform the operation as ourselves.
10139 final long identity = Binder.clearCallingIdentity();
10140 try {
10141 return phone.getEquivalentHomePlmns();
10142 } finally {
10143 Binder.restoreCallingIdentity(identity);
10144 }
10145 }
Daniel Bright59e67312020-11-13 11:49:37 -080010146
10147 @Override
10148 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010149 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10150 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010151 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010152 if (radioInterfaceCapabilities == null) {
10153 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010154 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010155 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010156 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010157
Hui Wang641e81c2020-10-12 12:14:23 -070010158 @Override
10159 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10160 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010161 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10162 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10163 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10164 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10165 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010166 if (DBG) {
10167 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10168 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10169 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10170 }
10171
10172 if (!SubscriptionManager.isValidSubscriptionId(subId)
10173 || appType < TelephonyManager.APPTYPE_UNKNOWN
10174 || appType > TelephonyManager.APPTYPE_ISIM
10175 || nafUrl == null || securityProtocol == null || callback == null) {
10176 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10177 if (callback != null) {
10178 try {
10179 callback.onAuthenticationFailure(
10180 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10181 } catch (RemoteException exception) {
10182 log("Fail to notify onAuthenticationFailure due to " + exception);
10183 }
10184 return;
10185 }
10186 }
10187
10188 final long token = Binder.clearCallingIdentity();
10189 try {
10190 getGbaManager(subId).bootstrapAuthenticationRequest(
10191 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10192 forceBootStrapping, callback));
10193 } finally {
10194 Binder.restoreCallingIdentity(token);
10195 }
10196 }
10197
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010198 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010199 * Attempts to set the radio power state for all phones for thermal reason.
10200 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010201 * requested radio power state will actually be set. See {@link
10202 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10203 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010204 * @param enable {@code true} if trying to turn radio on.
10205 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10206 * false}.
10207 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010208 private boolean setRadioPowerForThermal(boolean enable) {
10209 boolean isPhoneAvailable = false;
10210 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10211 Phone phone = PhoneFactory.getPhone(i);
10212 if (phone != null) {
10213 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10214 isPhoneAvailable = true;
10215 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010216 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010217
10218 // return true if successfully informed the phone object about the thermal radio power
10219 // request.
10220 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010221 }
10222
10223 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010224 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010225 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10226 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10227 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10228 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10229 throw new IllegalArgumentException("modem does not support data throttling");
10230 }
10231
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010232 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10233 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010234 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010235 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10236 }
10237
Sarah Chinecc78c42022-03-31 21:16:48 -070010238 setDataEnabledForReason(
10239 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010240
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010241 if (isDataThrottlingSupported) {
10242 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010243 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010244 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10245 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10246 } else if (thermalMitigationResult
10247 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010248 log("Modem likely does not support data throttling on secondary carrier. Data " +
10249 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10250 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010251 }
10252 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010253 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010254
10255 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010256 }
10257
Jack Nudelman644b91a2021-03-12 14:09:48 -080010258 private static List<String> getThermalMitigationAllowlist(Context context) {
10259 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10260 for (String pckg : context.getResources()
10261 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10262 sThermalMitigationAllowlistedPackages.add(pckg);
10263 }
10264 }
10265
10266 return sThermalMitigationAllowlistedPackages;
10267 }
10268
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010269 private boolean isAnyPhoneInEmergencyState() {
10270 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10271 if (tm.isInEmergencyCall()) {
10272 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10273 return true;
10274 }
10275 for (Phone phone : PhoneFactory.getPhones()) {
10276 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10277 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10278 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10279 + phone.isInEcm());
10280 return true;
10281 }
10282 }
10283
10284 return false;
10285 }
10286
Jack Nudelman644b91a2021-03-12 14:09:48 -080010287 /**
10288 * Used by shell commands to add an authorized package name for thermal mitigation.
10289 * @param packageName name of package to be allowlisted
10290 * @param context
10291 */
10292 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10293 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10294 sThermalMitigationAllowlistedPackages.add(packageName);
10295 }
10296
10297 /**
10298 * Used by shell commands to remove an authorized package name for thermal mitigation.
10299 * @param packageName name of package to remove from allowlist
10300 * @param context
10301 */
10302 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10303 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10304 sThermalMitigationAllowlistedPackages.remove(packageName);
10305 }
10306
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010307 /**
10308 * Thermal mitigation request to control functionalities at modem.
10309 *
10310 * @param subId the id of the subscription.
10311 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010312 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010313 *
10314 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10315 */
10316 @Override
10317 @ThermalMitigationResult
10318 public int sendThermalMitigationRequest(
10319 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010320 ThermalMitigationRequest thermalMitigationRequest,
10321 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010322 enforceModifyPermission();
10323
Jack Nudelman644b91a2021-03-12 14:09:48 -080010324 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10325 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10326 .contains(callingPackage)) {
10327 throw new SecurityException("Calling package must be configured in the device config. "
10328 + "calling package: " + callingPackage);
10329 }
10330
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010331 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10332 final long identity = Binder.clearCallingIdentity();
10333
10334 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10335 try {
10336 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10337 switch (thermalMitigationAction) {
10338 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10339 thermalMitigationResult =
10340 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010341 thermalMitigationRequest.getDataThrottlingRequest(),
10342 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010343 break;
10344 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10345 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10346 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10347 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10348 }
10349
10350 // Ensure that radio is on. If not able to power on due to phone being
10351 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010352 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010353 thermalMitigationResult =
10354 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10355 break;
10356 }
10357
10358 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010359 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010360 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10361 break;
10362 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10363 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10364 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10365 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10366 }
10367
10368 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10369 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010370 Phone phone = getPhone(subId);
10371 if (phone == null) {
10372 thermalMitigationResult =
10373 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10374 break;
10375 }
10376
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010377 TelephonyConnectionService service =
10378 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010379 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010380 Log.e(LOG_TAG, "An emergency call is pending");
10381 thermalMitigationResult =
10382 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10383 break;
10384 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010385 thermalMitigationResult =
10386 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10387 break;
10388 }
10389 } else {
10390 thermalMitigationResult =
10391 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10392 break;
10393 }
10394
10395 // Turn radio off. If not able to power off due to phone being unavailable,
10396 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010397 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010398 thermalMitigationResult =
10399 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10400 break;
10401 }
10402 thermalMitigationResult =
10403 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10404 break;
10405 default:
10406 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10407 + "not exist. Requested action: " + thermalMitigationAction);
10408 }
10409 } catch (IllegalArgumentException e) {
10410 throw e;
10411 } catch (Exception e) {
10412 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10413 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10414 } finally {
10415 Binder.restoreCallingIdentity(identity);
10416 }
10417
10418 if (DBG) {
10419 log("thermalMitigationRequest returning with thermalMitigationResult: "
10420 + thermalMitigationResult);
10421 }
10422
10423 return thermalMitigationResult;
10424 }
Hui Wang641e81c2020-10-12 12:14:23 -070010425
10426 /**
10427 * Set the GbaService Package Name that Telephony will bind to.
10428 *
10429 * @param subId The sim that the GbaService is associated with.
10430 * @param packageName The name of the package to be replaced with.
10431 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10432 */
10433 @Override
10434 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10435 enforceModifyPermission();
10436
10437 final long identity = Binder.clearCallingIdentity();
10438 try {
10439 return getGbaManager(subId).overrideServicePackage(packageName);
10440 } finally {
10441 Binder.restoreCallingIdentity(identity);
10442 }
10443 }
10444
10445 /**
10446 * Return the package name of the currently bound GbaService.
10447 *
10448 * @param subId The sim that the GbaService is associated with.
10449 * @return the package name of the GbaService configuration, null if GBA is not supported.
10450 */
10451 @Override
10452 public String getBoundGbaService(int subId) {
10453 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10454
10455 final long identity = Binder.clearCallingIdentity();
10456 try {
10457 return getGbaManager(subId).getServicePackage();
10458 } finally {
10459 Binder.restoreCallingIdentity(identity);
10460 }
10461 }
10462
10463 /**
10464 * Set the release time for telephony to unbind GbaService.
10465 *
10466 * @param subId The sim that the GbaService is associated with.
10467 * @param interval The release time to unbind GbaService by millisecond.
10468 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10469 */
10470 @Override
10471 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10472 enforceModifyPermission();
10473
10474 final long identity = Binder.clearCallingIdentity();
10475 try {
10476 return getGbaManager(subId).overrideReleaseTime(interval);
10477 } finally {
10478 Binder.restoreCallingIdentity(identity);
10479 }
10480 }
10481
10482 /**
10483 * Return the release time for telephony to unbind GbaService.
10484 *
10485 * @param subId The sim that the GbaService is associated with.
10486 * @return The release time to unbind GbaService by millisecond.
10487 */
10488 @Override
10489 public int getGbaReleaseTime(int subId) {
10490 enforceReadPrivilegedPermission("getGbaReleaseTime");
10491
10492 final long identity = Binder.clearCallingIdentity();
10493 try {
10494 return getGbaManager(subId).getReleaseTime();
10495 } finally {
10496 Binder.restoreCallingIdentity(identity);
10497 }
10498 }
10499
10500 private GbaManager getGbaManager(int subId) {
10501 GbaManager instance = GbaManager.getInstance(subId);
10502 if (instance == null) {
10503 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10504 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10505 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10506 }
10507 return instance;
10508 }
Hui Wang761a6682020-10-31 05:12:53 +000010509
10510 /**
10511 * indicate whether the device and the carrier can support
10512 * RCS VoLTE single registration.
10513 */
10514 @Override
10515 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010516 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10517 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10518 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10519 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010520
10521 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10522 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10523 }
10524
10525 final long identity = Binder.clearCallingIdentity();
10526 try {
10527 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10528 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010529 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10530 if (isCapable != null) {
10531 return isCapable;
10532 }
Hui Wang761a6682020-10-31 05:12:53 +000010533 }
Hui Wang67af90e2021-06-04 16:57:15 -070010534 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10535 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010536 } finally {
10537 Binder.restoreCallingIdentity(identity);
10538 }
10539 }
10540
10541 /**
10542 * Register RCS provisioning callback.
10543 */
10544 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010545 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010546 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010547 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010548 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010549 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10550 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010551
10552 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10553 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10554 }
10555 if (!isImsAvailableOnDevice()) {
10556 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10557 "IMS not available on device.");
10558 }
10559
10560 final long identity = Binder.clearCallingIdentity();
10561 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010562 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010563 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010564 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10565 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010566 }
Hui Wang761a6682020-10-31 05:12:53 +000010567 } finally {
10568 Binder.restoreCallingIdentity(identity);
10569 }
10570 }
10571
10572 /**
10573 * Unregister RCS provisioning callback.
10574 */
10575 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010576 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010577 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010578 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010579 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010580 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10581 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010582
10583 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10584 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10585 }
10586 if (!isImsAvailableOnDevice()) {
10587 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10588 "IMS not available on device.");
10589 }
10590
10591 final long identity = Binder.clearCallingIdentity();
10592 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010593 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010594 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010595 } finally {
10596 Binder.restoreCallingIdentity(identity);
10597 }
10598 }
10599
10600 /**
10601 * trigger RCS reconfiguration.
10602 */
10603 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010604 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10605 "triggerRcsReconfiguration",
10606 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010607
10608 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10609 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10610 }
10611 if (!isImsAvailableOnDevice()) {
10612 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10613 "IMS not available on device.");
10614 }
10615
10616 final long identity = Binder.clearCallingIdentity();
10617 try {
10618 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10619 } finally {
10620 Binder.restoreCallingIdentity(identity);
10621 }
10622 }
10623
10624 /**
10625 * Provide the client configuration parameters of the RCS application.
10626 */
10627 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010628 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10629 "setRcsClientConfiguration",
10630 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010631
10632 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10633 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10634 }
10635 if (!isImsAvailableOnDevice()) {
10636 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10637 "IMS not available on device.");
10638 }
10639
10640 final long identity = Binder.clearCallingIdentity();
10641
10642 try {
10643 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10644 if (configBinder == null) {
10645 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010646 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10647 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010648 } else {
10649 configBinder.setRcsClientConfiguration(rcc);
10650 }
joonhunshin3e154242021-09-17 06:33:39 +000010651
10652 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10653 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010654 } catch (RemoteException e) {
10655 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010656 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10657 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010658 } finally {
10659 Binder.restoreCallingIdentity(identity);
10660 }
10661 }
10662
10663 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010664 * Enables or disables the test mode for RCS VoLTE single registration.
10665 */
10666 @Override
10667 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10668 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10669 "setRcsSingleRegistrationTestModeEnabled");
10670
10671 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10672 }
10673
10674 /**
10675 * Gets the test mode for RCS VoLTE single registration.
10676 */
10677 @Override
10678 public boolean getRcsSingleRegistrationTestModeEnabled() {
10679 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10680 "getRcsSingleRegistrationTestModeEnabled");
10681
10682 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10683 }
10684
10685 /**
Hui Wang761a6682020-10-31 05:12:53 +000010686 * Overrides the config of RCS VoLTE single registration enabled for the device.
10687 */
10688 @Override
10689 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10690 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10691 "setDeviceSingleRegistrationEnabledOverride");
10692 enforceModifyPermission();
10693
10694 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10695 : Boolean.parseBoolean(enabledStr);
10696 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010697 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010698 }
10699
10700 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010701 * Sends a device to device communication message. Only usable via shell.
10702 * @param message message to send.
10703 * @param value message value.
10704 */
10705 @Override
10706 public void sendDeviceToDeviceMessage(int message, int value) {
10707 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010708 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010709 enforceModifyPermission();
10710
10711 final long identity = Binder.clearCallingIdentity();
10712 try {
10713 TelephonyConnectionService service =
10714 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10715 if (service == null) {
10716 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10717 return;
10718 }
10719 service.sendTestDeviceToDeviceMessage(message, value);
10720 } finally {
10721 Binder.restoreCallingIdentity(identity);
10722 }
10723 }
10724
Tyler Gunnbabbda02021-02-10 11:05:02 -080010725 /**
10726 * Sets the specified device to device transport active.
10727 * @param transport The transport to set active.
10728 */
10729 @Override
10730 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10731 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10732 "setActiveDeviceToDeviceTransport");
10733 enforceModifyPermission();
10734
10735 final long identity = Binder.clearCallingIdentity();
10736 try {
10737 TelephonyConnectionService service =
10738 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10739 if (service == null) {
10740 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10741 return;
10742 }
10743 service.setActiveDeviceToDeviceTransport(transport);
10744 } finally {
10745 Binder.restoreCallingIdentity(identity);
10746 }
10747 }
Tyler Gunn92479152021-01-20 16:30:10 -080010748
Tyler Gunnd4339262021-05-03 14:46:49 -070010749 @Override
10750 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10751 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10752 "setDeviceToDeviceForceEnabled");
10753
10754 final long identity = Binder.clearCallingIdentity();
10755 try {
10756 Arrays.stream(PhoneFactory.getPhones()).forEach(
10757 p -> {
10758 Phone thePhone = p.getImsPhone();
10759 if (thePhone != null && thePhone instanceof ImsPhone) {
10760 ImsPhone imsPhone = (ImsPhone) thePhone;
10761 CallTracker tracker = imsPhone.getCallTracker();
10762 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10763 ImsPhoneCallTracker imsPhoneCallTracker =
10764 (ImsPhoneCallTracker) tracker;
10765 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10766 }
10767 }
10768 }
10769 );
10770 } finally {
10771 Binder.restoreCallingIdentity(identity);
10772 }
10773 }
10774
Tyler Gunn92479152021-01-20 16:30:10 -080010775 /**
Hui Wang761a6682020-10-31 05:12:53 +000010776 * Gets the config of RCS VoLTE single registration enabled for the device.
10777 */
10778 @Override
10779 public boolean getDeviceSingleRegistrationEnabled() {
10780 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10781 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10782 }
10783
10784 /**
10785 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10786 */
10787 @Override
10788 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10789 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10790 "setCarrierSingleRegistrationEnabledOverride");
10791 enforceModifyPermission();
10792
10793 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10794 : Boolean.parseBoolean(enabledStr);
10795 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10796 subId, enabled);
10797 }
10798
10799 /**
10800 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10801 */
10802 @Override
10803 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10804 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10805 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10806 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010807
10808 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010809 * Overrides the ims feature validation result
10810 */
10811 @Override
10812 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10813 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10814 "setImsFeatureValidationOverride");
10815
10816 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10817 : Boolean.parseBoolean(enabledStr);
10818 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10819 subId, enabled);
10820 }
10821
10822 /**
10823 * Gets the ims feature validation override value
10824 */
10825 @Override
10826 public boolean getImsFeatureValidationOverride(int subId) {
10827 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10828 "getImsFeatureValidationOverride");
10829 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10830 }
10831
10832 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010833 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10834 * their mobile plan.
10835 */
10836 @Override
10837 public String getMobileProvisioningUrl() {
10838 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10839 final long identity = Binder.clearCallingIdentity();
10840 try {
10841 return getDefaultPhone().getMobileProvisioningUrl();
10842 } finally {
10843 Binder.restoreCallingIdentity(identity);
10844 }
10845 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010846
James.cf Linbcdf8b32021-01-14 16:44:13 +080010847 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010848 * Get the EAB contact from the EAB database.
10849 */
10850 @Override
10851 public String getContactFromEab(String contact) {
10852 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10853 enforceModifyPermission();
10854 final long identity = Binder.clearCallingIdentity();
10855 try {
10856 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10857 } finally {
10858 Binder.restoreCallingIdentity(identity);
10859 }
10860 }
10861
10862 /**
Calvin Pana1434322021-07-01 19:27:01 +080010863 * Get the EAB capability from the EAB database.
10864 */
10865 @Override
10866 public String getCapabilityFromEab(String contact) {
10867 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10868 enforceModifyPermission();
10869 final long identity = Binder.clearCallingIdentity();
10870 try {
10871 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10872 } finally {
10873 Binder.restoreCallingIdentity(identity);
10874 }
10875 }
10876
10877 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010878 * Remove the EAB contacts from the EAB database.
10879 */
10880 @Override
10881 public int removeContactFromEab(int subId, String contacts) {
10882 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10883 enforceModifyPermission();
10884 final long identity = Binder.clearCallingIdentity();
10885 try {
10886 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10887 } finally {
10888 Binder.restoreCallingIdentity(identity);
10889 }
10890 }
10891
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010892 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010893 public boolean getDeviceUceEnabled() {
10894 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10895 final long identity = Binder.clearCallingIdentity();
10896 try {
10897 return mApp.getDeviceUceEnabled();
10898 } finally {
10899 Binder.restoreCallingIdentity(identity);
10900 }
10901 }
10902
10903 @Override
10904 public void setDeviceUceEnabled(boolean isEnabled) {
10905 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10906 final long identity = Binder.clearCallingIdentity();
10907 try {
10908 mApp.setDeviceUceEnabled(isEnabled);
10909 } finally {
10910 Binder.restoreCallingIdentity(identity);
10911 }
10912 }
10913
Brad Ebinger14d467f2021-02-12 06:18:28 +000010914 /**
10915 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10916 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10917 */
10918 // Used for SHELL command only right now.
10919 @Override
10920 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10921 List<String> featureTags) {
10922 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10923 "addUceRegistrationOverrideShell");
10924 final long identity = Binder.clearCallingIdentity();
10925 try {
10926 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10927 new ArraySet<>(featureTags));
10928 } catch (ImsException e) {
10929 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10930 } finally {
10931 Binder.restoreCallingIdentity(identity);
10932 }
10933 }
10934
10935 /**
10936 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10937 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10938 */
10939 // Used for SHELL command only right now.
10940 @Override
10941 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10942 List<String> featureTags) {
10943 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10944 "removeUceRegistrationOverrideShell");
10945 final long identity = Binder.clearCallingIdentity();
10946 try {
10947 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10948 new ArraySet<>(featureTags));
10949 } catch (ImsException e) {
10950 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10951 } finally {
10952 Binder.restoreCallingIdentity(identity);
10953 }
10954 }
10955
10956 /**
10957 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10958 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10959 */
10960 // Used for SHELL command only right now.
10961 @Override
10962 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10963 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10964 "clearUceRegistrationOverrideShell");
10965 final long identity = Binder.clearCallingIdentity();
10966 try {
10967 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10968 } catch (ImsException e) {
10969 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10970 } finally {
10971 Binder.restoreCallingIdentity(identity);
10972 }
10973 }
10974
10975 /**
10976 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10977 */
10978 // Used for SHELL command only right now.
10979 @Override
10980 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10981 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10982 "getLatestRcsContactUceCapabilityShell");
10983 final long identity = Binder.clearCallingIdentity();
10984 try {
10985 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10986 } catch (ImsException e) {
10987 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10988 } finally {
10989 Binder.restoreCallingIdentity(identity);
10990 }
10991 }
10992
10993 /**
10994 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10995 * device does not have an active PUBLISH.
10996 */
10997 // Used for SHELL command only right now.
10998 @Override
10999 public String getLastUcePidfXmlShell(int subId) {
11000 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11001 final long identity = Binder.clearCallingIdentity();
11002 try {
11003 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11004 } catch (ImsException e) {
11005 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11006 } finally {
11007 Binder.restoreCallingIdentity(identity);
11008 }
11009 }
11010
James.cf Line8713a42021-04-29 16:04:26 +080011011 /**
11012 * Remove UCE requests cannot be sent to the network status.
11013 */
11014 // Used for SHELL command only right now.
11015 @Override
11016 public boolean removeUceRequestDisallowedStatus(int subId) {
11017 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11018 final long identity = Binder.clearCallingIdentity();
11019 try {
11020 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11021 } catch (ImsException e) {
11022 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11023 } finally {
11024 Binder.restoreCallingIdentity(identity);
11025 }
11026 }
11027
James.cf Lin18bb9002021-05-25 01:37:38 +080011028 /**
11029 * Remove UCE requests cannot be sent to the network status.
11030 */
11031 // Used for SHELL command only.
11032 @Override
11033 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11034 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11035 final long identity = Binder.clearCallingIdentity();
11036 try {
11037 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11038 } catch (ImsException e) {
11039 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11040 } finally {
11041 Binder.restoreCallingIdentity(identity);
11042 }
11043 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011044
James.cf Lin4b784aa2021-01-31 03:25:15 +080011045 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011046 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11047 String callingPackage) {
11048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11049 mApp, subId, "setSignalStrengthUpdateRequest");
11050
11051 final int callingUid = Binder.getCallingUid();
11052 // Verify that tha callingPackage belongs to the calling UID
11053 mApp.getSystemService(AppOpsManager.class)
11054 .checkPackage(callingUid, callingPackage);
11055
Rambo Wang3607f502021-02-01 21:51:40 -080011056 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011057
11058 final long identity = Binder.clearCallingIdentity();
11059 try {
11060 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11061 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11062
11063 if (result instanceof IllegalStateException) {
11064 throw (IllegalStateException) result;
11065 }
11066 } finally {
11067 Binder.restoreCallingIdentity(identity);
11068 }
11069 }
11070
11071 @Override
11072 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11073 String callingPackage) {
11074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11075 mApp, subId, "clearSignalStrengthUpdateRequest");
11076
11077 final int callingUid = Binder.getCallingUid();
11078 // Verify that tha callingPackage belongs to the calling UID
11079 mApp.getSystemService(AppOpsManager.class)
11080 .checkPackage(callingUid, callingPackage);
11081
11082 final long identity = Binder.clearCallingIdentity();
11083 try {
11084 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11085 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11086
11087 if (result instanceof IllegalStateException) {
11088 throw (IllegalStateException) result;
11089 }
11090 } finally {
11091 Binder.restoreCallingIdentity(identity);
11092 }
11093 }
11094
Rambo Wang3607f502021-02-01 21:51:40 -080011095 private static void validateSignalStrengthUpdateRequest(Context context,
11096 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011097 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11098 // phone/system process do not have further restriction on request
11099 return;
11100 }
11101
11102 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011103 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011104 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011105 context.enforceCallingOrSelfPermission(
11106 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11107 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011108 }
11109
11110 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11111 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11112 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11113 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11114 || info.isEnabled()) {
11115 throw new IllegalArgumentException(
11116 "Only system can set hide fields in SignalThresholdInfo");
11117 }
11118
11119 // Thresholds length for each RAN need in range. This has been validated in
11120 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11121 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11122 final int[] thresholds = info.getThresholds();
11123 Objects.requireNonNull(thresholds);
11124 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11125 || thresholds.length
11126 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11127 throw new IllegalArgumentException(
11128 "thresholds length is out of range: " + thresholds.length);
11129 }
11130 }
11131 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011132
11133 /**
11134 * Gets the current phone capability.
11135 *
11136 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11137 * @return the PhoneCapability which describes the data connection capability of modem.
11138 * It's used to evaluate possible phone config change, for example from single
11139 * SIM device to multi-SIM device.
11140 */
11141 @Override
11142 public PhoneCapability getPhoneCapability() {
11143 enforceReadPrivilegedPermission("getPhoneCapability");
11144 final long identity = Binder.clearCallingIdentity();
11145 try {
11146 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11147 } finally {
11148 Binder.restoreCallingIdentity(identity);
11149 }
11150 }
Michele Berionne5e411512020-11-13 02:36:59 +000011151
11152 /**
11153 * Prepare TelephonyManager for an unattended reboot. The reboot is
11154 * required to be done shortly after the API is invoked.
11155 */
11156 @Override
11157 @TelephonyManager.PrepareUnattendedRebootResult
11158 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011159 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011160 enforceRebootPermission();
11161
11162 final long identity = Binder.clearCallingIdentity();
11163 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011164 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011165 } finally {
11166 Binder.restoreCallingIdentity(identity);
11167 }
11168 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011169
11170 /**
11171 * Request to get the current slicing configuration including URSP rules and
11172 * NSSAIs (configured, allowed and rejected).
11173 *
11174 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11175 */
11176 @Override
11177 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011178 TelephonyPermissions
11179 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11180 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011181
11182 final long identity = Binder.clearCallingIdentity();
11183 try {
11184 Phone phone = getDefaultPhone();
11185 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11186 } finally {
11187 Binder.restoreCallingIdentity(identity);
11188 }
11189 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011190
11191 /**
11192 * Register an IMS connection state callback
11193 */
11194 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011195 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11196 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011197 if (feature == ImsFeature.FEATURE_MMTEL) {
11198 // ImsMmTelManager
11199 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11200 TelephonyPermissions
11201 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11202 mApp, subId, "registerImsStateCallback");
11203 } else if (feature == ImsFeature.FEATURE_RCS) {
11204 // ImsRcsManager or SipDelegateManager
11205 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11206 Binder.getCallingUid(), "registerImsStateCallback",
11207 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11208 Manifest.permission.READ_PRECISE_PHONE_STATE,
11209 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11210 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11211 }
11212
11213 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11214 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11215 "IMS not available on device.");
11216 }
11217
11218 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11219 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11220 }
11221
11222 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11223 if (controller == null) {
11224 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11225 "IMS not available on device.");
11226 }
11227
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011228 if (callingPackage == null) {
11229 callingPackage = getCurrentPackageName();
11230 }
11231
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011232 final long token = Binder.clearCallingIdentity();
11233 try {
11234 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011235 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011236 } catch (ImsException e) {
11237 throw new ServiceSpecificException(e.getCode());
11238 } finally {
11239 Binder.restoreCallingIdentity(token);
11240 }
11241 }
11242
11243 /**
11244 * Unregister an IMS connection state callback
11245 */
11246 @Override
11247 public void unregisterImsStateCallback(IImsStateCallback cb) {
11248 final long token = Binder.clearCallingIdentity();
11249 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11250 if (controller == null) {
11251 return;
11252 }
11253 try {
11254 controller.unregisterImsStateCallback(cb);
11255 } finally {
11256 Binder.restoreCallingIdentity(token);
11257 }
11258 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011259
11260 /**
11261 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11262 *
11263 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11264 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11265 * SecurityException.
11266 * If there is current registered network this value will be same as the registered cell
11267 * identity. If the device goes out of service the previous cell identity is cached and
11268 * will be returned. If the cache age of the Cell identity is more than 24 hours
11269 * it will be cleared and null will be returned.
11270 *
11271 */
11272 @Override
11273 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11274 String callingFeatureId) {
11275 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11276 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11277 LocationAccessPolicy.checkLocationPermission(mApp,
11278 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11279 .setCallingPackage(callingPackage)
11280 .setCallingFeatureId(callingFeatureId)
11281 .setCallingPid(Binder.getCallingPid())
11282 .setCallingUid(Binder.getCallingUid())
11283 .setMethod("getLastKnownCellIdentity")
11284 .setLogAsInfo(true)
11285 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11286 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11287 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11288 .build());
11289
11290 boolean hasFinePermission =
11291 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11292 if (!hasFinePermission
11293 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11294 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011295 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011296 }
11297
11298 final long identity = Binder.clearCallingIdentity();
11299 try {
11300 Phone phone = getPhone(subId);
11301 if (phone == null) return null;
11302 ServiceStateTracker sst = phone.getServiceStateTracker();
11303 if (sst == null) return null;
11304 return sst.getLastKnownCellIdentity();
11305 } finally {
11306 Binder.restoreCallingIdentity(identity);
11307 }
11308 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011309
jimsun3b9ccac2021-10-26 15:01:23 +080011310 /**
11311 * Sets the modem service class Name that Telephony will bind to.
11312 *
11313 * @param serviceName The class name of the modem service.
11314 * @return true if the operation is succeed, otherwise false.
11315 */
11316 public boolean setModemService(String serviceName) {
11317 Log.d(LOG_TAG, "setModemService - " + serviceName);
11318 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11320 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11321 "setModemService");
11322 return mPhoneConfigurationManager.setModemService(serviceName);
11323 }
11324
11325 /**
11326 * Return the class name of the currently bounded modem service.
11327 *
11328 * @return the class name of the modem service.
11329 */
11330 public String getModemService() {
11331 String result;
11332 Log.d(LOG_TAG, "getModemService");
11333 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11334 TelephonyPermissions
11335 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11336 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11337 "getModemService");
11338 result = mPhoneConfigurationManager.getModemService();
11339 Log.d(LOG_TAG, "result = " + result);
11340 return result;
11341 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011342
11343 @Override
11344 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11345 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11346 mApp.enforceCallingOrSelfPermission(
11347 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11348 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11349
11350 final long identity = Binder.clearCallingIdentity();
11351 try {
11352 Phone phone = getPhone(subId);
11353 if (phone == null) return;
11354 phone.setVoiceServiceStateOverride(hasService);
11355 } finally {
11356 Binder.restoreCallingIdentity(identity);
11357 }
11358 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011359
11360 /**
11361 * set removable eSIM as default eUICC.
11362 *
11363 * @hide
11364 */
11365 @Override
11366 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11367 enforceModifyPermission();
11368 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11369
11370 final long identity = Binder.clearCallingIdentity();
11371 try {
11372 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11373 } finally {
11374 Binder.restoreCallingIdentity(identity);
11375 }
11376 }
11377
11378 /**
11379 * Returns whether the removable eSIM is default eUICC or not.
11380 *
11381 * @hide
11382 */
11383 @Override
11384 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11385 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11386 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11387
11388 final long identity = Binder.clearCallingIdentity();
11389 try {
11390 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11391 } finally {
11392 Binder.restoreCallingIdentity(identity);
11393 }
11394 }
11395
Ryan Savitskicab25c52023-03-14 14:23:49 +000011396 /**
11397 * Get the SIM state for the slot index.
11398 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11399 *
11400 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11401 */
11402 @Override
11403 @SimState
11404 public int getSimStateForSlotIndex(int slotIndex) {
11405 IccCardConstants.State simState;
11406 if (slotIndex < 0) {
11407 simState = IccCardConstants.State.UNKNOWN;
11408 } else {
11409 Phone phone = null;
11410 try {
11411 phone = PhoneFactory.getPhone(slotIndex);
11412 } catch (IllegalStateException e) {
11413 // ignore
11414 }
11415 if (phone == null) {
11416 simState = IccCardConstants.State.UNKNOWN;
11417 } else {
11418 IccCard icc = phone.getIccCard();
11419 if (icc == null) {
11420 simState = IccCardConstants.State.UNKNOWN;
11421 } else {
11422 simState = icc.getState();
11423 }
11424 }
11425 }
11426 return simState.ordinal();
11427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011428}