blob: 809b1c2723007a32abc094779ace1abe4af6ff66 [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
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302611 *
2612 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2613 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002614 */
Wink Saville9de0f752013-10-22 19:04:03 -07002615 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616
2617 while (mHandler == null) {
2618 try {
2619 wait();
2620 } catch (InterruptedException e) {
2621 Thread.currentThread().interrupt();
2622 }
2623 }
2624 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2625
2626 if (puk == null) {
2627 mSimCard.supplyPin(pin, callback);
2628 } else {
2629 mSimCard.supplyPuk(puk, pin, callback);
2630 }
2631
2632 while (!mDone) {
2633 try {
2634 Log.d(LOG_TAG, "wait for done");
2635 wait();
2636 } catch (InterruptedException e) {
2637 // Restore the interrupted status
2638 Thread.currentThread().interrupt();
2639 }
2640 }
2641 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002642 int[] resultArray = new int[2];
2643 resultArray[0] = mResult;
2644 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002645
2646 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002647 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002648 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302649 // This instance is no longer reused, so quit its thread's looper.
2650 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002651
Wink Saville9de0f752013-10-22 19:04:03 -07002652 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 }
2654 }
2655
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002656 /**
2657 * This method has been removed due to privacy and stability concerns.
2658 */
2659 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002661 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2662 return;
Wink Saville36469e72014-06-11 15:17:00 -07002663 }
2664
Nathan Harold1f889d82020-06-04 17:05:26 -07002665 @Override
2666 public void updateServiceLocationWithPackageName(String callingPackage) {
2667 mApp.getSystemService(AppOpsManager.class)
2668 .checkPackage(Binder.getCallingUid(), callingPackage);
2669
Nathan Haroldf096d982020-11-18 17:18:06 -08002670 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002671 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2672 // Callers targeting S have no business invoking this method.
2673 return;
2674 }
2675
2676 LocationAccessPolicy.LocationPermissionResult locationResult =
2677 LocationAccessPolicy.checkLocationPermission(mApp,
2678 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2679 .setCallingPackage(callingPackage)
2680 .setCallingFeatureId(null)
2681 .setCallingPid(Binder.getCallingPid())
2682 .setCallingUid(Binder.getCallingUid())
2683 .setMethod("updateServiceLocation")
2684 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2685 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2686 .build());
2687 // Apps that lack location permission have no business calling this method;
2688 // however, because no permission was declared in the public API, denials must
2689 // all be "soft".
2690 switch (locationResult) {
2691 case DENIED_HARD: /* fall through */
2692 case DENIED_SOFT:
2693 return;
2694 }
2695
2696 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697 final long identity = Binder.clearCallingIdentity();
2698 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002699 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002701 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702 }
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002706 }
2707
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002708 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002709 @Override
2710 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002711 return isRadioOnWithFeature(callingPackage, null);
2712 }
2713
2714
2715 @Override
2716 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2717 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2718 callingFeatureId);
2719 }
2720
2721 @Deprecated
2722 @Override
2723 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2724 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002725 }
2726
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002727 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002728 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2729 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002730 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002731 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002732 return false;
2733 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734
2735 final long identity = Binder.clearCallingIdentity();
2736 try {
2737 return isRadioOnForSubscriber(subId);
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
2740 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002741 }
2742
2743 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744 final long identity = Binder.clearCallingIdentity();
2745 try {
2746 final Phone phone = getPhone(subId);
2747 if (phone != null) {
2748 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2749 } else {
2750 return false;
2751 }
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002755 }
2756
2757 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002758 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 }
Wink Saville36469e72014-06-11 15:17:00 -07002760
Wink Savilleb564aae2014-10-23 10:18:09 -07002761 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763
2764 final long identity = Binder.clearCallingIdentity();
2765 try {
2766 final Phone phone = getPhone(subId);
2767 if (phone != null) {
2768 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2769 }
2770 } finally {
2771 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002772 }
Wink Saville36469e72014-06-11 15:17:00 -07002773 }
2774
2775 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002776 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002777 }
2778
Wink Savilleb564aae2014-10-23 10:18:09 -07002779 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002780 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 final Phone phone = getPhone(subId);
2785 if (phone == null) {
2786 return false;
2787 }
2788 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2789 toggleRadioOnOffForSubscriber(subId);
2790 }
2791 return true;
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002795 }
Wink Saville36469e72014-06-11 15:17:00 -07002796
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002797 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002798 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002799 /*
2800 * If any of the Radios are available, it will need to be
2801 * shutdown. So return true if any Radio is available.
2802 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2806 Phone phone = PhoneFactory.getPhone(i);
2807 if (phone != null && phone.isRadioAvailable()) return true;
2808 }
2809 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2810 return false;
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002813 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002814 }
2815
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002817 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818 enforceModifyPermission();
2819
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2823 logv("Shutting down Phone " + i);
2824 shutdownRadioUsingPhoneId(i);
2825 }
2826 } finally {
2827 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002828 }
2829 }
2830
2831 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002832 Phone phone = PhoneFactory.getPhone(phoneId);
2833 if (phone != null && phone.isRadioAvailable()) {
2834 phone.shutdownRadio();
2835 }
2836 }
2837
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002838 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002839 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2844 if (defaultPhone != null) {
2845 defaultPhone.setRadioPower(turnOn);
2846 return true;
2847 } else {
2848 loge("There's no default phone.");
2849 return false;
2850 }
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002853 }
Wink Saville36469e72014-06-11 15:17:00 -07002854 }
2855
Wink Savilleb564aae2014-10-23 10:18:09 -07002856 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858
2859 final long identity = Binder.clearCallingIdentity();
2860 try {
2861 final Phone phone = getPhone(subId);
2862 if (phone != null) {
2863 phone.setRadioPower(turnOn);
2864 return true;
2865 } else {
2866 return false;
2867 }
2868 } finally {
2869 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002871 }
2872
Wink Saville36469e72014-06-11 15:17:00 -07002873 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002874 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002875 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002877
2878 final long identity = Binder.clearCallingIdentity();
2879 try {
Jack Yudf049d72022-12-02 22:48:35 -08002880 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881 final Phone phone = getPhone(subId);
2882 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002883 phone.getDataSettingsManager().setDataEnabled(
2884 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 return true;
2886 } else {
2887 return false;
2888 }
2889 } finally {
2890 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002892 }
2893
Wink Saville36469e72014-06-11 15:17:00 -07002894 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002895 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002896 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002897 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002898
2899 final long identity = Binder.clearCallingIdentity();
2900 try {
Jack Yudf049d72022-12-02 22:48:35 -08002901 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902 final Phone phone = getPhone(subId);
2903 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002904 phone.getDataSettingsManager().setDataEnabled(
2905 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 return true;
2907 } else {
2908 return false;
2909 }
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002913 }
2914
Sanket Padawe356d7632015-06-22 14:03:32 -07002915 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002916 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917 final long identity = Binder.clearCallingIdentity();
2918 try {
2919 final Phone phone = getPhone(subId);
2920 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07002921 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 } else {
2923 return false;
2924 }
2925 } finally {
2926 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002927 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002928 }
2929
2930 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002931 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002932 }
2933
pkanwarae03a6b2016-11-06 20:37:09 -08002934 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002935 enforceCallPermission();
2936
2937 final long identity = Binder.clearCallingIdentity();
2938 try {
2939 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2940 return;
2941 }
2942 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2943 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
2946 }
pkanwar32d516d2016-10-14 19:37:38 -07002947 };
2948
Wink Savilleb564aae2014-10-23 10:18:09 -07002949 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002950 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2955 return false;
2956 }
2957 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2958 } finally {
2959 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002960 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002961 }
2962
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002963 /**
2964 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2965 * tag on getCallState Binder call.
2966 */
2967 @Deprecated
2968 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002969 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002970 if (CompatChanges.isChangeEnabled(
2971 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2972 Binder.getCallingUid())) {
2973 // Do not allow this API to be called on API version 31+, it should only be
2974 // called on old apps using this Binder call directly.
2975 throw new SecurityException("This method can only be used for applications "
2976 + "targeting API version 30 or less.");
2977 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002978 final long identity = Binder.clearCallingIdentity();
2979 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002980 Phone phone = getPhone(getDefaultSubscription());
2981 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2982 PhoneConstantConversions.convertCallState(phone.getState());
2983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
2986 }
2987
2988 @Override
2989 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2990 if (CompatChanges.isChangeEnabled(
2991 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2992 Binder.getCallingUid())) {
2993 // Check READ_PHONE_STATE for API version 31+
2994 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2995 featureId, "getCallStateForSubscription")) {
2996 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2997 + "targeting API level 31+.");
2998 }
2999 }
3000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3004 PhoneConstantConversions.convertCallState(phone.getState());
3005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003008 }
3009
Sanket Padawe356d7632015-06-22 14:03:32 -07003010 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003011 public int getDataState() {
Jack Yudf049d72022-12-02 22:48:35 -08003012 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003013 }
3014
3015 @Override
3016 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017 final long identity = Binder.clearCallingIdentity();
3018 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003019 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07003021 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 } else {
3023 return PhoneConstantConversions.convertDataState(
3024 PhoneConstants.DataState.DISCONNECTED);
3025 }
3026 } finally {
3027 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003028 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003029 }
3030
Sanket Padawe356d7632015-06-22 14:03:32 -07003031 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003032 public @DataActivityType int getDataActivity() {
Jack Yudf049d72022-12-02 22:48:35 -08003033 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003034 }
3035
3036 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003037 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038 final long identity = Binder.clearCallingIdentity();
3039 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003040 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003042 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043 } else {
3044 return TelephonyManager.DATA_ACTIVITY_NONE;
3045 }
3046 } finally {
3047 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003049 }
3050
3051 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003052 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003053 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003054 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003055
3056 LocationAccessPolicy.LocationPermissionResult locationResult =
3057 LocationAccessPolicy.checkLocationPermission(mApp,
3058 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3059 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003060 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003061 .setCallingPid(Binder.getCallingPid())
3062 .setCallingUid(Binder.getCallingUid())
3063 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003064 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003065 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3066 .build());
3067 switch (locationResult) {
3068 case DENIED_HARD:
3069 throw new SecurityException("Not allowed to access cell location");
3070 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003071 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3072 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003073 }
3074
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003075 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yudf049d72022-12-02 22:48:35 -08003079 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003080 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081 } finally {
3082 Binder.restoreCallingIdentity(identity);
3083 }
Svetoslav64fad262015-04-14 14:35:21 -07003084 }
3085
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003086 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003087 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003088 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3089 // registered cell info, so return a NULL country instead.
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003092 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3093 // Get default phone in this case.
3094 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3095 }
Jack Yudf049d72022-12-02 22:48:35 -08003096 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003097 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003098 if (phone == null) return "";
3099 ServiceStateTracker sst = phone.getServiceStateTracker();
3100 if (sst == null) return "";
3101 LocaleTracker lt = sst.getLocaleTracker();
3102 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003103 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003104 } finally {
3105 Binder.restoreCallingIdentity(identity);
3106 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003107 }
3108
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003109 /**
3110 * This method was removed due to potential issues caused by performing partial
3111 * updates of service state, and lack of a credible use case.
3112 *
3113 * This has the ability to break the telephony implementation by disabling notification of
3114 * changes in device connectivity. DO NOT USE THIS!
3115 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003116 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 public void enableLocationUpdates() {
3118 mApp.enforceCallingOrSelfPermission(
3119 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003120 }
3121
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003122 /**
3123 * This method was removed due to potential issues caused by performing partial
3124 * updates of service state, and lack of a credible use case.
3125 *
3126 * This has the ability to break the telephony implementation by disabling notification of
3127 * changes in device connectivity. DO NOT USE THIS!
3128 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003129 @Override
3130 public void disableLocationUpdates() {
3131 mApp.enforceCallingOrSelfPermission(
3132 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003133 }
3134
3135 @Override
3136 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003137 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3138 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003139 try {
3140 mApp.getSystemService(AppOpsManager.class)
3141 .checkPackage(Binder.getCallingUid(), callingPackage);
3142 } catch (SecurityException e) {
3143 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3144 throw e;
3145 }
3146
Nathan Haroldf096d982020-11-18 17:18:06 -08003147 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003148 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3149 throw new SecurityException(
3150 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3151 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003152
Jordan Liu1617b712019-07-10 15:06:26 -07003153 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003154 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3155 return null;
3156 }
Svetoslav64fad262015-04-14 14:35:21 -07003157
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003158 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003159
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003160 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003161 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003162
Nathan Haroldf180aac2018-06-01 18:43:55 -07003163 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3164 for (CellInfo ci : info) {
3165 if (ci instanceof CellInfoGsm) {
3166 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3167 } else if (ci instanceof CellInfoWcdma) {
3168 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003171 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003172 }
3173
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003174 private List<CellInfo> getCachedCellInfo() {
3175 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3176 for (Phone phone : PhoneFactory.getPhones()) {
3177 List<CellInfo> info = phone.getAllCellInfo();
3178 if (info != null) cellInfos.addAll(info);
3179 }
3180 return cellInfos;
3181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003182
3183 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003184 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003185 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003186 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003187
3188 LocationAccessPolicy.LocationPermissionResult locationResult =
3189 LocationAccessPolicy.checkLocationPermission(mApp,
3190 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3191 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003192 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003193 .setCallingPid(Binder.getCallingPid())
3194 .setCallingUid(Binder.getCallingUid())
3195 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003196 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003197 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3198 .build());
3199 switch (locationResult) {
3200 case DENIED_HARD:
3201 throw new SecurityException("Not allowed to access cell info");
3202 case DENIED_SOFT:
3203 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 }
3205
Nathan Haroldf096d982020-11-18 17:18:06 -08003206 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003207 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3208 return getCachedCellInfo();
3209 }
3210
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003211 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003212 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213 final long identity = Binder.clearCallingIdentity();
3214 try {
3215 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3216 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003217 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003218 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003219 if (info != null) cellInfos.addAll(info);
3220 }
3221 return cellInfos;
3222 } finally {
3223 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003224 }
3225 }
3226
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003227 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003228 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3229 String callingFeatureId) {
3230 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3231 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003232 }
3233
3234 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003235 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3236 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003237 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003238 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003239 }
3240
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003241 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3242 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003243 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003244 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003245
3246 LocationAccessPolicy.LocationPermissionResult locationResult =
3247 LocationAccessPolicy.checkLocationPermission(mApp,
3248 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3249 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003250 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003251 .setCallingPid(Binder.getCallingPid())
3252 .setCallingUid(Binder.getCallingUid())
3253 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003254 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3255 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003256 .build());
3257 switch (locationResult) {
3258 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003259 if (TelephonyPermissions
3260 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003261 // Safetynet logging for b/154934934
3262 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3263 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003264 throw new SecurityException("Not allowed to access cell info");
3265 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003266 if (TelephonyPermissions
3267 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003268 // Safetynet logging for b/154934934
3269 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3270 }
Nathan Harold5320c422019-05-09 10:26:08 -07003271 try {
3272 cb.onCellInfo(new ArrayList<CellInfo>());
3273 } catch (RemoteException re) {
3274 // Drop without consequences
3275 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003276 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003277 }
3278
Nathan Harolda939a962019-05-09 10:13:47 -07003279
3280 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003281 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3282
3283 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3284 }
3285
3286 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003287 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003288 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003289 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003290
3291 final long identity = Binder.clearCallingIdentity();
3292 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003293 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003294 } finally {
3295 Binder.restoreCallingIdentity(identity);
3296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003297 }
3298
Shishir Agrawala9f32182016-04-12 12:00:16 -07003299 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003300 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003301 Phone phone = PhoneFactory.getPhone(slotIndex);
3302 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003303 return null;
3304 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003305 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003306 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003307 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003308 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003309 return null;
3310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003311
3312 final long identity = Binder.clearCallingIdentity();
3313 try {
3314 return phone.getImei();
3315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003318 }
3319
3320 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003321 public String getTypeAllocationCodeForSlot(int slotIndex) {
3322 Phone phone = PhoneFactory.getPhone(slotIndex);
3323 String tac = null;
3324 if (phone != null) {
3325 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003326 try {
3327 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3328 } catch (IndexOutOfBoundsException e) {
3329 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3330 return null;
3331 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003332 }
3333 return tac;
3334 }
3335
3336 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003337 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003338 try {
3339 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3340 } catch (SecurityException se) {
3341 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3342 throw new SecurityException("Package " + callingPackage + " does not belong to "
3343 + Binder.getCallingUid());
3344 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003345 Phone phone = PhoneFactory.getPhone(slotIndex);
3346 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003347 return null;
3348 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003349
Jeff Davidson913390f2018-02-23 17:11:49 -08003350 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003351 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003352 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003353 return null;
3354 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355
3356 final long identity = Binder.clearCallingIdentity();
3357 try {
3358 return phone.getMeid();
3359 } finally {
3360 Binder.restoreCallingIdentity(identity);
3361 }
Jack Yu2af8d712017-03-15 17:14:14 -07003362 }
3363
3364 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003365 public String getManufacturerCodeForSlot(int slotIndex) {
3366 Phone phone = PhoneFactory.getPhone(slotIndex);
3367 String manufacturerCode = null;
3368 if (phone != null) {
3369 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003370 try {
3371 manufacturerCode =
3372 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3373 } catch (IndexOutOfBoundsException e) {
3374 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3375 return null;
3376 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003377 }
3378 return manufacturerCode;
3379 }
3380
3381 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003382 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3383 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003384 Phone phone = PhoneFactory.getPhone(slotIndex);
3385 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003386 return null;
3387 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003388 int subId = phone.getSubId();
3389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003390 mApp, subId, callingPackage, callingFeatureId,
3391 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003392 return null;
3393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003394
3395 final long identity = Binder.clearCallingIdentity();
3396 try {
3397 return phone.getDeviceSvn();
3398 } finally {
3399 Binder.restoreCallingIdentity(identity);
3400 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003401 }
3402
fionaxu43304da2017-11-27 22:51:16 -08003403 @Override
3404 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405 final long identity = Binder.clearCallingIdentity();
3406 try {
3407 final Phone phone = getPhone(subId);
3408 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3409 } finally {
3410 Binder.restoreCallingIdentity(identity);
3411 }
fionaxu43304da2017-11-27 22:51:16 -08003412 }
3413
3414 @Override
3415 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003416 final long identity = Binder.clearCallingIdentity();
3417 try {
3418 final Phone phone = getPhone(subId);
3419 return phone == null ? null : phone.getCarrierName();
3420 } finally {
3421 Binder.restoreCallingIdentity(identity);
3422 }
fionaxu43304da2017-11-27 22:51:16 -08003423 }
3424
calvinpanffe225e2018-11-01 19:43:06 +08003425 @Override
chen xu0026ca62019-03-06 15:28:50 -08003426 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 final Phone phone = getPhone(subId);
3430 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003431 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003432 } finally {
3433 Binder.restoreCallingIdentity(identity);
3434 }
3435 }
3436
3437 @Override
chen xu0026ca62019-03-06 15:28:50 -08003438 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003439 final long identity = Binder.clearCallingIdentity();
3440 try {
3441 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003442 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003443 } finally {
3444 Binder.restoreCallingIdentity(identity);
3445 }
3446 }
3447
chen xu651eec72018-11-11 19:03:44 -08003448 @Override
chen xu864e11c2018-12-06 22:10:03 -08003449 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3450 if (!isSubscriptionMccMnc) {
3451 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3452 }
chen xu651eec72018-11-11 19:03:44 -08003453 final Phone phone = PhoneFactory.getPhone(slotIndex);
3454 if (phone == null) {
3455 return TelephonyManager.UNKNOWN_CARRIER_ID;
3456 }
3457 final long identity = Binder.clearCallingIdentity();
3458 try {
3459 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3460 } finally {
3461 Binder.restoreCallingIdentity(identity);
3462 }
3463 }
3464
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003465 //
3466 // Internal helper methods.
3467 //
3468
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003469 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003470 * Make sure the caller is the calling package itself
3471 *
3472 * @throws SecurityException if the caller is not the calling package
3473 */
3474 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3475 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003476 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3477 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003478 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003479 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003480 } catch (PackageManager.NameNotFoundException e) {
3481 // packageUid is -1
3482 }
3483 if (packageUid != callingUid) {
3484 throw new SecurityException(message + ": Package " + callingPackage
3485 + " does not belong to " + callingUid);
3486 }
3487 }
3488
3489 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003490 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3491 *
3492 * @throws SecurityException if the caller does not have the required permission
3493 */
3494 private void enforceModifyPermission() {
3495 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3496 }
3497
Shuo Qian3b6ee772019-11-13 17:43:31 -08003498 private void enforceActiveEmergencySessionPermission() {
3499 mApp.enforceCallingOrSelfPermission(
3500 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3501 }
3502
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003503 /**
3504 * Make sure the caller has the CALL_PHONE permission.
3505 *
3506 * @throws SecurityException if the caller does not have the required permission
3507 */
3508 private void enforceCallPermission() {
3509 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3510 }
3511
paulhu5a773602019-08-23 19:17:33 +08003512 private void enforceSettingsPermission() {
3513 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003514 }
3515
Michele Berionne5e411512020-11-13 02:36:59 +00003516 private void enforceRebootPermission() {
3517 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3518 }
3519
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003520 private String createTelUrl(String number) {
3521 if (TextUtils.isEmpty(number)) {
3522 return null;
3523 }
3524
Jake Hambye994d462014-02-03 13:10:13 -08003525 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003526 }
3527
Ihab Awadf9e92732013-12-05 18:02:52 -08003528 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003529 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3530 }
3531
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003532 private static void logv(String msg) {
3533 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3534 }
3535
Ihab Awadf9e92732013-12-05 18:02:52 -08003536 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003537 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3538 }
3539
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003540 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003541 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003542 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003543 }
3544
Sanket Padawe356d7632015-06-22 14:03:32 -07003545 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003546 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 final Phone phone = PhoneFactory.getPhone(slotIndex);
3550 if (phone == null) {
3551 return PhoneConstants.PHONE_TYPE_NONE;
3552 } else {
3553 return phone.getPhoneType();
3554 }
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003558 }
3559
3560 /**
3561 * Returns the CDMA ERI icon index to display
3562 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003563 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003564 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3565 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3566 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003567 }
3568
Sanket Padawe356d7632015-06-22 14:03:32 -07003569 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003570 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3571 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003572 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003573 mApp, subId, callingPackage, callingFeatureId,
3574 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003575 return -1;
3576 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003577
3578 final long identity = Binder.clearCallingIdentity();
3579 try {
3580 final Phone phone = getPhone(subId);
3581 if (phone != null) {
3582 return phone.getCdmaEriIconIndex();
3583 } else {
3584 return -1;
3585 }
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003589 }
3590
3591 /**
3592 * Returns the CDMA ERI icon mode,
3593 * 0 - ON
3594 * 1 - FLASHING
3595 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003596 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003597 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3598 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3599 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003600 }
3601
Sanket Padawe356d7632015-06-22 14:03:32 -07003602 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003603 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3604 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003605 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003606 mApp, subId, callingPackage, callingFeatureId,
3607 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003608 return -1;
3609 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003610
3611 final long identity = Binder.clearCallingIdentity();
3612 try {
3613 final Phone phone = getPhone(subId);
3614 if (phone != null) {
3615 return phone.getCdmaEriIconMode();
3616 } else {
3617 return -1;
3618 }
3619 } finally {
3620 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003622 }
3623
3624 /**
3625 * Returns the CDMA ERI text,
3626 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003627 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003628 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3629 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3630 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003631 }
3632
Sanket Padawe356d7632015-06-22 14:03:32 -07003633 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003634 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3635 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003636 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003637 mApp, subId, callingPackage, callingFeatureId,
3638 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003639 return null;
3640 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003641
3642 final long identity = Binder.clearCallingIdentity();
3643 try {
3644 final Phone phone = getPhone(subId);
3645 if (phone != null) {
3646 return phone.getCdmaEriText();
3647 } else {
3648 return null;
3649 }
3650 } finally {
3651 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003653 }
3654
3655 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003656 * Returns the CDMA MDN.
3657 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003658 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003659 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3661 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662
3663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003666 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003667 return phone.getLine1Number();
3668 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003669 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003670 return null;
3671 }
3672 } finally {
3673 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003674 }
3675 }
3676
3677 /**
3678 * Returns the CDMA MIN.
3679 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003680 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003681 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3683 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003684
3685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 final Phone phone = getPhone(subId);
3688 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3689 return phone.getCdmaMin();
3690 } else {
3691 return null;
3692 }
3693 } finally {
3694 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003695 }
3696 }
3697
Hall Liud892bec2018-11-30 14:51:45 -08003698 @Override
3699 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3700 INumberVerificationCallback callback, String callingPackage) {
3701 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3702 != PERMISSION_GRANTED) {
3703 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3704 }
3705 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3706
3707 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3708 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003709 throw new SecurityException("Calling package must be configured in the device config: "
3710 + "calling package: " + callingPackage
3711 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003712 }
3713
3714 if (range == null) {
3715 throw new NullPointerException("Range must be non-null");
3716 }
3717
3718 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003719 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003720
3721 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3722 }
3723
Junda Liuca05d5d2014-08-14 22:36:34 -07003724 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003725 * Returns true if CDMA provisioning needs to run.
3726 */
3727 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728 final long identity = Binder.clearCallingIdentity();
3729 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003730 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003731 } finally {
3732 Binder.restoreCallingIdentity(identity);
3733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003734 }
3735
3736 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003737 * Sets the voice mail number of a given subId.
3738 */
3739 @Override
3740 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003741 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3742 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743
3744 final long identity = Binder.clearCallingIdentity();
3745 try {
3746 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3747 new Pair<String, String>(alphaTag, number), new Integer(subId));
3748 return success;
3749 } finally {
3750 Binder.restoreCallingIdentity(identity);
3751 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003752 }
3753
Ta-wei Yen87c49842016-05-13 21:19:52 -07003754 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003755 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3756 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003757 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3758 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003759 if (!TextUtils.equals(callingPackage, systemDialer)) {
3760 throw new SecurityException("caller must be system dialer");
3761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003762
3763 final long identity = Binder.clearCallingIdentity();
3764 try {
3765 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3766 if (phoneAccountHandle == null) {
3767 return null;
3768 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003769 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003770 } finally {
3771 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003772 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003773 }
3774
3775 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003776 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3777 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003778 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003779 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003780 mApp, subId, callingPackage, callingFeatureId,
3781 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003782 return null;
3783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003784
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003785 final long identity = Binder.clearCallingIdentity();
3786 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003787 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003788 } finally {
3789 Binder.restoreCallingIdentity(identity);
3790 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003791 }
3792
3793 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003794 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3795 VisualVoicemailSmsFilterSettings settings) {
3796 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797
3798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003801 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003802 } finally {
3803 Binder.restoreCallingIdentity(identity);
3804 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003805 }
3806
3807 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003808 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3809 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810
3811 final long identity = Binder.clearCallingIdentity();
3812 try {
3813 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003814 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003815 } finally {
3816 Binder.restoreCallingIdentity(identity);
3817 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003818 }
3819
3820 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003821 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3822 String callingPackage, int subId) {
3823 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003824
3825 final long identity = Binder.clearCallingIdentity();
3826 try {
3827 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003828 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003829 } finally {
3830 Binder.restoreCallingIdentity(identity);
3831 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003832 }
3833
3834 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003835 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003836 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003837
3838 final long identity = Binder.clearCallingIdentity();
3839 try {
3840 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003841 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003842 } finally {
3843 Binder.restoreCallingIdentity(identity);
3844 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003845 }
3846
3847 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003848 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3849 String callingAttributionTag, int subId, String number, int port, String text,
3850 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003851 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003852 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003853 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003854 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003855 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3856 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003857 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003858
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003859 /**
fionaxu0152e512016-11-14 13:36:14 -08003860 * Sets the voice activation state of a given subId.
3861 */
3862 @Override
3863 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3865 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003866
3867 final long identity = Binder.clearCallingIdentity();
3868 try {
3869 final Phone phone = getPhone(subId);
3870 if (phone != null) {
3871 phone.setVoiceActivationState(activationState);
3872 } else {
3873 loge("setVoiceActivationState fails with invalid subId: " + subId);
3874 }
3875 } finally {
3876 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003877 }
3878 }
3879
3880 /**
3881 * Sets the data activation state of a given subId.
3882 */
3883 @Override
3884 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3886 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003887
3888 final long identity = Binder.clearCallingIdentity();
3889 try {
3890 final Phone phone = getPhone(subId);
3891 if (phone != null) {
3892 phone.setDataActivationState(activationState);
3893 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003894 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895 }
3896 } finally {
3897 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003898 }
3899 }
3900
3901 /**
3902 * Returns the voice activation state of a given subId.
3903 */
3904 @Override
3905 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003906 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003907
fionaxu0152e512016-11-14 13:36:14 -08003908 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909 final long identity = Binder.clearCallingIdentity();
3910 try {
3911 if (phone != null) {
3912 return phone.getVoiceActivationState();
3913 } else {
3914 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3915 }
3916 } finally {
3917 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003918 }
3919 }
3920
3921 /**
3922 * Returns the data activation state of a given subId.
3923 */
3924 @Override
3925 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003926 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003927
fionaxu0152e512016-11-14 13:36:14 -08003928 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003929 final long identity = Binder.clearCallingIdentity();
3930 try {
3931 if (phone != null) {
3932 return phone.getDataActivationState();
3933 } else {
3934 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3935 }
3936 } finally {
3937 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003938 }
3939 }
3940
3941 /**
Wink Saville36469e72014-06-11 15:17:00 -07003942 * Returns the unread count of voicemails for a subId
3943 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003944 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003945 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3946 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003947 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003948 mApp, subId, callingPackage, callingFeatureId,
3949 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003950 return 0;
3951 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 final Phone phone = getPhone(subId);
3955 if (phone != null) {
3956 return phone.getVoiceMessageCount();
3957 } else {
3958 return 0;
3959 }
3960 } finally {
3961 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003963 }
3964
3965 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003966 * returns true, if the device is in a state where both voice and data
3967 * are supported simultaneously. This can change based on location or network condition.
3968 */
3969 @Override
3970 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003971 final long identity = Binder.clearCallingIdentity();
3972 try {
3973 final Phone phone = getPhone(subId);
3974 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3975 } finally {
3976 Binder.restoreCallingIdentity(identity);
3977 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003978 }
3979
3980 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003981 * Send the dialer code if called from the current default dialer or the caller has
3982 * carrier privilege.
3983 * @param inputCode The dialer code to send
3984 */
3985 @Override
3986 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003987 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003988 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003989 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3990 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003991 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003992 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003993 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003995
3996 final long identity = Binder.clearCallingIdentity();
3997 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003998 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003999 } finally {
4000 Binder.restoreCallingIdentity(identity);
4001 }
fionaxu235cc5e2017-03-06 22:25:57 -08004002 }
4003
Pengquan Menga1bb6272018-09-06 09:59:22 -07004004 @Override
4005 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004006 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004007 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004008 mApp, subId, "getNetworkSelectionMode");
4009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 if (!isActiveSubscription(subId)) {
4012 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4013 }
4014 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4015 } finally {
4016 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004017 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004018 }
4019
Brad Ebinger35c841c2018-10-01 10:40:55 -07004020 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004021 public boolean isInEmergencySmsMode() {
4022 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4023 final long identity = Binder.clearCallingIdentity();
4024 try {
4025 for (Phone phone : PhoneFactory.getPhones()) {
4026 if (phone.isInEmergencySmsMode()) {
4027 return true;
4028 }
4029 }
4030 } finally {
4031 Binder.restoreCallingIdentity(identity);
4032 }
4033 return false;
4034 }
4035
shilu366312e2019-12-17 09:28:10 -08004036 /**
4037 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4038 * @param subId The subscription to use to check the configuration.
4039 * @param c The callback that will be used to send the result.
4040 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004041 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004042 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4043 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004044 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004045 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004046
4047 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4048 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4049 "IMS not available on device.");
4050 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004051 final long token = Binder.clearCallingIdentity();
4052 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004053 int slotId = getSlotIndexOrException(subId);
4054 verifyImsMmTelConfiguredOrThrow(slotId);
4055 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004056 } catch (ImsException e) {
4057 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 } finally {
4059 Binder.restoreCallingIdentity(token);
4060 }
4061 }
4062
shilu366312e2019-12-17 09:28:10 -08004063 /**
4064 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4065 * @param subId The subscription to use to check the configuration.
4066 * @param c The callback that will be used to send the result.
4067 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004068 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004069 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004070 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004071 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004072 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4073 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4074 }
Meng Wangafbc5852019-09-19 17:37:13 -07004075 final long token = Binder.clearCallingIdentity();
4076 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004077 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4078 .removeRegistrationCallbackForSubscription(c, subId);
4079 } catch (ImsException e) {
4080 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4081 + "is inactive, ignoring unregister.");
4082 // If the subscription is no longer active, just return, since the callback
4083 // will already have been removed internally.
4084 } finally {
4085 Binder.restoreCallingIdentity(token);
4086 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004087 }
4088
Brad Ebingera34a6c22019-10-22 17:36:18 -07004089 /**
4090 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4091 */
4092 @Override
4093 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4094 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4095 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4096 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4097 "IMS not available on device.");
4098 }
4099 final long token = Binder.clearCallingIdentity();
4100 try {
4101 Phone phone = getPhone(subId);
4102 if (phone == null) {
4103 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4104 + subId + "'");
4105 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4106 }
4107 phone.getImsRegistrationState(regState -> {
4108 try {
4109 consumer.accept((regState == null)
4110 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4111 } catch (RemoteException e) {
4112 // Ignore if the remote process is no longer available to call back.
4113 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4114 }
4115 });
4116 } finally {
4117 Binder.restoreCallingIdentity(token);
4118 }
4119 }
4120
4121 /**
4122 * Get the transport type for the IMS service registration state.
4123 */
4124 @Override
4125 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004126 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004127 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004128 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4129 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4130 "IMS not available on device.");
4131 }
4132 final long token = Binder.clearCallingIdentity();
4133 try {
4134 Phone phone = getPhone(subId);
4135 if (phone == null) {
4136 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4137 + subId + "'");
4138 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4139 }
4140 phone.getImsRegistrationTech(regTech -> {
4141 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4142 int regTechConverted = (regTech == null)
4143 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4144 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4145 regTechConverted);
4146 try {
4147 consumer.accept(regTechConverted);
4148 } catch (RemoteException e) {
4149 // Ignore if the remote process is no longer available to call back.
4150 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4151 }
4152 });
4153 } finally {
4154 Binder.restoreCallingIdentity(token);
4155 }
4156 }
4157
shilu366312e2019-12-17 09:28:10 -08004158 /**
4159 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4160 * @param subId The subscription to use to check the configuration.
4161 * @param c The callback that will be used to send the result.
4162 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004163 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004164 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4165 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004166 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004167 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004168 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4169 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4170 "IMS not available on device.");
4171 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004172 final long token = Binder.clearCallingIdentity();
4173 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004174 int slotId = getSlotIndexOrException(subId);
4175 verifyImsMmTelConfiguredOrThrow(slotId);
4176 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004177 } catch (ImsException e) {
4178 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004179 } finally {
4180 Binder.restoreCallingIdentity(token);
4181 }
4182 }
4183
shilu366312e2019-12-17 09:28:10 -08004184 /**
4185 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4186 * @param subId The subscription to use to check the configuration.
4187 * @param c The callback that will be used to send the result.
4188 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004189 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004190 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004191 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004192 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004193 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4194 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4195 }
Meng Wangafbc5852019-09-19 17:37:13 -07004196
4197 final long token = Binder.clearCallingIdentity();
4198 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004199 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004200 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004201 } catch (ImsException e) {
4202 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4203 + "is inactive, ignoring unregister.");
4204 // If the subscription is no longer active, just return, since the callback
4205 // will already have been removed internally.
4206 } finally {
4207 Binder.restoreCallingIdentity(token);
4208 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004209 }
4210
4211 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004212 public boolean isCapable(int subId, int capability, int regTech) {
4213 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 final long token = Binder.clearCallingIdentity();
4215 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004216 int slotId = getSlotIndexOrException(subId);
4217 verifyImsMmTelConfiguredOrThrow(slotId);
4218 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4219 } catch (com.android.ims.ImsException e) {
4220 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4221 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004222 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004223 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4224 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 } finally {
4226 Binder.restoreCallingIdentity(token);
4227 }
4228 }
4229
4230 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004231 public boolean isAvailable(int subId, int capability, int regTech) {
4232 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004233 final long token = Binder.clearCallingIdentity();
4234 try {
4235 Phone phone = getPhone(subId);
4236 if (phone == null) return false;
4237 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004238 } catch (com.android.ims.ImsException e) {
4239 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4240 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004241 } finally {
4242 Binder.restoreCallingIdentity(token);
4243 }
4244 }
4245
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004246 /**
4247 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4248 * subscription.
4249 * @param subId The subscription to use to check the configuration.
4250 * @param callback The callback that will be used to send the result.
4251 * @param capability The MmTelFeature capability that will be used to send the result.
4252 * @param transportType The transport type of the MmTelFeature capability.
4253 */
4254 @Override
4255 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4256 int transportType) {
4257 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004258 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4259 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4260 "IMS not available on device.");
4261 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004262 final long token = Binder.clearCallingIdentity();
4263 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004264 int slotId = getSlotIndex(subId);
4265 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4266 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4267 + subId + "'");
4268 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4269 }
4270 verifyImsMmTelConfiguredOrThrow(slotId);
4271 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4272 transportType, aBoolean -> {
4273 try {
4274 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4275 } catch (RemoteException e) {
4276 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4277 + "running. Ignore");
4278 }
4279 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004280 } catch (ImsException e) {
4281 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004282 } finally {
4283 Binder.restoreCallingIdentity(token);
4284 }
4285 }
4286
shilu366312e2019-12-17 09:28:10 -08004287 /**
4288 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4289 * @param subId The subscription to use to check the configuration.
4290 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 @Override
4292 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004293 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004294 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004295
Brad Ebinger35c841c2018-10-01 10:40:55 -07004296 final long token = Binder.clearCallingIdentity();
4297 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004298 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004299 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004300 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004301 } catch (ImsException e) {
4302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004303 } finally {
4304 Binder.restoreCallingIdentity(token);
4305 }
4306 }
4307
4308 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004309 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004311 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004312 final long identity = Binder.clearCallingIdentity();
4313 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004314 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004315 // This setting doesn't require an active ImsService connection, so do not verify. The
4316 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004317 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004318 } catch (ImsException e) {
4319 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
4323 }
4324
shilu366312e2019-12-17 09:28:10 -08004325 /**
4326 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4327 * @param subId The subscription to use to check the configuration.
4328 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004329 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004330 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004331 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004332 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004333 final long identity = Binder.clearCallingIdentity();
4334 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004335 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004336 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004337 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004338 } catch (ImsException e) {
4339 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004340 } finally {
4341 Binder.restoreCallingIdentity(identity);
4342 }
4343 }
4344
4345 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004346 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004348 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004349 final long identity = Binder.clearCallingIdentity();
4350 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004351 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004352 // This setting doesn't require an active ImsService connection, so do not verify. The
4353 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004354 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004355 } catch (ImsException e) {
4356 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004357 } finally {
4358 Binder.restoreCallingIdentity(identity);
4359 }
4360 }
4361
shilu366312e2019-12-17 09:28:10 -08004362 /**
4363 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4364 * @param subId The subscription to use to check the configuration.
4365 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004366 @Override
4367 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004368 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004369 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 final long identity = Binder.clearCallingIdentity();
4371 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004372 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004373 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004374 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004375 } catch (ImsException e) {
4376 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004377 } finally {
4378 Binder.restoreCallingIdentity(identity);
4379 }
4380 }
4381
4382 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004383 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004385 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 final long identity = Binder.clearCallingIdentity();
4387 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004388 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004389 // This setting doesn't require an active ImsService connection, so do not verify. The
4390 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004391 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004392 } catch (ImsException e) {
4393 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004394 } finally {
4395 Binder.restoreCallingIdentity(identity);
4396 }
4397 }
4398
shilu366312e2019-12-17 09:28:10 -08004399 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004400 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4401 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4402 * @param subId The subscription to use to check the configuration.
4403 */
4404 @Override
4405 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004406 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004407 mApp, subId, "isCrossSimCallingEnabledByUser");
4408 final long identity = Binder.clearCallingIdentity();
4409 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004410 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004411 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004412 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004413 } catch (ImsException e) {
4414 throw new ServiceSpecificException(e.getCode());
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
4417 }
4418 }
4419
4420 /**
4421 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4422 * Requires MODIFY_PHONE_STATE permission.
4423 * @param subId The subscription to use to check the configuration.
4424 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4425 * false otherwise
4426 */
4427 @Override
4428 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4430 "setCrossSimCallingEnabled");
4431 final long identity = Binder.clearCallingIdentity();
4432 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004433 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004434 // This setting doesn't require an active ImsService connection, so do not verify. The
4435 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004436 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004437 } catch (ImsException e) {
4438 throw new ServiceSpecificException(e.getCode());
4439 } finally {
4440 Binder.restoreCallingIdentity(identity);
4441 }
4442 }
4443
4444 /**
shilu366312e2019-12-17 09:28:10 -08004445 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4446 * @param subId The subscription to use to check the configuration.
4447 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004449
Brad Ebinger35c841c2018-10-01 10:40:55 -07004450 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004451 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004452 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004453 final long identity = Binder.clearCallingIdentity();
4454 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004455 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004456 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004457 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004458 } catch (ImsException e) {
4459 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004460 } finally {
4461 Binder.restoreCallingIdentity(identity);
4462 }
4463 }
4464
4465 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004466 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004468 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004469 final long identity = Binder.clearCallingIdentity();
4470 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004471 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004472 // This setting doesn't require an active ImsService connection, so do not verify. The
4473 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004474 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004475 } catch (ImsException e) {
4476 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004477 } finally {
4478 Binder.restoreCallingIdentity(identity);
4479 }
4480 }
4481
4482 @Override
4483 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4485 "setVoWiFiNonPersistent");
4486 final long identity = Binder.clearCallingIdentity();
4487 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004488 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004489 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004490 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004491 } catch (ImsException e) {
4492 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 } finally {
4494 Binder.restoreCallingIdentity(identity);
4495 }
4496 }
4497
shilu366312e2019-12-17 09:28:10 -08004498 /**
4499 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4500 * @param subId The subscription to use to check the configuration.
4501 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004502 @Override
4503 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004504 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004505 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004506 final long identity = Binder.clearCallingIdentity();
4507 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004508 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004509 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004510 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004511 } catch (ImsException e) {
4512 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
4516 }
4517
4518 @Override
4519 public void setVoWiFiModeSetting(int subId, int mode) {
4520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4521 "setVoWiFiModeSetting");
4522 final long identity = Binder.clearCallingIdentity();
4523 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004524 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004525 // This setting doesn't require an active ImsService connection, so do not verify. The
4526 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004527 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004528 } catch (ImsException e) {
4529 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004530 } finally {
4531 Binder.restoreCallingIdentity(identity);
4532 }
4533 }
4534
4535 @Override
4536 public int getVoWiFiRoamingModeSetting(int subId) {
4537 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4538 final long identity = Binder.clearCallingIdentity();
4539 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004540 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004541 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004542 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004543 } catch (ImsException e) {
4544 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004545 } finally {
4546 Binder.restoreCallingIdentity(identity);
4547 }
4548 }
4549
4550 @Override
4551 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4553 "setVoWiFiRoamingModeSetting");
4554 final long identity = Binder.clearCallingIdentity();
4555 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004556 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004557 // This setting doesn't require an active ImsService connection, so do not verify. The
4558 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004559 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004560 } catch (ImsException e) {
4561 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004562 } finally {
4563 Binder.restoreCallingIdentity(identity);
4564 }
4565 }
4566
4567 @Override
4568 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4570 "setRttCapabilityEnabled");
4571 final long identity = Binder.clearCallingIdentity();
4572 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004573 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004574 // This setting doesn't require an active ImsService connection, so do not verify. The
4575 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004576 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004577 } catch (ImsException e) {
4578 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
4582 }
4583
shilu366312e2019-12-17 09:28:10 -08004584 /**
4585 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4586 * @param subId The subscription to use to check the configuration.
4587 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004588 @Override
4589 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004590 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004591 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004592 final long identity = Binder.clearCallingIdentity();
4593 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004594 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004595 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004596 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004597 } catch (ImsException e) {
4598 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004599 } finally {
4600 Binder.restoreCallingIdentity(identity);
4601 }
4602 }
4603
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004604 @Override
4605 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4606 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004607
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004608 final long identity = Binder.clearCallingIdentity();
4609 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004610 if (!isImsAvailableOnDevice()) {
4611 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4612 "IMS not available on device.");
4613 }
4614 int slotId = getSlotIndexOrException(subId);
4615 verifyImsMmTelConfiguredOrThrow(slotId);
4616 ImsManager.getInstance(mApp, slotId)
4617 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004618 } catch (ImsException e) {
4619 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004620 } finally {
4621 Binder.restoreCallingIdentity(identity);
4622 }
4623 }
4624
4625 @Override
4626 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4627 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004628
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004629 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004630 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4631 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4632 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004633 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004634 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004635 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004636 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004637 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4638 + "is inactive, ignoring unregister.");
4639 // If the subscription is no longer active, just return, since the callback will already
4640 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004641 } finally {
4642 Binder.restoreCallingIdentity(identity);
4643 }
4644 }
4645
joonhunshincffb7fc2021-11-28 07:32:01 +00004646 @Override
4647 public void registerFeatureProvisioningChangedCallback(int subId,
4648 IFeatureProvisioningCallback callback) {
4649 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4650 mApp, subId, "registerFeatureProvisioningChangedCallback");
4651
4652 final long identity = Binder.clearCallingIdentity();
4653 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4654 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4655 }
4656
joonhunshin91bc1952022-04-29 08:47:15 +00004657 try {
4658 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4659 if (controller == null) {
4660 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4661 "Device does not support IMS");
4662 }
4663 controller.addFeatureProvisioningChangedCallback(subId, callback);
4664 } finally {
4665 Binder.restoreCallingIdentity(identity);
4666 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004667 }
4668
4669 @Override
4670 public void unregisterFeatureProvisioningChangedCallback(int subId,
4671 IFeatureProvisioningCallback callback) {
4672 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4673 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4674
4675 final long identity = Binder.clearCallingIdentity();
4676 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4677 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4678 }
4679
joonhunshin91bc1952022-04-29 08:47:15 +00004680 try {
4681 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4682 if (controller == null) {
4683 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4684 return;
4685 }
4686 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4687 } finally {
4688 Binder.restoreCallingIdentity(identity);
4689 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004690 }
allenwtsu99c623b2020-01-03 18:24:23 +08004691
4692 private void checkModifyPhoneStatePermission(int subId, String message) {
4693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4694 message);
4695 }
4696
allenwtsu99c623b2020-01-03 18:24:23 +08004697 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004698 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004699 boolean isProvisioned) {
4700 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4701
4702 final long identity = Binder.clearCallingIdentity();
4703 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004704 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4705 if (controller == null) {
4706 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4707 return;
4708 }
4709 controller.setRcsProvisioningStatusForCapability(
4710 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004711 } finally {
4712 Binder.restoreCallingIdentity(identity);
4713 }
allenwtsu99c623b2020-01-03 18:24:23 +08004714 }
4715
4716
4717 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004718 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4719 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4720 mApp, subId, "getRcsProvisioningStatusForCapability");
4721
allenwtsu99c623b2020-01-03 18:24:23 +08004722 final long identity = Binder.clearCallingIdentity();
4723 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004724 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4725 if (controller == null) {
4726 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4727
4728 // device does not support IMS, this method will return true always.
4729 return true;
4730 }
4731 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004732 } finally {
4733 Binder.restoreCallingIdentity(identity);
4734 }
4735 }
4736
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004737 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004738 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4739 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004740 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004741
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004742 final long identity = Binder.clearCallingIdentity();
4743 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004744 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4745 if (controller == null) {
4746 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4747 return;
4748 }
4749 controller.setImsProvisioningStatusForCapability(
4750 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004751 } finally {
4752 Binder.restoreCallingIdentity(identity);
4753 }
4754 }
4755
4756 @Override
4757 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004758 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4759 mApp, subId, "getProvisioningStatusForCapability");
4760
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004761 final long identity = Binder.clearCallingIdentity();
4762 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004763 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4764 if (controller == null) {
4765 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004766
joonhunshin91bc1952022-04-29 08:47:15 +00004767 // device does not support IMS, this method will return true always.
4768 return true;
4769 }
4770 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004771 } finally {
4772 Binder.restoreCallingIdentity(identity);
4773 }
4774 }
4775
4776 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004777 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4778 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4779 mApp, subId, "isProvisioningRequiredForCapability");
4780
4781 final long identity = Binder.clearCallingIdentity();
4782 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004783 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4784 if (controller == null) {
4785 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4786
4787 // device does not support IMS, this method will return false
4788 return false;
4789 }
4790 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004791 } finally {
4792 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004793 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004794 }
4795
4796 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004797 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4798 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4799 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004800
joonhunshincffb7fc2021-11-28 07:32:01 +00004801 final long identity = Binder.clearCallingIdentity();
4802 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004803 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4804 if (controller == null) {
4805 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4806
4807 // device does not support IMS, this method will return false
4808 return false;
4809 }
4810 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004811 } finally {
4812 Binder.restoreCallingIdentity(identity);
4813 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004814 }
4815
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004816 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004817 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004818 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4819 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4820 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004821 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4822 mApp, subId, "getImsProvisioningInt");
4823
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004824 final long identity = Binder.clearCallingIdentity();
4825 try {
4826 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004827 int slotId = getSlotIndex(subId);
4828 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4829 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4830 + subId + "' for key:" + key);
4831 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4832 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004833
joonhunshin91bc1952022-04-29 08:47:15 +00004834 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4835 if (controller == null) {
4836 loge("getImsProvisioningInt: Device does not support IMS");
4837
4838 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4839 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4840 }
4841 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004842 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4843 return retVal;
4844 }
4845
calvinpanb5a34062021-02-08 19:59:36 +08004846 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004847 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004848 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4849 + subId + "' for key:" + key);
4850 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004851 } finally {
4852 Binder.restoreCallingIdentity(identity);
4853 }
4854 }
4855
4856 @Override
4857 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4859 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4860 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004861 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4862 mApp, subId, "getImsProvisioningString");
4863
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004864 final long identity = Binder.clearCallingIdentity();
4865 try {
4866 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004867 int slotId = getSlotIndex(subId);
4868 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4869 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4870 + subId + "' for key:" + key);
4871 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4872 }
calvinpanb5a34062021-02-08 19:59:36 +08004873 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004874 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004875 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4876 + subId + "' for key:" + key);
4877 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004878 } finally {
4879 Binder.restoreCallingIdentity(identity);
4880 }
4881 }
4882
4883 @Override
4884 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004885 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4886 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4887 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4889 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004890
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004891 final long identity = Binder.clearCallingIdentity();
4892 try {
4893 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004894 int slotId = getSlotIndex(subId);
4895 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4896 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4897 + subId + "' for key:" + key);
4898 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4899 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004900
joonhunshin91bc1952022-04-29 08:47:15 +00004901 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4902 if (controller == null) {
4903 loge("setImsProvisioningInt: Device does not support IMS");
4904
4905 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
4906 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4907 }
4908 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00004909 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4910 return retVal;
4911 }
4912
calvinpanb5a34062021-02-08 19:59:36 +08004913 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4914 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004915 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004916 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004918 } finally {
4919 Binder.restoreCallingIdentity(identity);
4920 }
4921 }
4922
4923 @Override
4924 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004925 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4926 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4927 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4929 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004930 final long identity = Binder.clearCallingIdentity();
4931 try {
4932 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004933 int slotId = getSlotIndex(subId);
4934 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4935 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4936 + subId + "' for key:" + key);
4937 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4938 }
calvinpanb5a34062021-02-08 19:59:36 +08004939 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4940 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004941 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004942 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004943 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004944 } finally {
4945 Binder.restoreCallingIdentity(identity);
4946 }
4947 }
4948
Brad Ebinger919631e2021-06-02 17:46:35 -07004949 /**
4950 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4951 * for the given slot ID or no ImsResolver instance has been created.
4952 * @param slotId The slot ID that the IMS service is created for.
4953 * @throws ImsException If there is no ImsService configured for this slot.
4954 */
4955 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4956 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4957 ImsFeature.FEATURE_MMTEL)) {
4958 throw new ImsException("This subscription does not support MMTEL over IMS",
4959 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4960 }
4961 }
4962
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004963 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004964 int slotId = SubscriptionManager.getSlotIndex(subId);
4965 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004966 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4967 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004968 }
4969 return slotId;
4970 }
4971
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004972 private int getSlotIndex(int subId) {
4973 int slotId = SubscriptionManager.getSlotIndex(subId);
4974 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4975 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4976 }
4977 return slotId;
4978 }
4979
Wink Saville36469e72014-06-11 15:17:00 -07004980 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004981 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004982 */
4983 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004984 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4985 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004986 try {
4987 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4988 } catch (SecurityException se) {
4989 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4990 throw new SecurityException("Package " + callingPackage + " does not belong to "
4991 + Binder.getCallingUid());
4992 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004993 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004994 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004995 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004996 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004997 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004998 mApp, subId, callingPackage, callingFeatureId,
4999 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005000 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5001 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003 final long identity = Binder.clearCallingIdentity();
5004 try {
5005 final Phone phone = getPhone(subId);
5006 if (phone != null) {
5007 return phone.getServiceState().getDataNetworkType();
5008 } else {
5009 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5010 }
5011 } finally {
5012 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005013 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005014 }
5015
5016 /**
5017 * Returns the data network type
5018 */
5019 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005020 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yudf049d72022-12-02 22:48:35 -08005021 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005022 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005023 }
5024
5025 /**
5026 * Returns the data network type for a subId
5027 */
5028 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005029 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5030 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005031 String functionName = "getDataNetworkTypeForSubscriber";
5032 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5033 mApp, functionName)) {
5034 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5035 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5036 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5037 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005038 }
5039
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005040 final long identity = Binder.clearCallingIdentity();
5041 try {
5042 final Phone phone = getPhone(subId);
5043 if (phone != null) {
5044 return phone.getServiceState().getDataNetworkType();
5045 } else {
5046 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5047 }
5048 } finally {
5049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005051 }
5052
5053 /**
Wink Saville36469e72014-06-11 15:17:00 -07005054 * Returns the Voice network type for a subId
5055 */
5056 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005057 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5058 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005059 String functionName = "getVoiceNetworkTypeForSubscriber";
5060 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5061 mApp, functionName)) {
5062 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5063 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5064 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5065 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005066 }
5067
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005068 final long identity = Binder.clearCallingIdentity();
5069 try {
5070 final Phone phone = getPhone(subId);
5071 if (phone != null) {
5072 return phone.getServiceState().getVoiceNetworkType();
5073 } else {
5074 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5075 }
5076 } finally {
5077 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005078 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005079 }
5080
5081 /**
5082 * @return true if a ICC card is present
5083 */
5084 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005085 // FIXME Make changes to pass defaultSimId of type int
Jack Yudf049d72022-12-02 22:48:35 -08005086 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005087 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005088 }
5089
5090 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005091 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005092 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005093 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005094 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 final long identity = Binder.clearCallingIdentity();
5096 try {
5097 final Phone phone = PhoneFactory.getPhone(slotIndex);
5098 if (phone != null) {
5099 return phone.getIccCard().hasIccCard();
5100 } else {
5101 return false;
5102 }
5103 } finally {
5104 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005106 }
5107
5108 /**
5109 * Return if the current radio is LTE on CDMA. This
5110 * is a tri-state return value as for a period of time
5111 * the mode may be unknown.
5112 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005113 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005114 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005115 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005116 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005117 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005118 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5119 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5120 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005121 }
5122
Sanket Padawe356d7632015-06-22 14:03:32 -07005123 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005124 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5125 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005126 try {
5127 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5128 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005129 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5130 }
5131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132 final long identity = Binder.clearCallingIdentity();
5133 try {
5134 final Phone phone = getPhone(subId);
5135 if (phone == null) {
5136 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5137 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005138 return TelephonyProperties.lte_on_cdma_device()
5139 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140 }
5141 } finally {
5142 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005143 }
Wink Saville36469e72014-06-11 15:17:00 -07005144 }
5145
Wink Saville36469e72014-06-11 15:17:00 -07005146 /**
5147 * {@hide}
5148 * Returns Default subId, 0 in the case of single standby.
5149 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005150 private int getDefaultSubscription() {
Jack Yudf049d72022-12-02 22:48:35 -08005151 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005152 }
5153
Shishir Agrawala9f32182016-04-12 12:00:16 -07005154 private int getSlotForDefaultSubscription() {
Jack Yudf049d72022-12-02 22:48:35 -08005155 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005156 }
5157
Wink Savilleb564aae2014-10-23 10:18:09 -07005158 private int getPreferredVoiceSubscription() {
Jack Yudf049d72022-12-02 22:48:35 -08005159 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005160 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005161
Pengquan Menge92a50d2018-09-21 15:54:48 -07005162 private boolean isActiveSubscription(int subId) {
Jack Yudf049d72022-12-02 22:48:35 -08005163 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5164 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5165 mApp.getOpPackageName(), mApp.getFeatureId());
5166 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005167 return mSubscriptionController.isActiveSubId(subId);
5168 }
5169
Ihab Awadf2177b72013-11-25 13:33:23 -08005170 /**
5171 * @see android.telephony.TelephonyManager.WifiCallingChoices
5172 */
5173 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 final long identity = Binder.clearCallingIdentity();
5175 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005176 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5178 getWhenToMakeWifiCallsDefaultPreference());
5179 } finally {
5180 Binder.restoreCallingIdentity(identity);
5181 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005182 }
5183
5184 /**
5185 * @see android.telephony.TelephonyManager.WifiCallingChoices
5186 */
5187 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188 final long identity = Binder.clearCallingIdentity();
5189 try {
5190 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005191 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5193 } finally {
5194 Binder.restoreCallingIdentity(identity);
5195 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005196 }
5197
Sailesh Nepald1e68152013-12-12 19:08:02 -08005198 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005199 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005200 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005201 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005202
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005203 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5204 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5205 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005206 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005207 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5208 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005209 }
5210 return PhoneFactory.getPhone(phoneId);
5211 }
5212
Shishir Agrawal566b7612013-10-28 14:41:00 -07005213 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005214 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005215 @NonNull IccLogicalChannelRequest request) {
5216 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5217 /*message=*/ "iccOpenLogicalChannel");
5218
5219 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5220 // Verify that the callingPackage in the request belongs to the calling UID
5221 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5222
5223 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005224 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005225
Rambo Wanga1782702021-11-10 20:15:19 -08005226 private Phone getPhoneFromValidIccLogicalChannelRequest(
5227 @NonNull IccLogicalChannelRequest request, String message) {
5228 Phone phone;
5229 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5231 mApp, request.subId, message);
5232 phone = getPhoneFromSubId(request.subId);
5233 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5234 enforceModifyPermission();
5235 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5236 } else {
5237 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005238 }
Rambo Wanga1782702021-11-10 20:15:19 -08005239 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005240 }
5241
5242 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005243 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 final long identity = Binder.clearCallingIdentity();
5245 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005246 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005248 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5249 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005250 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5251 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 loge("The calling package is not allowed to access ISD-R.");
5253 throw new SecurityException(
5254 "The calling package is not allowed to access ISD-R.");
5255 }
Derek Tan740e1672017-06-27 14:56:27 -07005256 }
Derek Tan740e1672017-06-27 14:56:27 -07005257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005259 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5260 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 return response;
5262 } finally {
5263 Binder.restoreCallingIdentity(identity);
5264 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005265 }
5266
5267 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005268 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5269 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5270 /*message=*/"iccCloseLogicalChannel");
5271
5272 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5273
5274 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005275 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005276
Rambo Wanga1782702021-11-10 20:15:19 -08005277 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5278 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005279 // before this feature is enabled, this API should only return false if
5280 // the operation fails instead of throwing runtime exception for
5281 // backward-compatibility.
5282 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5283 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 final long identity = Binder.clearCallingIdentity();
5285 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005286 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005287 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 }
Chen Xue9d737e2022-01-01 23:41:31 -08005289 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005290 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005291 Boolean success = false;
5292 if (result instanceof RuntimeException) {
5293 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005294 if (shouldThrowExceptionOnFailure) {
5295 throw (RuntimeException) result;
5296 } else {
5297 return false;
5298 }
Chen Xue9d737e2022-01-01 23:41:31 -08005299 } else if (result instanceof Boolean) {
5300 success = (Boolean) result;
5301 } else {
5302 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5303 }
Rambo Wanga1782702021-11-10 20:15:19 -08005304 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 return success;
5306 } finally {
5307 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005308 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005309 }
5310
5311 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005312 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005313 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5315 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005316 if (DBG) {
5317 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5318 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5319 + p3 + " data=" + data);
5320 }
5321 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5322 command, p1, p2, p3, data);
5323 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005324
Jordan Liu4c733742019-02-28 12:03:40 -08005325 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005326 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5327 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005328 enforceModifyPermission();
5329 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005330 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5331 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5332 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005333 }
5334 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005335 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5336 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005337 }
5338
5339 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5340 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 final long identity = Binder.clearCallingIdentity();
5342 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005343 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005344 return "";
5345 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005347 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005348 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5349 null /* workSource */);
5350 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 // Append the returned status code to the end of the response payload.
5353 String s = Integer.toHexString(
5354 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5355 if (response.payload != null) {
5356 s = IccUtils.bytesToHexString(response.payload) + s;
5357 }
5358 return s;
5359 } finally {
5360 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005361 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005362 }
Jake Hambye994d462014-02-03 13:10:13 -08005363
Evan Charltonc66da362014-05-16 14:06:40 -07005364 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005365 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5366 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5368 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005370 if (DBG) {
5371 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5372 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5373 }
5374 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5375 cla, command, p1, p2, p3, data);
5376 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005377
Jordan Liu4c733742019-02-28 12:03:40 -08005378 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005379 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5380 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005381 enforceModifyPermission();
5382 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5383 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005384 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5385 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5386 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005387 }
5388
5389 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005390 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5391 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005392 }
5393
5394 // open APDU basic channel assuming the caller has sufficient permissions
5395 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5396 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 final long identity = Binder.clearCallingIdentity();
5398 try {
5399 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5400 && TextUtils.equals(ISDR_AID, data)) {
5401 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005402 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5403 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 if (bestComponent == null
5405 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5406 loge("The calling package is not allowed to select ISD-R.");
5407 throw new SecurityException(
5408 "The calling package is not allowed to select ISD-R.");
5409 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005410 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005411
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005412 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005413 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5414 null /* workSource */);
5415 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417 // Append the returned status code to the end of the response payload.
5418 String s = Integer.toHexString(
5419 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5420 if (response.payload != null) {
5421 s = IccUtils.bytesToHexString(response.payload) + s;
5422 }
5423 return s;
5424 } finally {
5425 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005426 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005427 }
5428
5429 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005430 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005431 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5433 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005434
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435 final long identity = Binder.clearCallingIdentity();
5436 try {
5437 if (DBG) {
5438 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5439 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5440 }
5441
5442 IccIoResult response =
5443 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5444 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5445 subId);
5446
5447 if (DBG) {
5448 log("Exchange SIM_IO [R]" + response);
5449 }
5450
5451 byte[] result = null;
5452 int length = 2;
5453 if (response.payload != null) {
5454 length = 2 + response.payload.length;
5455 result = new byte[length];
5456 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5457 } else {
5458 result = new byte[length];
5459 }
5460
5461 result[length - 1] = (byte) response.sw2;
5462 result[length - 2] = (byte) response.sw1;
5463 return result;
5464 } finally {
5465 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005466 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005467 }
5468
Nathan Haroldb3014052017-01-25 15:57:32 -08005469 /**
5470 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5471 * on a particular subscription
5472 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005473 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5474 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005476 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005477 return null;
5478 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479
5480 final long identity = Binder.clearCallingIdentity();
5481 try {
5482 if (appType != TelephonyManager.APPTYPE_USIM
5483 && appType != TelephonyManager.APPTYPE_SIM) {
5484 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5485 return null;
5486 }
5487 Object response = sendRequest(
5488 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5489 if (response instanceof String[]) {
5490 return (String[]) response;
5491 }
yincheng zhao2737e882019-09-06 17:06:54 -07005492 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005494 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 } finally {
5496 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005497 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005498 }
5499
yincheng zhao2737e882019-09-06 17:06:54 -07005500 /**
5501 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5502 * subscription.
5503 *
5504 * @param subId the id of the subscription.
5505 * @param appType the uicc app type, must be USIM or SIM.
5506 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5507 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005508 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005509 * @return number of fplmns that is successfully written to the SIM.
5510 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005511 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5512 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5514 mApp, subId, "setForbiddenPlmns");
5515
yincheng zhao2737e882019-09-06 17:06:54 -07005516 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5517 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5518 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5519 }
5520 if (fplmns == null) {
5521 throw new IllegalArgumentException("Fplmn List provided is null");
5522 }
5523 for (String fplmn : fplmns) {
5524 if (!CellIdentity.isValidPlmn(fplmn)) {
5525 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5526 }
5527 }
5528 final long identity = Binder.clearCallingIdentity();
5529 try {
5530 Object response = sendRequest(
5531 CMD_SET_FORBIDDEN_PLMNS,
5532 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5533 subId);
5534 return (int) response;
5535 } finally {
5536 Binder.restoreCallingIdentity(identity);
5537 }
5538 }
5539
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005540 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005541 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5543 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545 final long identity = Binder.clearCallingIdentity();
5546 try {
5547 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5548 if (response.payload == null) {
5549 return "";
5550 }
Evan Charltonc66da362014-05-16 14:06:40 -07005551
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005552 // Append the returned status code to the end of the response payload.
5553 String s = Integer.toHexString(
5554 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5555 s = IccUtils.bytesToHexString(response.payload) + s;
5556 return s;
5557 } finally {
5558 Binder.restoreCallingIdentity(identity);
5559 }
Evan Charltonc66da362014-05-16 14:06:40 -07005560 }
5561
Jake Hambye994d462014-02-03 13:10:13 -08005562 /**
5563 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5564 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5565 *
5566 * @param itemID the ID of the item to read
5567 * @return the NV item as a String, or null on error.
5568 */
5569 @Override
5570 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005571 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5573 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574
5575 final long identity = Binder.clearCallingIdentity();
5576 try {
5577 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005578 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5580 return value;
5581 } finally {
5582 Binder.restoreCallingIdentity(identity);
5583 }
Jake Hambye994d462014-02-03 13:10:13 -08005584 }
5585
5586 /**
5587 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5588 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5589 *
5590 * @param itemID the ID of the item to read
5591 * @param itemValue the value to write, as a String
5592 * @return true on success; false on any failure
5593 */
5594 @Override
5595 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005596 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5598 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599
5600 final long identity = Binder.clearCallingIdentity();
5601 try {
5602 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5603 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005604 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005605 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5606 return success;
5607 } finally {
5608 Binder.restoreCallingIdentity(identity);
5609 }
Jake Hambye994d462014-02-03 13:10:13 -08005610 }
5611
5612 /**
5613 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5614 * Used for device configuration by some CDMA operators.
5615 *
5616 * @param preferredRoamingList byte array containing the new PRL
5617 * @return true on success; false on any failure
5618 */
5619 @Override
5620 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5622 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623
5624 final long identity = Binder.clearCallingIdentity();
5625 try {
5626 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5627 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5628 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5629 return success;
5630 } finally {
5631 Binder.restoreCallingIdentity(identity);
5632 }
Jake Hambye994d462014-02-03 13:10:13 -08005633 }
5634
5635 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005636 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005637 * Used for device configuration by some CDMA operators.
5638 *
chen xu6dac5ab2018-10-26 17:39:23 -07005639 * @param slotIndex - device slot.
5640 *
Jake Hambye994d462014-02-03 13:10:13 -08005641 * @return true on success; false on any failure
5642 */
5643 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005644 public boolean resetModemConfig(int slotIndex) {
5645 Phone phone = PhoneFactory.getPhone(slotIndex);
5646 if (phone != null) {
5647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5648 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649
chen xu6dac5ab2018-10-26 17:39:23 -07005650 final long identity = Binder.clearCallingIdentity();
5651 try {
5652 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5653 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5654 return success;
5655 } finally {
5656 Binder.restoreCallingIdentity(identity);
5657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658 }
chen xu6dac5ab2018-10-26 17:39:23 -07005659 return false;
5660 }
5661
5662 /**
5663 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5664 *
5665 * @param slotIndex - device slot.
5666 *
5667 * @return true on success; false on any failure
5668 */
5669 @Override
5670 public boolean rebootModem(int slotIndex) {
5671 Phone phone = PhoneFactory.getPhone(slotIndex);
5672 if (phone != null) {
5673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5674 mApp, phone.getSubId(), "rebootModem");
5675
5676 final long identity = Binder.clearCallingIdentity();
5677 try {
5678 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5679 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5680 return success;
5681 } finally {
5682 Binder.restoreCallingIdentity(identity);
5683 }
5684 }
5685 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005686 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005687
Brad Ebinger51f743a2017-01-23 13:50:20 -08005688 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005689 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5690 * {@link #disableIms(int)}.
5691 * @param slotIndex device slot.
5692 */
5693 public void resetIms(int slotIndex) {
5694 enforceModifyPermission();
5695
5696 final long identity = Binder.clearCallingIdentity();
5697 try {
5698 if (mImsResolver == null) {
5699 // may happen if the does not support IMS.
5700 return;
5701 }
5702 mImsResolver.disableIms(slotIndex);
5703 mImsResolver.enableIms(slotIndex);
5704 } finally {
5705 Binder.restoreCallingIdentity(identity);
5706 }
5707 }
5708
5709 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005710 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5711 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005712 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005713 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005714 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715
5716 final long identity = Binder.clearCallingIdentity();
5717 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005718 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005719 // may happen if the device does not support IMS.
5720 return;
5721 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005722 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005726 }
5727
5728 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005729 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5730 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005731 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005732 public void disableIms(int slotId) {
5733 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734
5735 final long identity = Binder.clearCallingIdentity();
5736 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005737 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005738 // may happen if the device does not support IMS.
5739 return;
5740 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005741 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 } finally {
5743 Binder.restoreCallingIdentity(identity);
5744 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005745 }
5746
5747 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005748 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5749 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005750 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005751 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005752 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005753 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754
5755 final long identity = Binder.clearCallingIdentity();
5756 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005757 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005758 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5759 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005760 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005761 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 } finally {
5763 Binder.restoreCallingIdentity(identity);
5764 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005765 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005766 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005767 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5768 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005769 @Override
5770 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005771 enforceModifyPermission();
5772
5773 final long identity = Binder.clearCallingIdentity();
5774 try {
5775 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005776 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005777 } finally {
5778 Binder.restoreCallingIdentity(identity);
5779 }
5780 }
5781
5782 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005783 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005784 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005785 */
5786 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5787 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788
5789 final long identity = Binder.clearCallingIdentity();
5790 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005791 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005792 // may happen if the device does not support IMS.
5793 return null;
5794 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005795 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005796 } finally {
5797 Binder.restoreCallingIdentity(identity);
5798 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005799 }
5800
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005801 /**
5802 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005803 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005804 */
5805 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5806 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807
5808 final long identity = Binder.clearCallingIdentity();
5809 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005810 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005811 // may happen if the device does not support IMS.
5812 return null;
5813 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005814 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 } finally {
5816 Binder.restoreCallingIdentity(identity);
5817 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005818 }
5819
Brad Ebinger884c07b2018-02-15 16:17:40 -08005820 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005821 * Sets the ImsService Package Name that Telephony will bind to.
5822 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005823 * @param slotIndex the slot ID that the ImsService should bind for.
5824 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005825 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005826 * @param featureTypes An integer array of feature types associated with a packageName.
5827 * @param packageName The name of the package that the current configuration will be replaced
5828 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005829 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005830 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005831 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5832 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005833 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yude40a3f2022-11-19 22:29:12 -08005835 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005836
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005837 final long identity = Binder.clearCallingIdentity();
5838 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005839 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005840 // may happen if the device does not support IMS.
5841 return false;
5842 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005843 Map<Integer, String> featureConfig = new HashMap<>();
5844 for (int featureType : featureTypes) {
5845 featureConfig.put(featureType, packageName);
5846 }
5847 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5848 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005849 } finally {
5850 Binder.restoreCallingIdentity(identity);
5851 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005852 }
5853
5854 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005855 * Clears any carrier ImsService overrides for the slot index specified that were previously
5856 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5857 *
5858 * This should only be used for testing.
5859 *
5860 * @param slotIndex the slot ID that the ImsService should bind for.
5861 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5862 */
5863 @Override
5864 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08005865 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5866 "clearCarrierImsServiceOverride");
5867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yude40a3f2022-11-19 22:29:12 -08005868 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08005869
5870 final long identity = Binder.clearCallingIdentity();
5871 try {
5872 if (mImsResolver == null) {
5873 // may happen if the device does not support IMS.
5874 return false;
5875 }
5876 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5877 } finally {
5878 Binder.restoreCallingIdentity(identity);
5879 }
5880 }
5881
5882 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005883 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005884 *
5885 * @param slotId The slot that the ImsService is associated with.
5886 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5887 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005888 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005889 * @return the package name of the ImsService configuration.
5890 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005891 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5892 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005893 TelephonyPermissions
Jack Yude40a3f2022-11-19 22:29:12 -08005894 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
5895 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 final long identity = Binder.clearCallingIdentity();
5898 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005899 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005900 // may happen if the device does not support IMS.
5901 return "";
5902 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005903 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005904 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5905 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906 } finally {
5907 Binder.restoreCallingIdentity(identity);
5908 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005909 }
5910
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005911 /**
5912 * Get the MmTelFeature state associated with the requested subscription id.
5913 * @param subId The subscription that the MmTelFeature is associated with.
5914 * @param callback A callback with an integer containing the
5915 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5916 */
5917 @Override
5918 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5919 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005920 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5921 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5922 "IMS not available on device.");
5923 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005924 final long token = Binder.clearCallingIdentity();
5925 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005926 int slotId = getSlotIndex(subId);
5927 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5928 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5929 + subId + "'");
5930 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5931 }
5932 verifyImsMmTelConfiguredOrThrow(slotId);
5933 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5934 try {
5935 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5936 } catch (RemoteException e) {
5937 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5938 + "Ignore");
5939 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005940 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005941 } catch (ImsException e) {
5942 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005943 } finally {
5944 Binder.restoreCallingIdentity(token);
5945 }
5946 }
5947
Daniel Brightbb5840b2021-01-12 15:48:18 -08005948 /**
5949 * Sets the ims registration state on all valid {@link Phone}s.
5950 */
5951 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005952 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953
5954 final long identity = Binder.clearCallingIdentity();
5955 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005956 // NOTE: Before S, this method only set the default phone.
5957 for (final Phone phone : PhoneFactory.getPhones()) {
5958 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5959 phone.setImsRegistrationState(registered);
5960 }
5961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 } finally {
5963 Binder.restoreCallingIdentity(identity);
5964 }
Wink Saville36469e72014-06-11 15:17:00 -07005965 }
5966
5967 /**
Stuart Scott54788802015-03-30 13:18:01 -07005968 * Set the network selection mode to automatic.
5969 *
5970 */
5971 @Override
5972 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5974 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975
5976 final long identity = Binder.clearCallingIdentity();
5977 try {
shilufc958392020-01-20 11:36:01 -08005978 if (!isActiveSubscription(subId)) {
5979 return;
5980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005982 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5983 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 } finally {
5985 Binder.restoreCallingIdentity(identity);
5986 }
Stuart Scott54788802015-03-30 13:18:01 -07005987 }
5988
Jack Yud10cdd42020-09-28 20:28:01 -07005989 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005990 * Ask the radio to connect to the input network and change selection mode to manual.
5991 *
5992 * @param subId the id of the subscription.
5993 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5994 * the operator to attach to.
5995 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5996 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5997 * normal network selection next time.
5998 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005999 */
6000 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006001 public boolean setNetworkSelectionModeManual(
6002 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6004 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006005
Jack Yudf049d72022-12-02 22:48:35 -08006006 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006007 if (!isActiveSubscription(subId)) {
6008 return false;
6009 }
6010
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006012 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006014 if (DBG) {
6015 log("setNetworkSelectionModeManual: subId: " + subId
6016 + " operator: " + operatorInfo);
6017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6019 } finally {
6020 Binder.restoreCallingIdentity(identity);
6021 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006022 }
shilu84f6e8b2019-12-19 13:58:01 -08006023 /**
6024 * Get the manual network selection
6025 *
6026 * @param subId the id of the subscription.
6027 *
6028 * @return the previously saved user selected PLMN
6029 */
6030 @Override
6031 public String getManualNetworkSelectionPlmn(int subId) {
6032 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006033 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006034 mApp, subId, "getManualNetworkSelectionPlmn");
6035
6036 final long identity = Binder.clearCallingIdentity();
6037 try {
6038 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006039 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006040 }
6041
6042 final Phone phone = getPhone(subId);
6043 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006044 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006045 }
6046 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6047 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6048 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6049 } finally {
6050 Binder.restoreCallingIdentity(identity);
6051 }
6052 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006053
6054 /**
6055 * Scans for available networks.
6056 */
6057 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006058 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6059 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6061 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006062 LocationAccessPolicy.LocationPermissionResult locationResult =
6063 LocationAccessPolicy.checkLocationPermission(mApp,
6064 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6065 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006066 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006067 .setCallingPid(Binder.getCallingPid())
6068 .setCallingUid(Binder.getCallingUid())
6069 .setMethod("getCellNetworkScanResults")
6070 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006071 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6072 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006073 .build());
6074 switch (locationResult) {
6075 case DENIED_HARD:
6076 throw new SecurityException("Not allowed to access scan results -- location");
6077 case DENIED_SOFT:
6078 return null;
6079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080
Pengquan Menga1bb6272018-09-06 09:59:22 -07006081 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 try {
6083 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006084 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086 } finally {
6087 Binder.restoreCallingIdentity(identity);
6088 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006089 }
6090
6091 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006092 * Get the call forwarding info, given the call forwarding reason.
6093 */
6094 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006095 public void getCallForwarding(int subId, int callForwardingReason,
6096 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006097 enforceReadPrivilegedPermission("getCallForwarding");
6098 long identity = Binder.clearCallingIdentity();
6099 try {
6100 if (DBG) {
6101 log("getCallForwarding: subId " + subId
6102 + " callForwardingReason" + callForwardingReason);
6103 }
Hall Liu27d24262020-09-18 19:04:59 -07006104
6105 Phone phone = getPhone(subId);
6106 if (phone == null) {
6107 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006108 callback.onError(
6109 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006110 } catch (RemoteException e) {
6111 // ignore
6112 }
6113 return;
6114 }
6115
6116 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6117 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6118 @Override
6119 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6120 try {
6121 callback.onCallForwardingInfoAvailable(info);
6122 } catch (RemoteException e) {
6123 // ignore
6124 }
6125 }
6126
6127 @Override
6128 public void onError(int error) {
6129 try {
6130 callback.onError(error);
6131 } catch (RemoteException e) {
6132 // ignore
6133 }
6134 }
6135 });
6136 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006137 } finally {
6138 Binder.restoreCallingIdentity(identity);
6139 }
6140 }
6141
6142 /**
6143 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6144 * reason, the number to forward, and the timeout before the forwarding is attempted.
6145 */
6146 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006147 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6148 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006149 enforceModifyPermission();
6150 long identity = Binder.clearCallingIdentity();
6151 try {
6152 if (DBG) {
6153 log("setCallForwarding: subId " + subId
6154 + " callForwardingInfo" + callForwardingInfo);
6155 }
Hall Liu27d24262020-09-18 19:04:59 -07006156
6157 Phone phone = getPhone(subId);
6158 if (phone == null) {
6159 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006160 callback.accept(
6161 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006162 } catch (RemoteException e) {
6163 // ignore
6164 }
6165 return;
6166 }
6167
6168 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6169 FunctionalUtils.ignoreRemoteException(callback::accept));
6170
6171 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006172 } finally {
6173 Binder.restoreCallingIdentity(identity);
6174 }
6175 }
6176
6177 /**
Hall Liu27d24262020-09-18 19:04:59 -07006178 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006179 */
6180 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006181 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006182 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006183 long identity = Binder.clearCallingIdentity();
6184 try {
Hall Liu27d24262020-09-18 19:04:59 -07006185 Phone phone = getPhone(subId);
6186 if (phone == null) {
6187 try {
6188 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6189 } catch (RemoteException e) {
6190 // ignore
6191 }
6192 return;
6193 }
SongFerngWang0e767992021-03-31 22:08:45 +08006194 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6195 PersistableBundle c = configManager.getConfigForSubId(subId);
6196 boolean requireUssd = c.getBoolean(
6197 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006198
Shuo Qian4a594052020-01-23 11:59:30 -08006199 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006200 if (requireUssd) {
6201 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6202 getSubscriptionCarrierId(subId));
6203 String newUssdCommand = "";
6204 try {
6205 newUssdCommand = carrierXmlParser.getFeature(
6206 CarrierXmlParser.FEATURE_CALL_WAITING)
6207 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6208 } catch (NullPointerException e) {
6209 loge("Failed to generate USSD number" + e);
6210 }
6211 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6212 mMainThreadHandler, callback, carrierXmlParser,
6213 CarrierXmlParser.SsEntry.SSAction.QUERY);
6214 final String ussdCommand = newUssdCommand;
6215 Executors.newSingleThreadExecutor().execute(() -> {
6216 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6217 });
6218 } else {
6219 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6220 callback::accept);
6221 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6222 }
Shuo Qian4a594052020-01-23 11:59:30 -08006223 } finally {
6224 Binder.restoreCallingIdentity(identity);
6225 }
6226 }
6227
6228 /**
Hall Liu27d24262020-09-18 19:04:59 -07006229 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006230 */
6231 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006232 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006233 enforceModifyPermission();
6234 long identity = Binder.clearCallingIdentity();
6235 try {
Hall Liu27d24262020-09-18 19:04:59 -07006236 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6237
6238 Phone phone = getPhone(subId);
6239 if (phone == null) {
6240 try {
6241 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6242 } catch (RemoteException e) {
6243 // ignore
6244 }
6245 return;
6246 }
6247
SongFerngWang0e767992021-03-31 22:08:45 +08006248 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6249 PersistableBundle c = configManager.getConfigForSubId(subId);
6250 boolean requireUssd = c.getBoolean(
6251 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006252
SongFerngWang0e767992021-03-31 22:08:45 +08006253 if (DBG) log("getCallWaitingStatus: subId " + subId);
6254 if (requireUssd) {
6255 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6256 getSubscriptionCarrierId(subId));
6257 CarrierXmlParser.SsEntry.SSAction ssAction =
6258 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6259 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6260 String newUssdCommand = "";
6261 try {
6262 newUssdCommand = carrierXmlParser.getFeature(
6263 CarrierXmlParser.FEATURE_CALL_WAITING)
6264 .makeCommand(ssAction, null);
6265 } catch (NullPointerException e) {
6266 loge("Failed to generate USSD number" + e);
6267 }
6268 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6269 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6270 final String ussdCommand = newUssdCommand;
6271 Executors.newSingleThreadExecutor().execute(() -> {
6272 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6273 });
6274 } else {
6275 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6276 FunctionalUtils.ignoreRemoteException(callback::accept));
6277
6278 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6279 }
Shuo Qian4a594052020-01-23 11:59:30 -08006280 } finally {
6281 Binder.restoreCallingIdentity(identity);
6282 }
6283 }
6284
6285 /**
yinxub1bed742017-04-17 11:45:04 -07006286 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006287 *
yinxub1bed742017-04-17 11:45:04 -07006288 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006289 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6290 * location related information which will be sent if the caller already possess
6291 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006292 * @param request contains the radio access networks with bands/channels to scan
6293 * @param messenger callback messenger for scan results or errors
6294 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006295 * @return the id of the requested scan which can be used to stop the scan.
6296 */
6297 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006298 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6299 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006300 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6302 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006303 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006304 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6305 if (!renounceFineLocationAccess) {
6306 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6307 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6308 .setCallingPackage(callingPackage)
6309 .setCallingFeatureId(callingFeatureId)
6310 .setCallingPid(Binder.getCallingPid())
6311 .setCallingUid(Binder.getCallingUid())
6312 .setMethod("requestNetworkScan")
6313 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6314 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6315 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6316 .build());
6317 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006318 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006319 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6320 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006321 if (e != null) {
6322 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6323 throw e;
6324 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006325 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006326 return TelephonyScanManager.INVALID_SCAN_ID;
6327 }
6328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329 }
Hall Liu912dfd32019-04-25 14:02:26 -07006330 int callingUid = Binder.getCallingUid();
6331 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006332 final long identity = Binder.clearCallingIdentity();
6333 try {
6334 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006335 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006336 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006337 } finally {
6338 Binder.restoreCallingIdentity(identity);
6339 }
yinxu504e1392017-04-12 16:03:22 -07006340 }
6341
Hall Liub2ac8ef2019-02-28 15:56:23 -08006342 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006343 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wangaccdabf2022-10-20 16:52:29 +00006344 boolean hasCarrierPriv;
6345 final long identity = Binder.clearCallingIdentity();
6346 try {
6347 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6348 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6349 } finally {
6350 Binder.restoreCallingIdentity(identity);
6351 }
Hall Liu558027f2019-05-15 19:14:05 -07006352 boolean hasNetworkScanPermission =
6353 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6354 == PERMISSION_GRANTED;
6355
6356 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6357 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6358 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006359 }
6360
6361 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6362 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006363 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6364 return new SecurityException("Specific channels must not be"
6365 + " scanned without location access.");
6366 }
6367 }
6368 }
6369
Hall Liub2ac8ef2019-02-28 15:56:23 -08006370 return null;
6371 }
6372
yinxu504e1392017-04-12 16:03:22 -07006373 /**
6374 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006375 *
6376 * @param subId id of the subscription
6377 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006378 */
6379 @Override
6380 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6382 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383
Hall Liu912dfd32019-04-25 14:02:26 -07006384 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 final long identity = Binder.clearCallingIdentity();
6386 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006387 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388 } finally {
6389 Binder.restoreCallingIdentity(identity);
6390 }
yinxu504e1392017-04-12 16:03:22 -07006391 }
6392
6393 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006394 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006395 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006396 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006397 */
6398 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006399 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006400 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006401 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006402 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403
6404 final long identity = Binder.clearCallingIdentity();
6405 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006406 if (DBG) log("getAllowedNetworkTypesBitmask");
6407 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6408 int networkTypesBitmask = (result != null ? result[0] : -1);
6409 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6410 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006414 }
6415
6416 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006417 * Get the allowed network types for certain reason.
6418 *
6419 * @param subId the id of the subscription.
6420 * @param reason the reason the allowed network type change is taking place
6421 * @return the allowed network types.
6422 */
6423 @Override
6424 public long getAllowedNetworkTypesForReason(int subId,
6425 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006426 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006427 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006428 final long identity = Binder.clearCallingIdentity();
6429 try {
6430 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6431 } finally {
6432 Binder.restoreCallingIdentity(identity);
6433 }
6434 }
6435
6436 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006437 * Enable/Disable E-UTRA-NR Dual Connectivity
6438 * @param subId subscription id of the sim card
6439 * @param nrDualConnectivityState expected NR dual connectivity state
6440 * This can be passed following states
6441 * <ol>
6442 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6443 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6444 * <li>Disable NR dual connectivity and force secondary cell to be released
6445 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6446 * </ol>
6447 * @return operation result.
6448 */
6449 @Override
6450 public int setNrDualConnectivityState(int subId,
6451 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6453 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006454 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006455 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6456 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6457 }
6458
Sooraj Sasindran37444802020-08-11 10:40:43 -07006459 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6460 final long identity = Binder.clearCallingIdentity();
6461 try {
6462 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6463 nrDualConnectivityState, subId,
6464 workSource);
6465 if (DBG) log("enableNRDualConnectivity result: " + result);
6466 return result;
6467 } finally {
6468 Binder.restoreCallingIdentity(identity);
6469 }
6470 }
6471
6472 /**
6473 * Is E-UTRA-NR Dual Connectivity enabled
6474 * @return true if dual connectivity is enabled else false
6475 */
6476 @Override
6477 public boolean isNrDualConnectivityEnabled(int subId) {
6478 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006479 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006480 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006481 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006482 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6483 return false;
6484 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006485 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6486 final long identity = Binder.clearCallingIdentity();
6487 try {
6488 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6489 null, subId, workSource);
6490 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6491 return isEnabled;
6492 } finally {
6493 Binder.restoreCallingIdentity(identity);
6494 }
6495 }
6496
6497 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006498 * Set the allowed network types of the device and
6499 * provide the reason triggering the allowed network change.
6500 *
6501 * @param subId the id of the subscription.
6502 * @param reason the reason the allowed network type change is taking place
6503 * @param allowedNetworkTypes the allowed network types.
6504 * @return true on success; false on any failure.
6505 */
6506 @Override
6507 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006508 @TelephonyManager.AllowedNetworkTypesReason int reason,
6509 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6511 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006512 // If the caller only has carrier privileges, then they should not be able to override
6513 // any network types which were set for security reasons.
6514 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6515 != PERMISSION_GRANTED
6516 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6517 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6518 throw new SecurityException(
6519 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6520 + " reason "
6521 + reason);
6522 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006523 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006524 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6525 return false;
6526 }
6527 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6528 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006529 return false;
6530 }
6531
Jack Yu5e360c42022-12-16 11:53:37 -08006532 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006533 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6534
Jack Yu5e360c42022-12-16 11:53:37 -08006535 Phone phone = getPhone(subId);
6536 if (phone == null) {
6537 return false;
6538 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006539
Jack Yu5e360c42022-12-16 11:53:37 -08006540 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006541 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6542 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006543 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006544
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006545 final long identity = Binder.clearCallingIdentity();
6546 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006547 Boolean success = (Boolean) sendRequest(
6548 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6549 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6550
6551 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6552 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006553 } finally {
6554 Binder.restoreCallingIdentity(identity);
6555 }
6556 }
6557
6558 /**
Miaoa84611c2019-03-15 09:21:10 +08006559 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006560 *
Miaoa84611c2019-03-15 09:21:10 +08006561 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006562 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006563 * @hide
6564 */
6565 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006566 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006569 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570 try {
Miaoa84611c2019-03-15 09:21:10 +08006571 if (phone != null) {
6572 return phone.hasMatchedTetherApnSetting();
6573 } else {
6574 return false;
6575 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006576 } finally {
6577 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006578 }
Junda Liu475951f2014-11-07 16:45:03 -08006579 }
6580
6581 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006582 * Get the user enabled state of Mobile Data.
6583 *
6584 * TODO: remove and use isUserDataEnabled.
6585 * This can't be removed now because some vendor codes
6586 * calls through ITelephony directly while they should
6587 * use TelephonyManager.
6588 *
6589 * @return true on enabled
6590 */
6591 @Override
6592 public boolean getDataEnabled(int subId) {
6593 return isUserDataEnabled(subId);
6594 }
6595
6596 /**
6597 * Get whether mobile data is enabled per user setting.
6598 *
6599 * There are other factors deciding whether mobile data is actually enabled, but they are
6600 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006601 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006602 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6603 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006604 *
6605 * @return {@code true} if data is enabled else {@code false}
6606 */
6607 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006608 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006609 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006610 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006611 try {
6612 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6613 functionName);
6614 } catch (Exception e) {
6615 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6616 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006617 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006619 mApp, subId, functionName);
6620
Robert Greenwalt646120a2014-05-23 11:54:03 -07006621 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622
6623 final long identity = Binder.clearCallingIdentity();
6624 try {
Jack Yudf049d72022-12-02 22:48:35 -08006625 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006626 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6627 Phone phone = PhoneFactory.getPhone(phoneId);
6628 if (phone != null) {
6629 boolean retVal = phone.isUserDataEnabled();
6630 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6631 return retVal;
6632 } else {
6633 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6634 return false;
6635 }
6636 } finally {
6637 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006638 }
6639 }
6640
6641 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006642 * Checks if the device is capable of mobile data by considering whether whether the
6643 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6644 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006645 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006646 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006647 */
6648 @Override
6649 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006650 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006651 try {
6652 try {
6653 mApp.enforceCallingOrSelfPermission(
6654 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006655 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006656 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006657 try {
6658 mApp.enforceCallingOrSelfPermission(
6659 android.Manifest.permission.READ_PHONE_STATE,
6660 functionName);
6661 } catch (Exception e2) {
6662 mApp.enforceCallingOrSelfPermission(
6663 permission.READ_BASIC_PHONE_STATE, functionName);
6664 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006665 }
6666 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006667 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006668 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669
6670 final long identity = Binder.clearCallingIdentity();
6671 try {
Jack Yudf049d72022-12-02 22:48:35 -08006672 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006673 Phone phone = PhoneFactory.getPhone(phoneId);
6674 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006675 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006676 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006677 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006678 return retVal;
6679 } else {
6680 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6681 return false;
6682 }
6683 } finally {
6684 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006685 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006686 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006687
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006688 /**
6689 * Check if data is enabled for a specific reason
6690 * @param subId Subscription index
6691 * @param reason the reason the data enable change is taking place
6692 * @return {@code true} if the overall data is enabled; {@code false} if not.
6693 */
6694 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006695 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006696 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006697 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006698 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006699 try {
6700 mApp.enforceCallingOrSelfPermission(
6701 android.Manifest.permission.ACCESS_NETWORK_STATE,
6702 functionName);
6703 } catch (Exception e) {
6704 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6705 functionName);
6706 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006707 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006708 try {
6709 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006710 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006711 } catch (Exception e2) {
6712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006713 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006714 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006715 }
6716
6717
6718 final long identity = Binder.clearCallingIdentity();
6719 try {
Jack Yudf049d72022-12-02 22:48:35 -08006720 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006721 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006722 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006723 + " reason=" + reason);
6724 }
6725 Phone phone = PhoneFactory.getPhone(phoneId);
6726 if (phone != null) {
6727 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006728 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006729 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006730 return retVal;
6731 } else {
6732 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006733 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006734 + subId + " retVal=false");
6735 }
6736 return false;
6737 }
6738 } finally {
6739 Binder.restoreCallingIdentity(identity);
6740 }
6741 }
6742
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006743 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006744 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006745 // No permission needed; this only lets the caller inspect their own status.
6746 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006747 }
Junda Liu29340342014-07-10 15:23:27 -07006748
6749 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006750 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006751 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006752 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6753 }
6754
6755 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6756 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006757 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006758 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006759 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6760 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006761 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6762 if (cpt == null) {
6763 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006764 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6765 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006766 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006767 }
6768
6769 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006770 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006771 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006772 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006773 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006774 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006775 Phone phone = getPhone(subId);
6776 if (phone == null) {
6777 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6778 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6779 }
6780 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6781 if (cpt == null) {
6782 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006783 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6784 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006785 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006786 }
6787
6788 @Override
6789 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006790 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006791 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6792 }
6793
6794 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006795 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006796 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006797 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006798 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006799 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6800 Phone phone = PhoneFactory.getPhone(phoneId);
6801 if (phone == null) {
6802 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006803 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006804 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6805 if (cpt == null) {
6806 continue;
6807 }
6808 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006809 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6810 break;
6811 }
6812 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006813 return result;
Junda Liu29340342014-07-10 15:23:27 -07006814 }
Derek Tan89e89d42014-07-08 17:00:10 -07006815
6816 @Override
Junda Liue64de782015-04-16 17:19:16 -07006817 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006818 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006819 Phone phone = PhoneFactory.getPhone(phoneId);
6820 if (phone == null) {
6821 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006822 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006823 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6824 if (cpt == null) {
6825 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006826 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006827 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006828 }
6829
Amith Yamasani6e118872016-02-19 12:53:51 -08006830 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006831 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006832 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006833 Phone phone = PhoneFactory.getPhone(phoneId);
6834 if (phone == null) {
6835 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006836 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006837 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6838 if (cpt == null) {
6839 return Collections.emptyList();
6840 }
6841 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006842 }
6843
chen xuf7e9fe82019-05-09 19:31:02 -07006844 @Override
6845 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006846 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006847 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006848 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006849 try {
6850 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6851 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6852 }
6853 } finally {
6854 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006855 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006856 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006857 }
6858
Rambo Wang6812ffb2022-03-15 16:54:17 -07006859 @Override
6860 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6861 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6862
6863 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6864 if (phone == null) {
6865 return null;
6866 }
6867 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6868 if (cpt == null) {
6869 return null;
6870 }
6871 return cpt.getCarrierServicePackageName();
6872 }
6873
Wink Savilleb564aae2014-10-23 10:18:09 -07006874 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006875 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006876 UiccPort port = phone == null ? null : phone.getUiccPort();
6877 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006878 return null;
6879 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006880 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006881 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006882 return null;
6883 }
6884 return iccId;
6885 }
6886
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006887 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006888 public void setCallComposerStatus(int subId, int status) {
6889 enforceModifyPermission();
6890
6891 final long identity = Binder.clearCallingIdentity();
6892 try {
6893 Phone phone = getPhone(subId);
6894 if (phone != null) {
6895 Phone defaultPhone = phone.getImsPhone();
6896 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6897 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6898 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006899 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6900 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006901 }
6902 }
Shuo Qian284ae752020-12-22 19:10:14 -08006903 } catch (ImsException e) {
6904 throw new ServiceSpecificException(e.getCode());
6905 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006906 Binder.restoreCallingIdentity(identity);
6907 }
6908 }
6909
6910 @Override
6911 public int getCallComposerStatus(int subId) {
6912 enforceReadPrivilegedPermission("getCallComposerStatus");
6913
6914 final long identity = Binder.clearCallingIdentity();
6915 try {
6916 Phone phone = getPhone(subId);
6917 if (phone != null) {
6918 Phone defaultPhone = phone.getImsPhone();
6919 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6920 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6921 return imsPhone.getCallComposerStatus();
6922 }
6923 }
6924 } finally {
6925 Binder.restoreCallingIdentity(identity);
6926 }
6927 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6928 }
6929
6930 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006931 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6932 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006933 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006934 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006936 final long identity = Binder.clearCallingIdentity();
6937 try {
6938 final String iccId = getIccId(subId);
6939 final Phone phone = getPhone(subId);
6940 if (phone == null) {
6941 return false;
6942 }
6943 final String subscriberId = phone.getSubscriberId();
6944
6945 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006946 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947 + subscriberId + " to " + number);
6948 }
6949
6950 if (TextUtils.isEmpty(iccId)) {
6951 return false;
6952 }
6953
6954 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6955
6956 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6957 if (alphaTag == null) {
6958 editor.remove(alphaTagPrefKey);
6959 } else {
6960 editor.putString(alphaTagPrefKey, alphaTag);
6961 }
6962
6963 // Record both the line number and IMSI for this ICCID, since we need to
6964 // track all merged IMSIs based on line number
6965 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6966 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6967 if (number == null) {
6968 editor.remove(numberPrefKey);
6969 editor.remove(subscriberPrefKey);
6970 } else {
6971 editor.putString(numberPrefKey, number);
6972 editor.putString(subscriberPrefKey, subscriberId);
6973 }
6974
6975 editor.commit();
6976 return true;
6977 } finally {
6978 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006979 }
Derek Tan7226c842014-07-02 17:42:23 -07006980 }
6981
6982 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006983 public String getLine1NumberForDisplay(int subId, String callingPackage,
6984 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006985 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006987 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006988 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006989 return null;
6990 }
Derek Tan97ebb422014-09-05 16:55:38 -07006991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992 final long identity = Binder.clearCallingIdentity();
6993 try {
6994 String iccId = getIccId(subId);
6995 if (iccId != null) {
6996 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6997 if (DBG_MERGE) {
6998 log("getLine1NumberForDisplay returning "
6999 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7000 }
7001 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7004 return null;
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007007 }
Derek Tan7226c842014-07-02 17:42:23 -07007008 }
7009
7010 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007011 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7012 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007014 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007015 return null;
7016 }
Derek Tan97ebb422014-09-05 16:55:38 -07007017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 final long identity = Binder.clearCallingIdentity();
7019 try {
7020 String iccId = getIccId(subId);
7021 if (iccId != null) {
7022 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7023 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7024 }
7025 return null;
7026 } finally {
7027 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007028 }
Derek Tan7226c842014-07-02 17:42:23 -07007029 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007030
7031 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007032 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7033 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007034 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7035 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007037 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007038 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007039 return null;
7040 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007041
Jordan Liub49b04b2019-05-06 14:45:15 -07007042 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7043 // the process, where TelephonyManager was instantiated.
7044 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007045 final long identity = Binder.clearCallingIdentity();
7046 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007047 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048 final TelephonyManager tele = TelephonyManager.from(context);
7049 final SubscriptionManager sub = SubscriptionManager.from(context);
7050
7051 // Figure out what subscribers are currently active
7052 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053
Jordan Liub49b04b2019-05-06 14:45:15 -07007054 // Only consider subs which match the current subId
7055 // This logic can be simplified. See b/131189269 for progress.
7056 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007057 activeSubscriberIds.add(tele.getSubscriberId(subId));
7058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059
7060 // First pass, find a number override for an active subscriber
7061 String mergeNumber = null;
7062 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7063 for (String key : prefs.keySet()) {
7064 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7065 final String subscriberId = (String) prefs.get(key);
7066 if (activeSubscriberIds.contains(subscriberId)) {
7067 final String iccId = key.substring(
7068 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7069 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7070 mergeNumber = (String) prefs.get(numberKey);
7071 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007072 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 + " for active subscriber " + subscriberId);
7074 }
7075 if (!TextUtils.isEmpty(mergeNumber)) {
7076 break;
7077 }
7078 }
7079 }
7080 }
7081
7082 // Shortcut when no active merged subscribers
7083 if (TextUtils.isEmpty(mergeNumber)) {
7084 return null;
7085 }
7086
7087 // Second pass, find all subscribers under that line override
7088 final ArraySet<String> result = new ArraySet<>();
7089 for (String key : prefs.keySet()) {
7090 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7091 final String number = (String) prefs.get(key);
7092 if (mergeNumber.equals(number)) {
7093 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7094 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7095 final String subscriberId = (String) prefs.get(subscriberKey);
7096 if (!TextUtils.isEmpty(subscriberId)) {
7097 result.add(subscriberId);
7098 }
7099 }
7100 }
7101 }
7102
7103 final String[] resultArray = result.toArray(new String[result.size()]);
7104 Arrays.sort(resultArray);
7105 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007106 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7108 }
7109 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007110 } finally {
7111 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007112 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007113 }
7114
7115 @Override
zoey chen38003472019-12-13 17:16:31 +08007116 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7117 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007118
7119 final long identity = Binder.clearCallingIdentity();
7120 try {
7121 final TelephonyManager telephonyManager = mApp.getSystemService(
7122 TelephonyManager.class);
7123 String subscriberId = telephonyManager.getSubscriberId(subId);
7124 if (subscriberId == null) {
7125 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007126 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007127 + subId);
7128 }
7129 return null;
7130 }
7131
Jack Yudf049d72022-12-02 22:48:35 -08007132 ParcelUuid groupUuid;
7133 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7134 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7135 .getSubscriptionInfo(subId);
7136 groupUuid = info.getGroupUuid();
7137 } else {
7138 final SubscriptionInfo info = mSubscriptionController
7139 .getSubscriptionInfo(subId);
7140 groupUuid = info.getGroupUuid();
7141 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007142 // If it doesn't belong to any group, return just subscriberId of itself.
7143 if (groupUuid == null) {
7144 return new String[]{subscriberId};
7145 }
7146
7147 // Get all subscriberIds from the group.
7148 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yudf049d72022-12-02 22:48:35 -08007149 List<SubscriptionInfo> groupInfos;
7150 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7151 groupInfos = SubscriptionManagerService.getInstance()
7152 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7153 mApp.getAttributionTag());
7154 } else {
7155 groupInfos = mSubscriptionController
7156 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7157 mApp.getAttributionTag());
7158 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007159 for (SubscriptionInfo subInfo : groupInfos) {
7160 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7161 if (subscriberId != null) {
7162 mergedSubscriberIds.add(subscriberId);
7163 }
7164 }
7165
7166 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7167 } finally {
7168 Binder.restoreCallingIdentity(identity);
7169
7170 }
7171 }
7172
7173 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007174 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007175 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007176 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007177
7178 final long identity = Binder.clearCallingIdentity();
7179 try {
7180 final Phone phone = getPhone(subId);
7181 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7182 } finally {
7183 Binder.restoreCallingIdentity(identity);
7184 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007185 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007186
7187 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007188 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007189 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7190 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007191 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7192 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007193
7194 final long identity = Binder.clearCallingIdentity();
7195 try {
7196 final Phone phone = getPhone(subId);
7197 if (phone == null) {
7198 return false;
7199 }
7200 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7201 cdmaNonRoamingList);
7202 } finally {
7203 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007204 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007205 }
7206
7207 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007208 @Deprecated
7209 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7210 enforceModifyPermission();
7211
7212 int returnValue = 0;
7213 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007214 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007215 if(result.exception == null) {
7216 if (result.result != null) {
7217 byte[] responseData = (byte[])(result.result);
7218 if(responseData.length > oemResp.length) {
7219 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7220 responseData.length + "bytes. Buffer Size is " +
7221 oemResp.length + "bytes.");
7222 }
7223 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7224 returnValue = responseData.length;
7225 }
7226 } else {
7227 CommandException ex = (CommandException) result.exception;
7228 returnValue = ex.getCommandError().ordinal();
7229 if(returnValue > 0) returnValue *= -1;
7230 }
7231 } catch (RuntimeException e) {
7232 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7233 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7234 if(returnValue > 0) returnValue *= -1;
7235 }
7236
7237 return returnValue;
7238 }
7239
7240 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007241 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007242 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007243 try {
7244 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007245 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007246 mApp, phone.getSubId(), "getRadioAccessFamily");
7247 } catch (SecurityException e) {
7248 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7249 throw e;
7250 }
chen xub97461a2018-10-26 14:17:57 -07007251 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007252 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007253 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255 final long identity = Binder.clearCallingIdentity();
7256 try {
chen xub97461a2018-10-26 14:17:57 -07007257 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007258 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007259 mApp, phone.getSubId(), "getRadioAccessFamily");
7260 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007261 } finally {
7262 Binder.restoreCallingIdentity(identity);
7263 }
chen xub97461a2018-10-26 14:17:57 -07007264 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007265 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007266
7267 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007268 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007269 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007270 try {
7271 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7272 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007273 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007274 }
7275 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007276 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007277 }
7278 RoleManager rm = mApp.getSystemService(RoleManager.class);
7279 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7280 if (!dialerRoleHolders.contains(callingPackage)) {
7281 throw new SecurityException("App must be the dialer role holder to"
7282 + " upload a call composer pic");
7283 }
7284
7285 Executors.newSingleThreadExecutor().execute(() -> {
7286 ByteArrayOutputStream output = new ByteArrayOutputStream(
7287 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7288 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7289 boolean readUntilEnd = false;
7290 int totalBytesRead = 0;
7291 byte[] buffer = new byte[16 * 1024];
7292 while (true) {
7293 int numRead;
7294 try {
7295 numRead = input.read(buffer);
7296 } catch (IOException e) {
7297 try {
7298 fd.checkError();
7299 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7300 null);
7301 } catch (IOException e1) {
7302 // This means that the other side closed explicitly with an error. If this
7303 // happens, log and ignore.
7304 loge("Remote end of call composer picture pipe closed: " + e1);
7305 }
7306 break;
7307 }
7308 if (numRead == -1) {
7309 readUntilEnd = true;
7310 break;
7311 }
7312 totalBytesRead += numRead;
7313 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7314 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7315 try {
7316 input.close();
7317 } catch (IOException e) {
7318 // ignore
7319 }
7320 break;
7321 }
7322 output.write(buffer, 0, numRead);
7323 }
7324 // Generally, the remote end will close the file descriptors. The only case where we
7325 // close is above, where the picture size is too big.
7326
7327 try {
7328 fd.checkError();
7329 } catch (IOException e) {
7330 loge("Remote end for call composer closed with an error: " + e);
7331 return;
7332 }
7333
Hall Liuaa4211e2021-01-20 15:43:39 -08007334 if (!readUntilEnd) {
7335 loge("Did not finish reading entire image; aborting");
7336 return;
7337 }
Hall Liu82694d52020-12-11 18:22:04 -08007338
Hall Liuaa4211e2021-01-20 15:43:39 -08007339 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7340 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7341 new CallComposerPictureTransfer.Factory() {},
7342 imageData,
7343 (result) -> {
7344 if (result.first != null) {
7345 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7346 Bundle outputResult = new Bundle();
7347 outputResult.putParcelable(
7348 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7349 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7350 outputResult);
7351 } else {
7352 callback.send(result.second, null);
7353 }
7354 }
7355 );
Hall Liu82694d52020-12-11 18:22:04 -08007356 });
7357 }
7358
7359 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007360 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007361 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007362 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363
7364 final long identity = Binder.clearCallingIdentity();
7365 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007366 ImsManager.getInstance(defaultPhone.getContext(),
7367 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007368 } finally {
7369 Binder.restoreCallingIdentity(identity);
7370 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007371 }
7372
7373 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007374 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007375 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007376 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7377 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007378 return false;
7379 }
Svet Ganovb320e182015-04-16 12:30:10 -07007380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007381 final long identity = Binder.clearCallingIdentity();
7382 try {
7383 // Check the user preference and the system-level IMS setting. Even if the user has
7384 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7385 // In the long run, we may instead need to check if there exists a connection service
7386 // which can support video calling.
7387 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007388 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 return imsManager.isVtEnabledByPlatform()
7390 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7391 && imsManager.isVtEnabledByUser();
7392 } finally {
7393 Binder.restoreCallingIdentity(identity);
7394 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007395 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007396
Andrew Leea1239f22015-03-02 17:44:07 -08007397 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007398 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7399 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007400 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007401 mApp, subId, callingPackage, callingFeatureId,
7402 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007403 return false;
7404 }
7405
7406 final long identity = Binder.clearCallingIdentity();
7407 try {
7408 CarrierConfigManager configManager =
7409 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007410 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007411 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7412 } finally {
7413 Binder.restoreCallingIdentity(identity);
7414 }
Andrew Leea1239f22015-03-02 17:44:07 -08007415 }
7416
7417 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007418 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007420 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421 return false;
7422 }
7423
7424 final long identity = Binder.clearCallingIdentity();
7425 try {
7426 CarrierConfigManager configManager =
7427 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007428 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7430 } finally {
7431 Binder.restoreCallingIdentity(identity);
7432 }
Andrew Leea1239f22015-03-02 17:44:07 -08007433 }
7434
Andrew Lee9431b832015-03-09 18:46:45 -07007435 @Override
7436 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007437 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007438 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007439 }
7440
7441 @Override
7442 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 final long identity = Binder.clearCallingIdentity();
7444 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007445 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 } finally {
7447 Binder.restoreCallingIdentity(identity);
7448 }
Andrew Lee9431b832015-03-09 18:46:45 -07007449 }
7450
Hall Liuf6668912018-10-31 17:05:23 -07007451 /**
7452 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7453 * support for the feature and device firmware support.
7454 *
7455 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7456 */
7457 @Override
7458 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007460 final Phone phone = getPhone(subscriptionId);
7461 if (phone == null) {
7462 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7463 return false;
7464 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007466 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7468 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007469 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007470 return isCarrierSupported && isDeviceSupported;
7471 } finally {
7472 Binder.restoreCallingIdentity(identity);
7473 }
Hall Liu98187582018-01-22 19:15:32 -08007474 }
7475
Hall Liuf6668912018-10-31 17:05:23 -07007476 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007477 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7478 * RTT setting, will return true if the device and carrier both support RTT.
7479 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007480 */
7481 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 final long identity = Binder.clearCallingIdentity();
7483 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007484 boolean isRttSupported = isRttSupported(subscriptionId);
7485 boolean isUserRttSettingOn = Settings.Secure.getInt(
7486 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7487 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7488 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7489 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 } finally {
7491 Binder.restoreCallingIdentity(identity);
7492 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007493 }
7494
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007495 @Deprecated
7496 @Override
7497 public String getDeviceId(String callingPackage) {
7498 return getDeviceIdWithFeature(callingPackage, null);
7499 }
7500
Sanket Padawe7310cc72015-01-14 09:53:20 -08007501 /**
7502 * Returns the unique device ID of phone, for example, the IMEI for
7503 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7504 *
7505 * <p>Requires Permission:
7506 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7507 */
7508 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007509 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007510 try {
7511 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7512 } catch (SecurityException se) {
7513 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7514 throw new SecurityException("Package " + callingPackage + " does not belong to "
7515 + Binder.getCallingUid());
7516 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007517 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007518 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007519 return null;
7520 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007521 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007522 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007523 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007524 return null;
7525 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526
7527 final long identity = Binder.clearCallingIdentity();
7528 try {
7529 return phone.getDeviceId();
7530 } finally {
7531 Binder.restoreCallingIdentity(identity);
7532 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007533 }
7534
Ping Sunc67b7c22016-03-02 19:16:45 +08007535 /**
7536 * {@hide}
7537 * Returns the IMS Registration Status on a particular subid
7538 *
7539 * @param subId
7540 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007541 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007542 Phone phone = getPhone(subId);
7543 if (phone != null) {
7544 return phone.isImsRegistered();
7545 } else {
7546 return false;
7547 }
7548 }
7549
Santos Cordon7a1885b2015-02-03 11:15:19 -08007550 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007551 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007552 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007553 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007554 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007555 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7556 }
7557 final long identity = Binder.clearCallingIdentity();
7558 try {
7559 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7560 } finally {
7561 Binder.restoreCallingIdentity(identity);
7562 }
7563 }
7564
7565 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007566 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007567 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007568 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007569 mApp,
7570 subscriptionId,
7571 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007572 final long identity = Binder.clearCallingIdentity();
7573 try {
7574 Phone phone = getPhone(subscriptionId);
7575 if (phone == null) {
7576 return null;
7577 }
7578 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7579 } finally {
7580 Binder.restoreCallingIdentity(identity);
7581 }
7582 }
7583
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007584 /**
7585 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007586 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007587 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007588 final long identity = Binder.clearCallingIdentity();
7589 try {
7590 Phone phone = getPhone(subId);
7591 if (phone != null) {
7592 return phone.isWifiCallingEnabled();
7593 } else {
7594 return false;
7595 }
7596 } finally {
7597 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007598 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007599 }
7600
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007601 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007602 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007603 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007604 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007605 final long identity = Binder.clearCallingIdentity();
7606 try {
7607 Phone phone = getPhone(subId);
7608 if (phone != null) {
7609 return phone.isVideoEnabled();
7610 } else {
7611 return false;
7612 }
7613 } finally {
7614 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007615 }
7616 }
7617
7618 /**
7619 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7620 * defined in {@link ImsRegistrationImplBase}.
7621 */
7622 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007623 final long identity = Binder.clearCallingIdentity();
7624 try {
7625 Phone phone = getPhone(subId);
7626 if (phone != null) {
7627 return phone.getImsRegistrationTech();
7628 } else {
7629 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7630 }
7631 } finally {
7632 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007633 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007634 }
7635
Stuart Scott8eef64f2015-04-08 15:13:54 -07007636 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007637 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007638 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007639 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7640 return;
7641 }
Kai Shif70f46f2021-03-03 13:59:46 -08007642 Phone defaultPhone = getDefaultPhone();
7643 if (defaultPhone != null) {
7644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7645 mApp, getDefaultPhone().getSubId(), "factoryReset");
7646 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007647 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007648
Svet Ganovcc087f82015-05-12 20:35:54 -07007649 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007650 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7651 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007652 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007653 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007654 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007655 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007656 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007657 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007658 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007659 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007660 // There has been issues when Sms raw table somehow stores orphan
7661 // fragments. They lead to garbled message when new fragments come
7662 // in and combined with those stale ones. In case this happens again,
7663 // user can reset all network settings which will clean up this table.
7664 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007665 // Clean up IMS settings as well here.
7666 int slotId = getSlotIndex(subId);
7667 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7668 ImsManager.getInstance(mApp, slotId).factoryReset();
7669 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007670
Kai Shif70f46f2021-03-03 13:59:46 -08007671 if (defaultPhone == null) {
7672 return;
7673 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007674 // Erase modem config if erase modem on network setting is enabled.
7675 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7676 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7677 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007678 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007679 }
Kai Shif70f46f2021-03-03 13:59:46 -08007680
7681 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007682 } finally {
7683 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007684 }
7685 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007686
SongFerngWangfd89b102021-05-27 22:44:54 +08007687 @VisibleForTesting
7688 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7689 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7690 return;
7691 }
7692 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7693 RILConstants.PREFERRED_NETWORK_MODE);
7694 SubscriptionManager.setSubscriptionProperty(subId,
7695 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7696 "user=" + defaultNetworkType);
7697 phone.loadAllowedNetworksFromSubscriptionDatabase();
7698 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7699 defaultNetworkType, null);
7700 }
7701
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007702 private void cleanUpSmsRawTable(Context context) {
7703 ContentResolver resolver = context.getContentResolver();
7704 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7705 resolver.delete(uri, null, null);
7706 }
7707
Narayan Kamath1c496c22015-04-16 14:40:19 +01007708 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007709 public String getSimLocaleForSubscriber(int subId) {
7710 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7711 final Phone phone = getPhone(subId);
7712 if (phone == null) {
7713 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007714 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716 final long identity = Binder.clearCallingIdentity();
7717 try {
Jack Yudf049d72022-12-02 22:48:35 -08007718 SubscriptionInfo info;
7719 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7720 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
7721 phone.getContext().getOpPackageName(),
7722 phone.getContext().getAttributionTag());
7723 if (info == null) {
7724 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7725 return null;
7726 }
7727 } else {
7728 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
7729 phone.getContext().getOpPackageName(),
7730 phone.getContext().getAttributionTag());
7731 if (info == null) {
7732 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7733 return null;
7734 }
chen xu6291c472019-02-04 12:55:53 -08007735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007736 // Try and fetch the locale from the carrier properties or from the SIM language
7737 // preferences (EF-PL and EF-LI)...
7738 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007739 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007740 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7741 if (localeFromDefaultSim != null) {
7742 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7743 if (DBG) log("Using locale from subId: " + subId + " locale: "
7744 + localeFromDefaultSim);
tom hsu22b7c3e2022-10-27 00:10:04 +08007745 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007746 } else {
7747 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007748 }
7749 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751 // The SIM language preferences only store a language (e.g. fr = French), not an
7752 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7753 // the SIM and carrier preferences does not include a country we add the country
7754 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007755 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007757 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu22b7c3e2022-10-27 00:10:04 +08007758 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007759 }
7760
7761 if (DBG) log("No locale found - returning null");
7762 return null;
7763 } finally {
7764 Binder.restoreCallingIdentity(identity);
7765 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007766 }
7767
tom hsue9360cd2022-09-29 23:49:21 +08007768 @VisibleForTesting
tom hsu22b7c3e2022-10-27 00:10:04 +08007769 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsue9360cd2022-09-29 23:49:21 +08007770 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu22b7c3e2022-10-27 00:10:04 +08007771 phone.getContext());
tom hsue9360cd2022-09-29 23:49:21 +08007772 for (String localeTag : supportedLocale) {
tom hsu22b7c3e2022-10-27 00:10:04 +08007773 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7774 && TextUtils.equals(inputLocale.getCountry(),
tom hsue9360cd2022-09-29 23:49:21 +08007775 Locale.forLanguageTag(localeTag).getCountry())) {
7776 return localeTag;
7777 }
7778 }
7779 return inputLocale.toLanguageTag();
7780 }
7781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007782 /**
7783 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7784 */
7785 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yudf049d72022-12-02 22:48:35 -08007786 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7787 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
7788 mApp.getOpPackageName(), mApp.getAttributionTag());
7789 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007790 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007791 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007792 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007793
Gary Jian3aa9a762022-01-24 16:41:19 +08007794 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7795 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007796
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007797 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007798 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7799 * representing the state of the modem.
7800 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007801 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7802 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007803 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007804 */
7805 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007806 public void requestModemActivityInfo(ResultReceiver result) {
7807 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007808 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007809
7810 final long identity = Binder.clearCallingIdentity();
7811 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007812 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007813 } finally {
7814 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007815 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007816 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007817
Siddharth Rayb8114062018-06-17 15:02:38 -07007818 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7819 // less than total activity duration.
7820 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7821 if (info == null) {
7822 return false;
7823 }
7824 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007825 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7826 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7827
Siddharth Rayb8114062018-06-17 15:02:38 -07007828 return (info.isValid()
7829 && (info.getSleepTimeMillis() <= activityDurationMs)
7830 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007831 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007832 && (totalTxTimeMs <= activityDurationMs));
7833 }
7834
Gary Jian3aa9a762022-01-24 16:41:19 +08007835 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7836 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7837 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7838 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7839
7840 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7841 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7842 }
7843
7844 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7845 mLastModemActivityInfo.setReceiveTimeMillis(
7846 rat,
7847 freq,
7848 info.getReceiveTimeMillis(rat, freq)
7849 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7850 }
7851
7852 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7853 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7854 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7855 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7856
7857 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7858 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7859 }
7860 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7861 mLastModemActivityInfo.setReceiveTimeMillis(
7862 rat,
7863 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7864 }
7865
7866 /**
7867 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7868 * @param info recent ModemActivityInfo
7869 */
7870 private void mergeModemActivityInfo(ModemActivityInfo info) {
7871 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08007872 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08007873 boolean matched;
7874 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7875 matched = false;
7876 int rat = info.getSpecificInfoRat(i);
7877 int freq = info.getSpecificInfoFrequencyRange(i);
7878 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7879 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7880 //if it already exists
7881 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7882 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7883 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7884 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7885 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7886 updateLastModemActivityInfo(info, rat, freq);
7887 matched = true;
7888 }
7889 } else {
7890 updateLastModemActivityInfo(info, rat);
7891 matched = true;
7892 }
7893 }
7894 }
7895
7896 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08007897 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08007898 new ActivityStatsTechSpecificInfo(
7899 rat,
7900 freq,
7901 info.getTransmitTimeMillis(rat, freq),
7902 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08007903 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08007904 }
7905 }
7906 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7907 mLastModemActivitySpecificInfo =
7908 new ActivityStatsTechSpecificInfo[merged.size()];
7909 merged.toArray(mLastModemActivitySpecificInfo);
7910
7911 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7912 mLastModemActivityInfo.setSleepTimeMillis(
7913 info.getSleepTimeMillis()
7914 + mLastModemActivityInfo.getSleepTimeMillis());
7915 mLastModemActivityInfo.setIdleTimeMillis(
7916 info.getIdleTimeMillis()
7917 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08007918
7919 mLastModemActivityInfo =
7920 new ModemActivityInfo(
7921 mLastModemActivityInfo.getTimestampMillis(),
7922 mLastModemActivityInfo.getSleepTimeMillis(),
7923 mLastModemActivityInfo.getIdleTimeMillis(),
7924 mLastModemActivitySpecificInfo);
7925 }
7926
7927 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
7928 ActivityStatsTechSpecificInfo[] info) {
7929 int infoSize = info.length;
7930 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
7931 for (int i = 0; i < infoSize; i++) {
7932 ret[i] = new ActivityStatsTechSpecificInfo(
7933 info[i].getRat(), info[i].getFrequencyRange(),
7934 info[i].getTransmitTimeMillis(),
7935 (int) info[i].getReceiveTimeMillis());
7936 }
7937 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08007938 }
7939
Jack Yu85bd38a2015-11-09 11:34:32 -08007940 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007941 * Returns the service state information on specified subscription.
7942 */
7943 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007944 public ServiceState getServiceStateForSubscriber(int subId,
7945 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7946 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007947 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007948 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007949 return null;
7950 }
7951
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007952 boolean hasFinePermission = false;
7953 boolean hasCoarsePermission = false;
7954 if (!renounceFineLocationAccess) {
7955 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7956 LocationAccessPolicy.checkLocationPermission(mApp,
7957 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7958 .setCallingPackage(callingPackage)
7959 .setCallingFeatureId(callingFeatureId)
7960 .setCallingPid(Binder.getCallingPid())
7961 .setCallingUid(Binder.getCallingUid())
7962 .setMethod("getServiceStateForSubscriber")
7963 .setLogAsInfo(true)
7964 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7965 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7966 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7967 .build());
7968 hasFinePermission =
7969 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7970 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007971
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007972 if (!renounceCoarseLocationAccess) {
7973 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7974 LocationAccessPolicy.checkLocationPermission(mApp,
7975 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7976 .setCallingPackage(callingPackage)
7977 .setCallingFeatureId(callingFeatureId)
7978 .setCallingPid(Binder.getCallingPid())
7979 .setCallingUid(Binder.getCallingUid())
7980 .setMethod("getServiceStateForSubscriber")
7981 .setLogAsInfo(true)
7982 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7983 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7984 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7985 .build());
7986 hasCoarsePermission =
7987 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7988 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007989
Jack Yu479f40e2020-10-27 21:29:25 -07007990 final Phone phone = getPhone(subId);
7991 if (phone == null) {
7992 return null;
7993 }
7994
Jordan Liu0f2bc442020-11-18 16:47:37 -08007995 final long identity = Binder.clearCallingIdentity();
7996
Jack Yu479f40e2020-10-27 21:29:25 -07007997 boolean isCallingPackageDataService = phone.getDataServicePackages()
7998 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007999 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008000 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yudf049d72022-12-02 22:48:35 -08008001 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8002 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8003 .getSubscriptionInfoInternal(subId);
8004 if (subInfo == null || !subInfo.isActive()) {
8005 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8006 + "subId=" + subId);
8007 return null;
8008 }
8009 } else {
8010 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8011 callingFeatureId)) {
8012 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8013 + "subId=" + subId);
8014 return null;
8015 }
Jordan Liuc437b192020-08-17 10:59:12 -07008016 }
8017
Hall Liuf19c44f2018-11-27 14:38:17 -08008018 ServiceState ss = phone.getServiceState();
8019
8020 // Scrub out the location info in ServiceState depending on what level of access
8021 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008022 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008023 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8024 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008025 } finally {
8026 Binder.restoreCallingIdentity(identity);
8027 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008028 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008029
8030 /**
8031 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8032 *
8033 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8034 * voicemail ringtone.
8035 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8036 * PhoneAccount.
8037 */
8038 @Override
8039 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008040 final long identity = Binder.clearCallingIdentity();
8041 try {
8042 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8043 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008044 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008045 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8048 } finally {
8049 Binder.restoreCallingIdentity(identity);
8050 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008051 }
8052
8053 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008054 * Sets the per-account voicemail ringtone.
8055 *
8056 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8057 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8058 *
8059 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8060 * voicemail ringtone.
8061 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8062 * PhoneAccount.
8063 */
8064 @Override
8065 public void setVoicemailRingtoneUri(String callingPackage,
8066 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008067 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008068 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008069 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8070 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8072 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8073 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075
8076 final long identity = Binder.clearCallingIdentity();
8077 try {
8078 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8079 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008080 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081 }
8082 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8083 } finally {
8084 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008085 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008086 }
8087
8088 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008089 * Returns whether vibration is set for voicemail notification in Phone settings.
8090 *
8091 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8092 * voicemail vibration setting.
8093 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8094 */
8095 @Override
8096 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 final long identity = Binder.clearCallingIdentity();
8098 try {
8099 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8100 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008101 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008102 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8105 } finally {
8106 Binder.restoreCallingIdentity(identity);
8107 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008108 }
8109
Youhan Wange64578a2016-05-02 15:32:42 -07008110 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008111 * Sets the per-account voicemail vibration.
8112 *
8113 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8114 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8115 *
8116 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8117 * voicemail vibration setting.
8118 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8119 * specific PhoneAccount.
8120 */
8121 @Override
8122 public void setVoicemailVibrationEnabled(String callingPackage,
8123 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008124 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008125 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008126 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8127 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8129 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8130 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008131 }
8132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133 final long identity = Binder.clearCallingIdentity();
8134 try {
8135 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8136 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008137 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008138 }
8139 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8140 } finally {
8141 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008142 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008143 }
8144
8145 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008146 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8147 *
8148 * @throws SecurityException if the caller does not have the required permission
8149 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008150 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008151 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008152 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008153 }
8154
8155 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008156 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8157 * permission.
8158 *
8159 * @throws SecurityException if the caller does not have the required permission
8160 */
8161 private void enforceSendSmsPermission() {
8162 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8163 }
8164
8165 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008166 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008167 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008168 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008169 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008170 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008171 final long identity = Binder.clearCallingIdentity();
8172 try {
8173 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008174 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008175 if (componentName == null) {
8176 throw new SecurityException(
8177 "Caller not current active visual voicemail package[null]");
8178 }
8179 String vvmPackage = componentName.getPackageName();
8180 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008181 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008182 }
8183 } finally {
8184 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008185 }
8186 }
8187
8188 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008189 * Return the application ID for the app type.
8190 *
8191 * @param subId the subscription ID that this request applies to.
8192 * @param appType the uicc app type.
8193 * @return Application ID for specificied app type, or null if no uicc.
8194 */
8195 @Override
8196 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008197 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008198 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008199
8200 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008201 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008202 if (phone == null) {
8203 return null;
8204 }
8205 String aid = null;
8206 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008207 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008208 .getApplicationByType(appType).getAid();
8209 } catch (Exception e) {
8210 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8211 }
8212 return aid;
8213 } finally {
8214 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008215 }
Youhan Wange64578a2016-05-02 15:32:42 -07008216 }
8217
Youhan Wang4001d252016-05-11 10:29:41 -07008218 /**
8219 * Return the Electronic Serial Number.
8220 *
8221 * @param subId the subscription ID that this request applies to.
8222 * @return ESN or null if error.
8223 */
8224 @Override
8225 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008226 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008227 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008228
8229 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008230 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008231 if (phone == null) {
8232 return null;
8233 }
8234 String esn = null;
8235 try {
8236 esn = phone.getEsn();
8237 } catch (Exception e) {
8238 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8239 }
8240 return esn;
8241 } finally {
8242 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008243 }
Youhan Wang4001d252016-05-11 10:29:41 -07008244 }
8245
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008246 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008247 * Return the Preferred Roaming List Version.
8248 *
8249 * @param subId the subscription ID that this request applies to.
8250 * @return PRLVersion or null if error.
8251 */
8252 @Override
8253 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008254 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008255 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008256
8257 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008258 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008259 if (phone == null) {
8260 return null;
8261 }
8262 String cdmaPrlVersion = null;
8263 try {
8264 cdmaPrlVersion = phone.getCdmaPrlVersion();
8265 } catch (Exception e) {
8266 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8267 }
8268 return cdmaPrlVersion;
8269 } finally {
8270 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008271 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008272 }
8273
8274 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008275 * Get snapshot of Telephony histograms
8276 * @return List of Telephony histograms
8277 * @hide
8278 */
8279 @Override
8280 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8282 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283
8284 final long identity = Binder.clearCallingIdentity();
8285 try {
8286 return RIL.getTelephonyRILTimingHistograms();
8287 } finally {
8288 Binder.restoreCallingIdentity(identity);
8289 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008290 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008291
8292 /**
8293 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008294 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8295 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008296 * Require system privileges. In the future we may add this to carrier APIs.
8297 *
Michele Berionne482f8202018-11-27 18:57:59 -08008298 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008299 */
8300 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008301 @TelephonyManager.SetCarrierRestrictionResult
8302 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008303 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008304 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008305
Michele Berionne482f8202018-11-27 18:57:59 -08008306 if (carrierRestrictionRules == null) {
8307 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008308 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008309
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008310 final long identity = Binder.clearCallingIdentity();
8311 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008312 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008313 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008314 } finally {
8315 Binder.restoreCallingIdentity(identity);
8316 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008317 }
8318
8319 /**
8320 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008321 * Get the allowed carrier list and the excluded carrier list, including the priority between
8322 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008323 * Require system privileges. In the future we may add this to carrier APIs.
8324 *
Michele Berionne482f8202018-11-27 18:57:59 -08008325 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008326 */
8327 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008328 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008329 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008330 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008331
8332 final long identity = Binder.clearCallingIdentity();
8333 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008334 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8335 if (response instanceof CarrierRestrictionRules) {
8336 return (CarrierRestrictionRules) response;
8337 }
8338 // Response is an Exception of some kind,
8339 // which is signalled to the user as a NULL retval
8340 return null;
8341 } catch (Exception e) {
8342 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8343 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008344 } finally {
8345 Binder.restoreCallingIdentity(identity);
8346 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008347 }
8348
fionaxu59545b42016-05-25 15:53:37 -07008349 /**
fionaxu59545b42016-05-25 15:53:37 -07008350 * Action set from carrier signalling broadcast receivers to enable/disable radio
8351 * @param subId the subscription ID that this action applies to.
8352 * @param enabled control enable or disable radio.
8353 * {@hide}
8354 */
8355 @Override
8356 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8357 enforceModifyPermission();
8358 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008359
8360 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008361 if (phone == null) {
8362 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8363 return;
8364 }
8365 try {
8366 phone.carrierActionSetRadioEnabled(enabled);
8367 } catch (Exception e) {
8368 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369 } finally {
8370 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008371 }
8372 }
8373
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008374 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008375 * Enable or disable Voice over NR (VoNR)
8376 * @param subId the subscription ID that this action applies to.
8377 * @param enabled enable or disable VoNR.
8378 * @return operation result.
8379 */
8380 @Override
8381 public int setVoNrEnabled(int subId, boolean enabled) {
8382 enforceModifyPermission();
8383 final Phone phone = getPhone(subId);
8384
8385 final long identity = Binder.clearCallingIdentity();
8386 if (phone == null) {
8387 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8388 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8389 }
8390
8391 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8392 try {
8393 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8394 workSource);
8395 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008396
8397 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8398 if (DBG) {
8399 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8400 }
8401 SubscriptionManager.setSubscriptionProperty(
8402 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8403 (enabled ? "1" : "0"));
8404 }
8405
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008406 return result;
8407 } finally {
8408 Binder.restoreCallingIdentity(identity);
8409 }
8410 }
8411
8412 /**
8413 * Is voice over NR enabled
8414 * @return true if VoNR is enabled else false
8415 */
8416 @Override
8417 public boolean isVoNrEnabled(int subId) {
8418 enforceReadPrivilegedPermission("isVoNrEnabled");
8419 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8420 final long identity = Binder.clearCallingIdentity();
8421 try {
8422 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8423 null, subId, workSource);
8424 if (DBG) log("isVoNrEnabled: " + isEnabled);
8425 return isEnabled;
8426 } finally {
8427 Binder.restoreCallingIdentity(identity);
8428 }
8429 }
8430
8431 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008432 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8433 * network status based on which carrier apps could apply actions accordingly,
8434 * enable/disable default url handler for example.
8435 *
8436 * @param subId the subscription ID that this action applies to.
8437 * @param report control start/stop reporting the default network status.
8438 * {@hide}
8439 */
8440 @Override
8441 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8442 enforceModifyPermission();
8443 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008444
8445 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008446 if (phone == null) {
8447 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8448 return;
8449 }
8450 try {
8451 phone.carrierActionReportDefaultNetworkStatus(report);
8452 } catch (Exception e) {
8453 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008454 } finally {
8455 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008456 }
8457 }
8458
8459 /**
fionaxud9622282017-07-17 17:51:30 -07008460 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8461 * @param subId the subscription ID that this action applies to.
8462 * {@hide}
8463 */
8464 @Override
8465 public void carrierActionResetAll(int subId) {
8466 enforceModifyPermission();
8467 final Phone phone = getPhone(subId);
8468 if (phone == null) {
8469 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8470 return;
8471 }
8472 try {
8473 phone.carrierActionResetAll();
8474 } catch (Exception e) {
8475 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8476 }
8477 }
8478
8479 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008480 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8481 * bug report is being generated.
8482 */
8483 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008484 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008485 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8486 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008487 writer.println("Permission Denial: can't dump Phone from pid="
8488 + Binder.getCallingPid()
8489 + ", uid=" + Binder.getCallingUid()
8490 + "without permission "
8491 + android.Manifest.permission.DUMP);
8492 return;
8493 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008494 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008495 }
Jack Yueb89b242016-06-22 13:27:47 -07008496
Brad Ebingerdac2f002018-04-03 15:17:52 -07008497 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008498 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8499 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8500 @NonNull String[] args) {
8501 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8502 this, in.getFileDescriptor(), out.getFileDescriptor(),
8503 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008504 }
8505
Jack Yueb89b242016-06-22 13:27:47 -07008506 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008507 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008508 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008509 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008510 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008511 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008512 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008513 */
8514 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008515 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008516 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008517 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8518 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8519 try {
8520 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008521 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008522 } catch (SecurityException se) {
8523 enforceModifyPermission();
8524 }
8525 } else {
8526 enforceModifyPermission();
8527 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008528
8529 final long identity = Binder.clearCallingIdentity();
8530 try {
8531 Phone phone = getPhone(subId);
8532 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008533 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8534 phone.carrierActionSetMeteredApnsEnabled(enabled);
8535 } else {
Jack Yuabb10902022-07-31 00:43:21 -07008536 phone.getDataSettingsManager().setDataEnabled(
8537 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008539 }
8540 } finally {
8541 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008542 }
8543 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008544
8545 /**
8546 * Get Client request stats
8547 * @return List of Client Request Stats
8548 * @hide
8549 */
8550 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008551 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8552 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008553 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008554 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008555 return null;
8556 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008557 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008559 final long identity = Binder.clearCallingIdentity();
8560 try {
8561 if (phone != null) {
8562 return phone.getClientRequestStats();
8563 }
8564
8565 return null;
8566 } finally {
8567 Binder.restoreCallingIdentity(identity);
8568 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008569 }
8570
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008571 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008572 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008573 if (uid == Process.ROOT_UID && packageName == null) {
8574 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8575 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8576 // exception. ROOT_UID seems not to have a valid package name returned by
8577 // PackageManager, so just fake it here to avoid issues when running telephony shell
8578 // commands that plumb through the RIL as root, like so:
8579 // $ adb root
8580 // $ adb shell cmd phone ...
8581 packageName = "root";
8582 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008583 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008584 }
Jack Yueb4124c2017-02-16 15:32:43 -08008585
8586 /**
Grace Chen70990072017-03-24 17:21:30 -07008587 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008588 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008589 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008590 * @param state State of SIM (power down, power up, pass through)
8591 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8592 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8593 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008594 *
8595 **/
8596 @Override
Grace Chen70990072017-03-24 17:21:30 -07008597 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008598 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008599 Phone phone = PhoneFactory.getPhone(slotIndex);
8600
vagdeviaf9a5b92018-08-15 16:01:53 -07008601 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008603 final long identity = Binder.clearCallingIdentity();
8604 try {
8605 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008606 phone.setSimPowerState(state, null, workSource);
8607 }
8608 } finally {
8609 Binder.restoreCallingIdentity(identity);
8610 }
8611 }
8612
8613 /**
8614 * Set SIM card power state.
8615 *
8616 * @param slotIndex SIM slot id.
8617 * @param state State of SIM (power down, power up, pass through)
8618 * @param callback callback to trigger after success or failure
8619 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8620 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8621 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8622 *
8623 **/
8624 @Override
8625 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8626 IIntegerConsumer callback) {
8627 enforceModifyPermission();
8628 Phone phone = PhoneFactory.getPhone(slotIndex);
8629
8630 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8631
8632 final long identity = Binder.clearCallingIdentity();
8633 try {
8634 if (phone != null) {
8635 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8636 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008637 }
8638 } finally {
8639 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008640 }
8641 }
Shuo Qiandd210312017-04-12 22:11:33 +00008642
Tyler Gunn65d45c22017-06-05 11:22:26 -07008643 private boolean isUssdApiAllowed(int subId) {
8644 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008645 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008646 if (configManager == null) {
8647 return false;
8648 }
8649 PersistableBundle pb = configManager.getConfigForSubId(subId);
8650 if (pb == null) {
8651 return false;
8652 }
8653 return pb.getBoolean(
8654 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8655 }
8656
Shuo Qiandd210312017-04-12 22:11:33 +00008657 /**
8658 * Check if phone is in emergency callback mode
8659 * @return true if phone is in emergency callback mode
8660 * @param subId sub id
8661 */
goneil9c5f4872017-12-05 14:07:56 -08008662 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008663 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008664 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008665 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008666
8667 final long identity = Binder.clearCallingIdentity();
8668 try {
8669 if (phone != null) {
8670 return phone.isInEcm();
8671 } else {
8672 return false;
8673 }
8674 } finally {
8675 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008676 }
8677 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008678
8679 /**
8680 * Get the current signal strength information for the given subscription.
8681 * Because this information is not updated when the device is in a low power state
8682 * it should not be relied-upon to be current.
8683 * @param subId Subscription index
8684 * @return the most recent cached signal strength info from the modem
8685 */
8686 @Override
8687 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008688 final long identity = Binder.clearCallingIdentity();
8689 try {
8690 Phone p = getPhone(subId);
8691 if (p == null) {
8692 return null;
8693 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008695 return p.getSignalStrength();
8696 } finally {
8697 Binder.restoreCallingIdentity(identity);
8698 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008699 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008700
Pengquan Meng77b7f132018-08-22 14:49:57 -07008701 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008702 * Get the current modem radio state for the given slot.
8703 * @param slotIndex slot index.
8704 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008705 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008706 * @return the current radio power state from the modem
8707 */
8708 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008709 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008710 Phone phone = PhoneFactory.getPhone(slotIndex);
8711 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8713 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008714 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8715 }
8716
8717 final long identity = Binder.clearCallingIdentity();
8718 try {
8719 return phone.getRadioPowerState();
8720 } finally {
8721 Binder.restoreCallingIdentity(identity);
8722 }
8723 }
8724 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8725 }
8726
8727 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008728 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8729 *
8730 * <p>Requires one of the following permissions:
8731 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008732 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008733 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8734 * privileges.
8735 *
8736 * @param subId subscription id
8737 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8738 * {@code false}.
8739 */
8740 @Override
8741 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008742 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008743 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008744 try {
8745 mApp.enforceCallingOrSelfPermission(
8746 android.Manifest.permission.ACCESS_NETWORK_STATE,
8747 functionName);
8748 } catch (Exception e) {
8749 mApp.enforceCallingOrSelfPermission(
8750 permission.READ_BASIC_PHONE_STATE, functionName);
8751 }
Shuo Qian093013d2020-08-13 15:42:55 -07008752 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008753 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008754 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008755 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008756
Pengquan Menga1bb6272018-09-06 09:59:22 -07008757 boolean isEnabled = false;
8758 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008759 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008760 Phone phone = getPhone(subId);
8761 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008762 } finally {
8763 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008764 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008765 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008766 }
8767
8768
8769 /**
8770 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8771 *
8772 * <p> Requires permission:
8773 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8774 * privileges.
8775 *
8776 * @param subId subscription id
8777 * @param isEnabled {@code true} means enable, {@code false} means disable.
8778 */
8779 @Override
8780 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8782 mApp, subId, "setDataRoamingEnabled");
8783
Pengquan Menga1bb6272018-09-06 09:59:22 -07008784 final long identity = Binder.clearCallingIdentity();
8785 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008786 Phone phone = getPhone(subId);
8787 if (phone != null) {
8788 phone.setDataRoamingEnabled(isEnabled);
8789 }
8790 } finally {
8791 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008792 }
8793 }
8794
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008795 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008796 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008797 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008798 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008799 mApp, subId, "isManualNetworkSelectionAllowed");
8800
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008801 boolean isAllowed = true;
8802 final long identity = Binder.clearCallingIdentity();
8803 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008804 Phone phone = getPhone(subId);
8805 if (phone != null) {
8806 isAllowed = phone.isCspPlmnEnabled();
8807 }
8808 } finally {
8809 Binder.restoreCallingIdentity(identity);
8810 }
8811 return isAllowed;
8812 }
8813
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008814 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8815 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008816 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008817 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008818 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008819 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8820 if (phone == null) {
8821 return false;
8822 }
8823 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8824 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8825 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008826 }
8827
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008828 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008829 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008830 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008831 mApp.getSystemService(AppOpsManager.class)
8832 .checkPackage(Binder.getCallingUid(), callingPackage);
8833
Jordan Liu1e142fc2019-04-22 15:10:43 -07008834 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008835 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008836 try {
8837 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008838 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008839 } catch (SecurityException e) {
8840 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8841 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008842 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008843 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008844 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008845 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008846 }
sandeepjsb6c87872021-09-27 15:34:44 +00008847 // checking compatibility, if calling app's target SDK is T and beyond.
8848 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8849 Binder.getCallingUid())) {
8850 isIccIdAccessRestricted = true;
8851 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008852 final long identity = Binder.clearCallingIdentity();
8853 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008854 UiccController uiccController = UiccController.getInstance();
8855 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008856 if (hasReadPermission) {
8857 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008858 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008859
8860 // Remove private info if the caller doesn't have access
8861 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8862 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008863 //setting the value after compatibility check
8864 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008865 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8866 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008867 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008868 if (card == null) {
8869 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008870 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008871 continue;
8872 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008873 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8874 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008875 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008876 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008877 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008878 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8879 for (UiccPortInfo portInfo : portInfos) {
8880 UiccPort port = uiccController.getUiccPortForSlot(
8881 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8882 if (port == null) {
8883 // assume no access if port is null
8884 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8885 continue;
8886 }
8887 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8888 uiccPortInfos.add(portInfo);
8889 } else {
8890 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8891 }
8892 }
8893 filteredInfos.add(new UiccCardInfo(
8894 cardInfo.isEuicc(),
8895 cardInfo.getCardId(),
8896 null,
8897 cardInfo.getPhysicalSlotIndex(),
8898 cardInfo.isRemovable(),
8899 cardInfo.isMultipleEnabledProfilesSupported(),
8900 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008901 }
8902 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008903 } finally {
8904 Binder.restoreCallingIdentity(identity);
8905 }
8906 }
8907
sandeepjsb6c87872021-09-27 15:34:44 +00008908 /**
8909 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8910 * generally private and require carrier privileges to view.
8911 *
8912 * @hide
8913 */
8914 @NonNull
8915 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8916 List<UiccPortInfo> portinfo = new ArrayList<>();
8917 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8918 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8919 }
8920 return new UiccCardInfo(
8921 cardInfo.isEuicc(),
8922 cardInfo.getCardId(),
8923 null,
8924 cardInfo.getPhysicalSlotIndex(),
8925 cardInfo.isRemovable(),
8926 cardInfo.isMultipleEnabledProfilesSupported(),
8927 portinfo
8928 );
8929 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008930
sandeepjsb6c87872021-09-27 15:34:44 +00008931 /**
8932 * @hide
8933 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8934 * These values are generally private and require carrier privileges to view.
8935 */
8936 @NonNull
8937 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8938 return new UiccPortInfo(
8939 UiccPortInfo.ICCID_REDACTED,
8940 portInfo.getPortIndex(),
8941 portInfo.getLogicalSlotIndex(),
8942 portInfo.isActive()
8943 );
8944 }
8945 @Override
8946 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008947 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008948 mApp.getSystemService(AppOpsManager.class)
8949 .checkPackage(Binder.getCallingUid(), callingPackage);
8950
sandeepjsb6c87872021-09-27 15:34:44 +00008951 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008952
Aman Guptaf3c90b32022-03-17 04:54:16 +00008953 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8954 // we are reading iccId which is PII data.
8955 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008956
8957 // checking compatibility, if calling app's target SDK is T and beyond.
8958 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8959 Binder.getCallingUid())) {
8960 isLogicalSlotAccessRestricted = true;
8961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008962 final long identity = Binder.clearCallingIdentity();
8963 try {
8964 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008965 if (slots == null || slots.length == 0) {
8966 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008967 return null;
8968 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008969 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8970 for (int i = 0; i < slots.length; i++) {
8971 UiccSlot slot = slots[i];
8972 if (slot == null) {
8973 continue;
8974 }
8975
Jordan Liu7be7e652019-05-06 18:55:02 +00008976 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008977 UiccCard card = slot.getUiccCard();
8978 if (card != null) {
8979 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008980 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008981 cardId = slot.getEid();
8982 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00008983 // If cardId is null, use iccId of default port as cardId.
8984 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07008985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008986 }
8987
Jordan Liu857451f2019-05-09 16:35:35 -07008988 if (cardId != null) {
8989 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8990 // if cardId is an EID, it's all digits so this is fine
8991 cardId = IccUtils.stripTrailingFs(cardId);
8992 }
8993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008994 int cardState = 0;
8995 switch (slot.getCardState()) {
8996 case CARDSTATE_ABSENT:
8997 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8998 break;
8999 case CARDSTATE_PRESENT:
9000 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9001 break;
9002 case CARDSTATE_ERROR:
9003 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9004 break;
9005 case CARDSTATE_RESTRICTED:
9006 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9007 break;
9008 default:
9009 break;
9010
9011 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009012 List<UiccPortInfo> portInfos = new ArrayList<>();
9013 int[] portIndexes = slot.getPortList();
9014 for (int portIdx : portIndexes) {
9015 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009016 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009017 portInfos.add(new UiccPortInfo(iccId, portIdx,
9018 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009020 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009021 slot.isEuicc(),
9022 cardId,
9023 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009024 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009025 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009026 //setting the value after compatibility check
9027 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009028 }
9029 return infos;
9030 } finally {
9031 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009032 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009033 }
9034
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009035 /* Returns null if doesn't have read permission or carrier privilege access. */
9036 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9037 boolean hasReadPermission) {
9038 String iccId = slot.getIccId(portIndex);
9039 if (hasReadPermission) { // if has read permission
9040 return iccId;
9041 } else {
9042 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9043 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9044 // if no read permission, checking carrier privilege access
9045 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9046 return iccId;
9047 }
9048 }
9049 }
9050 // No read permission or carrier privilege access.
9051 return UiccPortInfo.ICCID_REDACTED;
9052 }
9053
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009054 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009055 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009056 public boolean switchSlots(int[] physicalSlots) {
9057 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009058
9059 final long identity = Binder.clearCallingIdentity();
9060 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009061 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9062 for (int i = 0; i < physicalSlots.length; i++) {
9063 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9064 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9065 physicalSlots[i], i));
9066 }
9067 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009068 } finally {
9069 Binder.restoreCallingIdentity(identity);
9070 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009071 }
Jack Yu4c988042018-02-27 15:30:01 -08009072
9073 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009074 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9075 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9076 enforceModifyPermission();
9077
9078 final long identity = Binder.clearCallingIdentity();
9079 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009080 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009081 } finally {
9082 Binder.restoreCallingIdentity(identity);
9083 }
9084 }
9085
9086 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009087 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009088 final long identity = Binder.clearCallingIdentity();
9089 try {
9090 return UiccController.getInstance().getCardIdForDefaultEuicc();
9091 } finally {
9092 Binder.restoreCallingIdentity(identity);
9093 }
9094 }
9095
Pengquan Meng85728fb2018-03-12 16:31:21 -07009096 /**
goneil47ffb6e2018-04-06 15:40:58 -07009097 * A test API to reload the UICC profile.
9098 *
9099 * <p>Requires that the calling app has permission
9100 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9101 * @hide
9102 */
9103 @Override
9104 public void refreshUiccProfile(int subId) {
9105 enforceModifyPermission();
9106
9107 final long identity = Binder.clearCallingIdentity();
9108 try {
9109 Phone phone = getPhone(subId);
9110 if (phone == null) {
9111 return;
9112 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009113 UiccPort uiccPort = phone.getUiccPort();
9114 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009115 return;
9116 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009117 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009118 if (uiccProfile == null) {
9119 return;
9120 }
9121 uiccProfile.refresh();
9122 } finally {
9123 Binder.restoreCallingIdentity(identity);
9124 }
9125 }
9126
9127 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009128 * Returns false if the mobile data is disabled by default, otherwise return true.
9129 */
9130 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009131 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009132 }
9133
9134 /**
9135 * Returns true if the data roaming is enabled by default, i.e the system property
9136 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9137 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9138 */
9139 private boolean getDefaultDataRoamingEnabled(int subId) {
9140 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009141 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009142 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009143 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9144 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9145 return isDataRoamingEnabled;
9146 }
9147
9148 /**
9149 * Returns the default network type for the given {@code subId}, if the default network type is
9150 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9151 */
9152 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009153 List<Integer> list = TelephonyProperties.default_network();
Jack Yudf049d72022-12-02 22:48:35 -08009154 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009155 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9156 return list.get(phoneId);
9157 }
9158 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009159 }
fionaxua13278b2018-03-21 00:08:13 -07009160
9161 @Override
9162 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009163 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009164 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009165
9166 final long identity = Binder.clearCallingIdentity();
9167 try {
9168 final Phone phone = getPhone(subId);
9169 if (phone == null) {
9170 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9171 return;
9172 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009173 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9174 if (cpt != null) {
9175 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9176 }
9177 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009178 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9179 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009180 if (carrierPrivilegeRules == null) {
9181 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9182 } else {
9183 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9184 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009185 } finally {
9186 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009187 }
fionaxua13278b2018-03-21 00:08:13 -07009188 }
9189
9190 @Override
Benedict Wong45280102023-02-03 23:30:57 +00009191 public void setCarrierServicePackageOverride(
9192 int subId, String carrierServicePackage, String callingPackage) {
9193 TelephonyPermissions.enforceShellOnly(
9194 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9195
9196 // Verify that the callingPackage belongs to the calling UID
9197 mApp.getSystemService(AppOpsManager.class)
9198 .checkPackage(Binder.getCallingUid(), callingPackage);
9199
9200 final long identity = Binder.clearCallingIdentity();
9201 try {
9202 final Phone phone = getPhone(subId);
9203 if (phone == null || phone.getSubId() != subId) {
9204 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9205 throw new IllegalArgumentException("No phone for subid");
9206 }
9207 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9208 if (cpt == null) {
9209 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9210 throw new IllegalStateException("No CPT for phone");
9211 }
9212 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9213 } finally {
9214 Binder.restoreCallingIdentity(identity);
9215 }
9216 }
9217
9218 @Override
fionaxua13278b2018-03-21 00:08:13 -07009219 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009220 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009221
9222 final long identity = Binder.clearCallingIdentity();
9223 try {
9224 final Phone phone = getPhone(subId);
9225 if (phone == null) {
9226 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9227 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9228 }
9229 return phone.getCarrierIdListVersion();
9230 } finally {
9231 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009232 }
fionaxua13278b2018-03-21 00:08:13 -07009233 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009234
9235 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009236 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9237 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009239 mApp, subId, callingPackage, callingFeatureId,
9240 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009241 return -1;
9242 }
9243
9244 final long identity = Binder.clearCallingIdentity();
9245 try {
9246 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9247 } finally {
9248 Binder.restoreCallingIdentity(identity);
9249 }
9250 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009251
9252 @Override
9253 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009254 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009255 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009256 mApp, subId, "getCdmaRoamingMode");
9257
9258 final long identity = Binder.clearCallingIdentity();
9259 try {
9260 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9261 } finally {
9262 Binder.restoreCallingIdentity(identity);
9263 }
9264 }
9265
9266 @Override
9267 public boolean setCdmaRoamingMode(int subId, int mode) {
9268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9269 mApp, subId, "setCdmaRoamingMode");
9270
9271 final long identity = Binder.clearCallingIdentity();
9272 try {
9273 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9274 } finally {
9275 Binder.restoreCallingIdentity(identity);
9276 }
9277 }
9278
9279 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009280 public int getCdmaSubscriptionMode(int subId) {
9281 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009282 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009283 mApp, subId, "getCdmaSubscriptionMode");
9284
9285 final long identity = Binder.clearCallingIdentity();
9286 try {
9287 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9288 } finally {
9289 Binder.restoreCallingIdentity(identity);
9290 }
9291 }
9292
9293 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009294 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9296 mApp, subId, "setCdmaSubscriptionMode");
9297
9298 final long identity = Binder.clearCallingIdentity();
9299 try {
9300 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9301 } finally {
9302 Binder.restoreCallingIdentity(identity);
9303 }
9304 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009305
sqianc5eccab2018-10-19 18:46:41 -07009306 @Override
sqian8c685422019-02-22 15:55:18 -08009307 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009308 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009310 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9311 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009312 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9313 }
9314 final long identity = Binder.clearCallingIdentity();
9315 try {
sqian854d44b2018-12-12 16:48:18 -08009316 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9317 for (Phone phone: PhoneFactory.getPhones()) {
9318 if (phone.getEmergencyNumberTracker() != null
9319 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9320 emergencyNumberListInternal.put(
9321 phone.getSubId(),
9322 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9323 }
sqian11b7a0e2018-12-05 18:48:28 -08009324 }
sqian854d44b2018-12-12 16:48:18 -08009325 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009326 } finally {
9327 Binder.restoreCallingIdentity(identity);
9328 }
sqianc5eccab2018-10-19 18:46:41 -07009329 }
9330
9331 @Override
sqian8c685422019-02-22 15:55:18 -08009332 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009333 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009334 if (!exactMatch) {
9335 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009336 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009337 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009338 }
9339 final long identity = Binder.clearCallingIdentity();
9340 try {
sqian854d44b2018-12-12 16:48:18 -08009341 for (Phone phone: PhoneFactory.getPhones()) {
9342 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009343 && phone.getEmergencyNumberTracker()
9344 .isEmergencyNumber(number, exactMatch)) {
9345 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009346 }
sqian11b7a0e2018-12-05 18:48:28 -08009347 }
9348 return false;
9349 } finally {
9350 Binder.restoreCallingIdentity(identity);
9351 }
9352 }
9353
sqianf4ca7ed2019-01-15 18:32:07 -08009354 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009355 * Start emergency callback mode for GsmCdmaPhone for testing.
9356 */
9357 @Override
9358 public void startEmergencyCallbackMode() {
9359 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9360 "startEmergencyCallbackMode");
9361 enforceModifyPermission();
9362 final long identity = Binder.clearCallingIdentity();
9363 try {
9364 for (Phone phone : PhoneFactory.getPhones()) {
9365 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9366 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9367 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9368 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9369 gsmCdmaPhone.obtainMessage(
9370 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9371 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9372 }
9373 }
9374 } finally {
9375 Binder.restoreCallingIdentity(identity);
9376 }
9377 }
9378
9379 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009380 * Update emergency number list for test mode.
9381 */
9382 @Override
9383 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9384 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9385 "updateEmergencyNumberListTestMode");
9386
9387 final long identity = Binder.clearCallingIdentity();
9388 try {
9389 for (Phone phone: PhoneFactory.getPhones()) {
9390 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9391 if (tracker != null) {
9392 tracker.executeEmergencyNumberTestModeCommand(action, num);
9393 }
9394 }
9395 } finally {
9396 Binder.restoreCallingIdentity(identity);
9397 }
9398 }
9399
9400 /**
9401 * Get the full emergency number list for test mode.
9402 */
9403 @Override
9404 public List<String> getEmergencyNumberListTestMode() {
9405 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9406 "getEmergencyNumberListTestMode");
9407
9408 final long identity = Binder.clearCallingIdentity();
9409 try {
9410 Set<String> emergencyNumbers = new HashSet<>();
9411 for (Phone phone: PhoneFactory.getPhones()) {
9412 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9413 if (tracker != null) {
9414 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9415 emergencyNumbers.add(num.getNumber());
9416 }
9417 }
9418 }
9419 return new ArrayList<>(emergencyNumbers);
9420 } finally {
9421 Binder.restoreCallingIdentity(identity);
9422 }
9423 }
9424
chen xud6b45bd2018-10-30 22:27:10 -07009425 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009426 public int getEmergencyNumberDbVersion(int subId) {
9427 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9428
9429 final long identity = Binder.clearCallingIdentity();
9430 try {
9431 final Phone phone = getPhone(subId);
9432 if (phone == null) {
9433 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9434 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9435 }
9436 return phone.getEmergencyNumberDbVersion();
9437 } finally {
9438 Binder.restoreCallingIdentity(identity);
9439 }
9440 }
9441
9442 @Override
9443 public void notifyOtaEmergencyNumberDbInstalled() {
9444 enforceModifyPermission();
9445
9446 final long identity = Binder.clearCallingIdentity();
9447 try {
9448 for (Phone phone: PhoneFactory.getPhones()) {
9449 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9450 if (tracker != null) {
9451 tracker.updateOtaEmergencyNumberDatabase();
9452 }
9453 }
9454 } finally {
9455 Binder.restoreCallingIdentity(identity);
9456 }
9457 }
9458
9459 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009460 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009461 enforceActiveEmergencySessionPermission();
9462
9463 final long identity = Binder.clearCallingIdentity();
9464 try {
9465 for (Phone phone: PhoneFactory.getPhones()) {
9466 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9467 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009468 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9469 }
9470 }
9471 } finally {
9472 Binder.restoreCallingIdentity(identity);
9473 }
9474 }
9475
9476 @Override
9477 public void resetOtaEmergencyNumberDbFilePath() {
9478 enforceActiveEmergencySessionPermission();
9479
9480 final long identity = Binder.clearCallingIdentity();
9481 try {
9482 for (Phone phone: PhoneFactory.getPhones()) {
9483 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9484 if (tracker != null) {
9485 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009486 }
9487 }
9488 } finally {
9489 Binder.restoreCallingIdentity(identity);
9490 }
9491 }
9492
9493 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009494 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9495 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9496 Phone phone = getPhone(subId);
9497 if (phone == null) {
9498 return null;
9499 }
9500 final long identity = Binder.clearCallingIdentity();
9501 try {
9502 UiccProfile profile = UiccController.getInstance()
9503 .getUiccProfileForPhone(phone.getPhoneId());
9504 if (profile != null) {
9505 return profile.getCertsFromCarrierPrivilegeAccessRules();
9506 }
9507 } finally {
9508 Binder.restoreCallingIdentity(identity);
9509 }
9510 return null;
9511 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009512
9513 /**
9514 * Enable or disable a modem stack.
9515 */
9516 @Override
9517 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9518 enforceModifyPermission();
9519
9520 final long identity = Binder.clearCallingIdentity();
9521 try {
9522 Phone phone = PhoneFactory.getPhone(slotIndex);
9523 if (phone == null) {
9524 return false;
9525 } else {
9526 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9527 }
9528 } finally {
9529 Binder.restoreCallingIdentity(identity);
9530 }
9531 }
Michelecea4cf22018-12-21 15:00:11 -08009532
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009533 /**
9534 * Whether a modem stack is enabled or not.
9535 */
9536 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009537 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9538 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009539 Phone phone = PhoneFactory.getPhone(slotIndex);
9540 if (phone == null) return false;
9541
9542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009543 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9544 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009545 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9546 }
9547
9548 final long identity = Binder.clearCallingIdentity();
9549 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009550 try {
9551 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9552 } catch (NoSuchElementException ex) {
9553 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9554 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009555 } finally {
9556 Binder.restoreCallingIdentity(identity);
9557 }
9558 }
9559
Michelecea4cf22018-12-21 15:00:11 -08009560 @Override
Michele0ea7d782019-03-19 14:58:42 -07009561 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009562 enforceModifyPermission();
9563
9564 final long identity = Binder.clearCallingIdentity();
9565 try {
9566 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009567 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009568 .commit();
9569 } finally {
9570 Binder.restoreCallingIdentity(identity);
9571 }
9572 }
9573
9574 @Override
Michele0ea7d782019-03-19 14:58:42 -07009575 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009576 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009577 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009578 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9579 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009580 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009581 }
Michelecea4cf22018-12-21 15:00:11 -08009582
9583 final long identity = Binder.clearCallingIdentity();
9584 try {
Michele0ea7d782019-03-19 14:58:42 -07009585 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009586 } finally {
9587 Binder.restoreCallingIdentity(identity);
9588 }
9589 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009590
Michele0ea7d782019-03-19 14:58:42 -07009591 @TelephonyManager.IsMultiSimSupportedResult
9592 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009593 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9594 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9595 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009596 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9597 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009598 }
9599 // Check if the hardware supports multisim functionality. If usage of multisim is not
9600 // supported by the modem, indicate that it is restricted.
9601 PhoneCapability staticCapability =
9602 mPhoneConfigurationManager.getStaticPhoneCapability();
9603 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009604 loge("isMultiSimSupportedInternal: no static configuration available");
9605 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009606 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009607 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009608 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9609 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009610 }
9611 // Check if support of multiple SIMs is restricted by carrier
9612 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009613 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009614 }
9615
Michele0ea7d782019-03-19 14:58:42 -07009616 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009617 }
9618
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009619 /**
9620 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009621 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9622 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9623 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009624 * @param numOfSims number of active sims we want to switch to
9625 */
9626 @Override
9627 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009628 if (numOfSims == 1) {
9629 enforceModifyPermission();
9630 } else {
9631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9632 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9633 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009634 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009635
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009636 try {
Michele30b57b22019-03-01 12:01:14 -08009637 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009638 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009639 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9640 return;
9641 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009642 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9643 } finally {
9644 Binder.restoreCallingIdentity(identity);
9645 }
9646 }
9647
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009648 @Override
9649 public boolean isApplicationOnUicc(int subId, int appType) {
9650 enforceReadPrivilegedPermission("isApplicationOnUicc");
9651 Phone phone = getPhone(subId);
9652 if (phone == null) {
9653 return false;
9654 }
9655 final long identity = Binder.clearCallingIdentity();
9656 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009657 UiccPort uiccPort = phone.getUiccPort();
9658 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009659 return false;
9660 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009661 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009662 if (uiccProfile == null) {
9663 return false;
9664 }
9665 if (TelephonyManager.APPTYPE_SIM <= appType
9666 && appType <= TelephonyManager.APPTYPE_ISIM) {
9667 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9668 }
9669 return false;
9670 } finally {
9671 Binder.restoreCallingIdentity(identity);
9672 }
9673 }
9674
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009675 /**
chen xub4baa772019-04-03 10:23:41 -07009676 * Get whether making changes to modem configurations will trigger reboot.
9677 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009678 */
9679 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009680 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9681 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009683 mApp, subId, callingPackage, callingFeatureId,
9684 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009685 return false;
9686 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009687 final long identity = Binder.clearCallingIdentity();
9688 try {
9689 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9690 } finally {
9691 Binder.restoreCallingIdentity(identity);
9692 }
9693 }
9694
Nathan Harold29f5f052019-02-15 13:41:57 -08009695 private void updateModemStateMetrics() {
9696 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9697 // TODO: check the state for each modem if the api is ready.
9698 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9699 }
9700
Pengquan Meng3889a572019-01-23 11:16:29 -08009701 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009702 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009703 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009704 // Verify that the callingPackage belongs to the calling UID
9705 mApp.getSystemService(AppOpsManager.class)
9706 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009707 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009708 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009709 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009710 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9711 if (slotInfos != null) {
9712 for (int i = 0; i < slotInfos.length; i++) {
9713 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9714 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9715 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9716 portInfo.getLogicalSlotIndex()));
9717 }
9718 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009719 }
9720 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009721 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009722 } finally {
9723 Binder.restoreCallingIdentity(identity);
9724 }
9725 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009726
9727 /**
9728 * Get the IRadio HAL Version
9729 */
9730 @Override
9731 public int getRadioHalVersion() {
9732 Phone phone = getDefaultPhone();
9733 if (phone == null) return -1;
9734 HalVersion hv = phone.getHalVersion();
9735 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9736 return hv.major * 100 + hv.minor;
9737 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009738
9739 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009740 * Get the current calling package name.
9741 * @return the current calling package name
9742 */
9743 @Override
9744 public String getCurrentPackageName() {
9745 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9746 }
9747
9748 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009749 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9750 * corresponding network requests on a subId.
9751 *
9752 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009753 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009754 * 2) APN is un-metered for this subscription, or
9755 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009756 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009757 *
9758 * @return whether data is allowed for a apn type.
9759 *
9760 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009761 */
9762 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009763 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009764 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9765 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009766
9767 // Now that all security checks passes, perform the operation as ourselves.
9768 final long identity = Binder.clearCallingIdentity();
9769 try {
9770 Phone phone = getPhone(subId);
9771 if (phone == null) return false;
9772
Jack Yu27422a52022-03-21 10:38:05 -07009773 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009774 boolean isDataEnabled;
Jack Yuabb10902022-07-31 00:43:21 -07009775 isMetered = phone.getDataNetworkController().getDataConfigManager()
9776 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9777 phone.getServiceState().getDataRoaming());
9778 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009779 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009780 } finally {
9781 Binder.restoreCallingIdentity(identity);
9782 }
9783 }
9784
9785 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009786 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009787 enforceReadPrivilegedPermission("isApnMetered");
9788
9789 // Now that all security checks passes, perform the operation as ourselves.
9790 final long identity = Binder.clearCallingIdentity();
9791 try {
9792 Phone phone = getPhone(subId);
9793 if (phone == null) return true; // By default return true.
Jack Yuabb10902022-07-31 00:43:21 -07009794 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9795 DataUtils.apnTypeToNetworkCapability(apnType),
9796 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009797 } finally {
9798 Binder.restoreCallingIdentity(identity);
9799 }
9800 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009801
9802 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009803 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9804 int subscriptionId, IBooleanConsumer resultCallback) {
9805 enforceModifyPermission();
9806 long token = Binder.clearCallingIdentity();
9807 try {
9808 Phone phone = getPhone(subscriptionId);
9809 if (phone == null) {
9810 try {
9811 if (resultCallback != null) {
9812 resultCallback.accept(false);
9813 }
9814 } catch (RemoteException e) {
9815 // ignore
9816 }
9817 return;
9818 }
9819 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9820 Pair.create(specifiers, (x) -> {
9821 try {
9822 if (resultCallback != null) {
9823 resultCallback.accept(x);
9824 }
9825 } catch (RemoteException e) {
9826 // ignore
9827 }
9828 });
9829 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9830 } finally {
9831 Binder.restoreCallingIdentity(token);
9832 }
9833 }
9834
9835 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009836 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9837 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009838 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009839 mApp, subId, "getSystemSelectionChannels");
9840 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9841 final long identity = Binder.clearCallingIdentity();
9842 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009843 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9844 if (result instanceof IllegalStateException) {
9845 throw (IllegalStateException) result;
9846 }
9847 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009848 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9849 return specifiers;
9850 } finally {
9851 Binder.restoreCallingIdentity(identity);
9852 }
9853 }
9854
9855 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009856 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009857 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009858 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009859 }
9860
9861 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009862 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9863 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009864 if (callingPackage == null) {
9865 callingPackage = getCurrentPackageName();
9866 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009867 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9868 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009869 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9870 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009871 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9872 }
9873 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9874 Intent intent = new Intent();
9875 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9876 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9877 // Bring up choose default SMS subscription dialog right now
9878 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9879 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9880 mApp.startActivity(intent);
9881 }
chen xud5ca2d52019-05-28 15:20:57 -07009882
9883 @Override
9884 public String getMmsUAProfUrl(int subId) {
9885 //TODO investigate if this API should require proper permission check in R b/133791609
9886 final long identity = Binder.clearCallingIdentity();
9887 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009888 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9889 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9890 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9891 return carrierUAProfUrl;
9892 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009893 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9894 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009895 } finally {
9896 Binder.restoreCallingIdentity(identity);
9897 }
9898 }
9899
9900 @Override
9901 public String getMmsUserAgent(int subId) {
9902 //TODO investigate if this API should require proper permission check in R b/133791609
9903 final long identity = Binder.clearCallingIdentity();
9904 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009905 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9906 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9907 if (!TextUtils.isEmpty(carrierUserAgent)) {
9908 return carrierUserAgent;
9909 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009910 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9911 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009912 } finally {
9913 Binder.restoreCallingIdentity(identity);
9914 }
9915 }
Jack Yub07d4972019-05-28 16:12:25 -07009916
9917 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009918 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9919 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009920
Jack Yub07d4972019-05-28 16:12:25 -07009921 final long identity = Binder.clearCallingIdentity();
9922 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009923 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009924 if (phone == null) return false;
9925
Ling Ma58448e42022-09-16 15:22:36 -07009926 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -07009927 } finally {
9928 Binder.restoreCallingIdentity(identity);
9929 }
9930 }
9931
9932 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009933 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009934 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009935 enforceModifyPermission();
9936
changbettyd5c246e2019-12-24 15:40:37 +08009937 final long identity = Binder.clearCallingIdentity();
9938 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009939 Phone phone = getPhone(subscriptionId);
9940 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009941
Ling Ma58448e42022-09-16 15:22:36 -07009942 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +08009943 } finally {
9944 Binder.restoreCallingIdentity(identity);
9945 }
9946 }
9947
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009948 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009949 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009950 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9951 * otherwise.
9952 */
9953 @Override
9954 public void setCepEnabled(boolean isCepEnabled) {
9955 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9956
9957 final long identity = Binder.clearCallingIdentity();
9958 try {
9959 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9960 for (Phone phone : PhoneFactory.getPhones()) {
9961 Phone defaultPhone = phone.getImsPhone();
9962 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9963 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9964 ImsPhoneCallTracker imsPhoneCallTracker =
9965 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9966 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9967 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9968 + imsPhone.getMsisdn());
9969 }
9970 }
9971 } finally {
9972 Binder.restoreCallingIdentity(identity);
9973 }
9974 }
allenwtsu46dcc572020-01-08 18:24:03 +08009975
9976 /**
9977 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9978 *
9979 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9980 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9981 * before being read.
9982 */
9983 @Override
9984 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9985 isCompressed) {
9986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9987 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009988 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9989 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9990 }
9991 if (!isImsAvailableOnDevice()) {
9992 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9993 "IMS not available on device.");
9994 }
9995
9996 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009997 try {
Hui Wang761a6682020-10-31 05:12:53 +00009998 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9999 } finally {
10000 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010001 }
10002 }
zoey chene02881a2019-12-30 16:11:23 +080010003
10004 @Override
10005 public boolean isIccLockEnabled(int subId) {
10006 enforceReadPrivilegedPermission("isIccLockEnabled");
10007
10008 // Now that all security checks passes, perform the operation as ourselves.
10009 final long identity = Binder.clearCallingIdentity();
10010 try {
10011 Phone phone = getPhone(subId);
10012 if (phone != null && phone.getIccCard() != null) {
10013 return phone.getIccCard().getIccLockEnabled();
10014 } else {
10015 return false;
10016 }
10017 } finally {
10018 Binder.restoreCallingIdentity(identity);
10019 }
10020 }
10021
10022 /**
10023 * Set the ICC pin lock enabled or disabled.
10024 *
10025 * @return an integer representing the status of IccLock enabled or disabled in the following
10026 * three cases:
10027 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10028 * successfully.
10029 * - Positive number and zero for remaining password attempts.
10030 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10031 *
10032 */
10033 @Override
10034 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10035 enforceModifyPermission();
10036
10037 Phone phone = getPhone(subId);
10038 if (phone == null) {
10039 return 0;
10040 }
10041 // Now that all security checks passes, perform the operation as ourselves.
10042 final long identity = Binder.clearCallingIdentity();
10043 try {
10044 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10045 new Pair<Boolean, String>(enabled, password), phone, null);
10046 return attemptsRemaining;
10047
10048 } catch (Exception e) {
10049 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10050 } finally {
10051 Binder.restoreCallingIdentity(identity);
10052 }
10053 return 0;
10054 }
10055
10056 /**
10057 * Change the ICC password used in ICC pin lock.
10058 *
10059 * @return an integer representing the status of IccLock changed in the following three cases:
10060 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10061 * - Positive number and zero for remaining password attempts.
10062 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10063 *
10064 */
10065 @Override
10066 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10067 enforceModifyPermission();
10068
10069 Phone phone = getPhone(subId);
10070 if (phone == null) {
10071 return 0;
10072 }
10073 // Now that all security checks passes, perform the operation as ourselves.
10074 final long identity = Binder.clearCallingIdentity();
10075 try {
10076 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10077 new Pair<String, String>(oldPassword, newPassword), phone, null);
10078 return attemptsRemaining;
10079
10080 } catch (Exception e) {
10081 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10082 } finally {
10083 Binder.restoreCallingIdentity(identity);
10084 }
10085 return 0;
10086 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010087
10088 /**
10089 * Request for receiving user activity notification
10090 */
10091 @Override
10092 public void requestUserActivityNotification() {
10093 if (!mNotifyUserActivity.get()
10094 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10095 mNotifyUserActivity.set(true);
10096 }
10097 }
10098
10099 /**
10100 * Called when userActivity is signalled in the power manager.
10101 * This is safe to call from any thread, with any window manager locks held or not.
10102 */
10103 @Override
10104 public void userActivity() {
10105 // ***************************************
10106 // * Inherited from PhoneWindowManager *
10107 // ***************************************
10108 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10109 // WITH ITS LOCKS HELD.
10110 //
10111 // This code must be VERY careful about the locks
10112 // it acquires.
10113 // In fact, the current code acquires way too many,
10114 // and probably has lurking deadlocks.
10115
10116 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10117 throw new SecurityException("Only the OS may call notifyUserActivity()");
10118 }
10119
10120 if (mNotifyUserActivity.getAndSet(false)) {
10121 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10122 USER_ACTIVITY_NOTIFICATION_DELAY);
10123 }
10124 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010125
10126 @Override
10127 public boolean canConnectTo5GInDsdsMode() {
10128 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10129 }
Jack Yud10cdd42020-09-28 20:28:01 -070010130
10131 @Override
10132 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10133 String callingFeatureId) {
10134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10135 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10136 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10137 }
10138
10139 Phone phone = getPhone(subId);
10140 if (phone == null) {
10141 throw new RuntimeException("phone is not available");
10142 }
10143 // Now that all security checks passes, perform the operation as ourselves.
10144 final long identity = Binder.clearCallingIdentity();
10145 try {
10146 return phone.getEquivalentHomePlmns();
10147 } finally {
10148 Binder.restoreCallingIdentity(identity);
10149 }
10150 }
Daniel Bright59e67312020-11-13 11:49:37 -080010151
10152 @Override
10153 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010154 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10155 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010156 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010157 if (radioInterfaceCapabilities == null) {
10158 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010159 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010160 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010161 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010162
Hui Wang641e81c2020-10-12 12:14:23 -070010163 @Override
10164 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10165 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010166 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10167 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10168 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10169 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10170 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010171 if (DBG) {
10172 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10173 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10174 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10175 }
10176
10177 if (!SubscriptionManager.isValidSubscriptionId(subId)
10178 || appType < TelephonyManager.APPTYPE_UNKNOWN
10179 || appType > TelephonyManager.APPTYPE_ISIM
10180 || nafUrl == null || securityProtocol == null || callback == null) {
10181 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10182 if (callback != null) {
10183 try {
10184 callback.onAuthenticationFailure(
10185 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10186 } catch (RemoteException exception) {
10187 log("Fail to notify onAuthenticationFailure due to " + exception);
10188 }
10189 return;
10190 }
10191 }
10192
10193 final long token = Binder.clearCallingIdentity();
10194 try {
10195 getGbaManager(subId).bootstrapAuthenticationRequest(
10196 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10197 forceBootStrapping, callback));
10198 } finally {
10199 Binder.restoreCallingIdentity(token);
10200 }
10201 }
10202
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010203 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010204 * Attempts to set the radio power state for all phones for thermal reason.
10205 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010206 * requested radio power state will actually be set. See {@link
10207 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10208 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010209 * @param enable {@code true} if trying to turn radio on.
10210 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10211 * false}.
10212 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010213 private boolean setRadioPowerForThermal(boolean enable) {
10214 boolean isPhoneAvailable = false;
10215 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10216 Phone phone = PhoneFactory.getPhone(i);
10217 if (phone != null) {
10218 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10219 isPhoneAvailable = true;
10220 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010221 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010222
10223 // return true if successfully informed the phone object about the thermal radio power
10224 // request.
10225 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010226 }
10227
10228 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010229 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010230 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10231 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10232 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10233 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10234 throw new IllegalArgumentException("modem does not support data throttling");
10235 }
10236
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010237 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10238 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010239 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010240 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10241 }
10242
Sarah Chinecc78c42022-03-31 21:16:48 -070010243 setDataEnabledForReason(
10244 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010245
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010246 if (isDataThrottlingSupported) {
10247 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010248 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010249 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10250 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10251 } else if (thermalMitigationResult
10252 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010253 log("Modem likely does not support data throttling on secondary carrier. Data " +
10254 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10255 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010256 }
10257 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010258 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010259
10260 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010261 }
10262
Jack Nudelman644b91a2021-03-12 14:09:48 -080010263 private static List<String> getThermalMitigationAllowlist(Context context) {
10264 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10265 for (String pckg : context.getResources()
10266 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10267 sThermalMitigationAllowlistedPackages.add(pckg);
10268 }
10269 }
10270
10271 return sThermalMitigationAllowlistedPackages;
10272 }
10273
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010274 private boolean isAnyPhoneInEmergencyState() {
10275 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10276 if (tm.isInEmergencyCall()) {
10277 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10278 return true;
10279 }
10280 for (Phone phone : PhoneFactory.getPhones()) {
10281 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10282 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10283 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10284 + phone.isInEcm());
10285 return true;
10286 }
10287 }
10288
10289 return false;
10290 }
10291
Jack Nudelman644b91a2021-03-12 14:09:48 -080010292 /**
10293 * Used by shell commands to add an authorized package name for thermal mitigation.
10294 * @param packageName name of package to be allowlisted
10295 * @param context
10296 */
10297 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10298 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10299 sThermalMitigationAllowlistedPackages.add(packageName);
10300 }
10301
10302 /**
10303 * Used by shell commands to remove an authorized package name for thermal mitigation.
10304 * @param packageName name of package to remove from allowlist
10305 * @param context
10306 */
10307 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10308 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10309 sThermalMitigationAllowlistedPackages.remove(packageName);
10310 }
10311
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010312 /**
10313 * Thermal mitigation request to control functionalities at modem.
10314 *
10315 * @param subId the id of the subscription.
10316 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010317 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010318 *
10319 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10320 */
10321 @Override
10322 @ThermalMitigationResult
10323 public int sendThermalMitigationRequest(
10324 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010325 ThermalMitigationRequest thermalMitigationRequest,
10326 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010327 enforceModifyPermission();
10328
Jack Nudelman644b91a2021-03-12 14:09:48 -080010329 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10330 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10331 .contains(callingPackage)) {
10332 throw new SecurityException("Calling package must be configured in the device config. "
10333 + "calling package: " + callingPackage);
10334 }
10335
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010336 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10337 final long identity = Binder.clearCallingIdentity();
10338
10339 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10340 try {
10341 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10342 switch (thermalMitigationAction) {
10343 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10344 thermalMitigationResult =
10345 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010346 thermalMitigationRequest.getDataThrottlingRequest(),
10347 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010348 break;
10349 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10350 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10351 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10352 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10353 }
10354
10355 // Ensure that radio is on. If not able to power on due to phone being
10356 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010357 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010358 thermalMitigationResult =
10359 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10360 break;
10361 }
10362
10363 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010364 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010365 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10366 break;
10367 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10368 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10369 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10370 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10371 }
10372
10373 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10374 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010375 Phone phone = getPhone(subId);
10376 if (phone == null) {
10377 thermalMitigationResult =
10378 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10379 break;
10380 }
10381
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010382 TelephonyConnectionService service =
10383 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010384 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010385 Log.e(LOG_TAG, "An emergency call is pending");
10386 thermalMitigationResult =
10387 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10388 break;
10389 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010390 thermalMitigationResult =
10391 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10392 break;
10393 }
10394 } else {
10395 thermalMitigationResult =
10396 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10397 break;
10398 }
10399
10400 // Turn radio off. If not able to power off due to phone being unavailable,
10401 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010402 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010403 thermalMitigationResult =
10404 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10405 break;
10406 }
10407 thermalMitigationResult =
10408 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10409 break;
10410 default:
10411 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10412 + "not exist. Requested action: " + thermalMitigationAction);
10413 }
10414 } catch (IllegalArgumentException e) {
10415 throw e;
10416 } catch (Exception e) {
10417 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10418 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10419 } finally {
10420 Binder.restoreCallingIdentity(identity);
10421 }
10422
10423 if (DBG) {
10424 log("thermalMitigationRequest returning with thermalMitigationResult: "
10425 + thermalMitigationResult);
10426 }
10427
10428 return thermalMitigationResult;
10429 }
Hui Wang641e81c2020-10-12 12:14:23 -070010430
10431 /**
10432 * Set the GbaService Package Name that Telephony will bind to.
10433 *
10434 * @param subId The sim that the GbaService is associated with.
10435 * @param packageName The name of the package to be replaced with.
10436 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10437 */
10438 @Override
10439 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10440 enforceModifyPermission();
10441
10442 final long identity = Binder.clearCallingIdentity();
10443 try {
10444 return getGbaManager(subId).overrideServicePackage(packageName);
10445 } finally {
10446 Binder.restoreCallingIdentity(identity);
10447 }
10448 }
10449
10450 /**
10451 * Return the package name of the currently bound GbaService.
10452 *
10453 * @param subId The sim that the GbaService is associated with.
10454 * @return the package name of the GbaService configuration, null if GBA is not supported.
10455 */
10456 @Override
10457 public String getBoundGbaService(int subId) {
10458 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10459
10460 final long identity = Binder.clearCallingIdentity();
10461 try {
10462 return getGbaManager(subId).getServicePackage();
10463 } finally {
10464 Binder.restoreCallingIdentity(identity);
10465 }
10466 }
10467
10468 /**
10469 * Set the release time for telephony to unbind GbaService.
10470 *
10471 * @param subId The sim that the GbaService is associated with.
10472 * @param interval The release time to unbind GbaService by millisecond.
10473 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10474 */
10475 @Override
10476 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10477 enforceModifyPermission();
10478
10479 final long identity = Binder.clearCallingIdentity();
10480 try {
10481 return getGbaManager(subId).overrideReleaseTime(interval);
10482 } finally {
10483 Binder.restoreCallingIdentity(identity);
10484 }
10485 }
10486
10487 /**
10488 * Return the release time for telephony to unbind GbaService.
10489 *
10490 * @param subId The sim that the GbaService is associated with.
10491 * @return The release time to unbind GbaService by millisecond.
10492 */
10493 @Override
10494 public int getGbaReleaseTime(int subId) {
10495 enforceReadPrivilegedPermission("getGbaReleaseTime");
10496
10497 final long identity = Binder.clearCallingIdentity();
10498 try {
10499 return getGbaManager(subId).getReleaseTime();
10500 } finally {
10501 Binder.restoreCallingIdentity(identity);
10502 }
10503 }
10504
10505 private GbaManager getGbaManager(int subId) {
10506 GbaManager instance = GbaManager.getInstance(subId);
10507 if (instance == null) {
10508 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10509 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10510 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10511 }
10512 return instance;
10513 }
Hui Wang761a6682020-10-31 05:12:53 +000010514
10515 /**
10516 * indicate whether the device and the carrier can support
10517 * RCS VoLTE single registration.
10518 */
10519 @Override
10520 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010521 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10522 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10523 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10524 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010525
10526 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10527 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10528 }
10529
10530 final long identity = Binder.clearCallingIdentity();
10531 try {
10532 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10533 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010534 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10535 if (isCapable != null) {
10536 return isCapable;
10537 }
Hui Wang761a6682020-10-31 05:12:53 +000010538 }
Hui Wang67af90e2021-06-04 16:57:15 -070010539 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10540 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010541 } finally {
10542 Binder.restoreCallingIdentity(identity);
10543 }
10544 }
10545
10546 /**
10547 * Register RCS provisioning callback.
10548 */
10549 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010550 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010551 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010552 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010553 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010554 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10555 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010556
10557 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10558 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10559 }
10560 if (!isImsAvailableOnDevice()) {
10561 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10562 "IMS not available on device.");
10563 }
10564
10565 final long identity = Binder.clearCallingIdentity();
10566 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010567 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010568 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010569 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10570 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010571 }
Hui Wang761a6682020-10-31 05:12:53 +000010572 } finally {
10573 Binder.restoreCallingIdentity(identity);
10574 }
10575 }
10576
10577 /**
10578 * Unregister RCS provisioning callback.
10579 */
10580 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010581 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010582 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010583 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010584 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010585 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10586 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010587
10588 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10589 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10590 }
10591 if (!isImsAvailableOnDevice()) {
10592 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10593 "IMS not available on device.");
10594 }
10595
10596 final long identity = Binder.clearCallingIdentity();
10597 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010598 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010599 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010600 } finally {
10601 Binder.restoreCallingIdentity(identity);
10602 }
10603 }
10604
10605 /**
10606 * trigger RCS reconfiguration.
10607 */
10608 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010609 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10610 "triggerRcsReconfiguration",
10611 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010612
10613 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10614 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10615 }
10616 if (!isImsAvailableOnDevice()) {
10617 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10618 "IMS not available on device.");
10619 }
10620
10621 final long identity = Binder.clearCallingIdentity();
10622 try {
10623 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10624 } finally {
10625 Binder.restoreCallingIdentity(identity);
10626 }
10627 }
10628
10629 /**
10630 * Provide the client configuration parameters of the RCS application.
10631 */
10632 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010633 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10634 "setRcsClientConfiguration",
10635 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010636
10637 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10638 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10639 }
10640 if (!isImsAvailableOnDevice()) {
10641 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10642 "IMS not available on device.");
10643 }
10644
10645 final long identity = Binder.clearCallingIdentity();
10646
10647 try {
10648 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10649 if (configBinder == null) {
10650 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010651 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10652 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010653 } else {
10654 configBinder.setRcsClientConfiguration(rcc);
10655 }
joonhunshin3e154242021-09-17 06:33:39 +000010656
10657 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10658 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010659 } catch (RemoteException e) {
10660 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010661 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10662 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010663 } finally {
10664 Binder.restoreCallingIdentity(identity);
10665 }
10666 }
10667
10668 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010669 * Enables or disables the test mode for RCS VoLTE single registration.
10670 */
10671 @Override
10672 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10673 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10674 "setRcsSingleRegistrationTestModeEnabled");
10675
10676 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10677 }
10678
10679 /**
10680 * Gets the test mode for RCS VoLTE single registration.
10681 */
10682 @Override
10683 public boolean getRcsSingleRegistrationTestModeEnabled() {
10684 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10685 "getRcsSingleRegistrationTestModeEnabled");
10686
10687 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10688 }
10689
10690 /**
Hui Wang761a6682020-10-31 05:12:53 +000010691 * Overrides the config of RCS VoLTE single registration enabled for the device.
10692 */
10693 @Override
10694 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10695 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10696 "setDeviceSingleRegistrationEnabledOverride");
10697 enforceModifyPermission();
10698
10699 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10700 : Boolean.parseBoolean(enabledStr);
10701 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010702 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010703 }
10704
10705 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010706 * Sends a device to device communication message. Only usable via shell.
10707 * @param message message to send.
10708 * @param value message value.
10709 */
10710 @Override
10711 public void sendDeviceToDeviceMessage(int message, int value) {
10712 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010713 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010714 enforceModifyPermission();
10715
10716 final long identity = Binder.clearCallingIdentity();
10717 try {
10718 TelephonyConnectionService service =
10719 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10720 if (service == null) {
10721 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10722 return;
10723 }
10724 service.sendTestDeviceToDeviceMessage(message, value);
10725 } finally {
10726 Binder.restoreCallingIdentity(identity);
10727 }
10728 }
10729
Tyler Gunnbabbda02021-02-10 11:05:02 -080010730 /**
10731 * Sets the specified device to device transport active.
10732 * @param transport The transport to set active.
10733 */
10734 @Override
10735 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10736 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10737 "setActiveDeviceToDeviceTransport");
10738 enforceModifyPermission();
10739
10740 final long identity = Binder.clearCallingIdentity();
10741 try {
10742 TelephonyConnectionService service =
10743 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10744 if (service == null) {
10745 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10746 return;
10747 }
10748 service.setActiveDeviceToDeviceTransport(transport);
10749 } finally {
10750 Binder.restoreCallingIdentity(identity);
10751 }
10752 }
Tyler Gunn92479152021-01-20 16:30:10 -080010753
Tyler Gunnd4339262021-05-03 14:46:49 -070010754 @Override
10755 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10756 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10757 "setDeviceToDeviceForceEnabled");
10758
10759 final long identity = Binder.clearCallingIdentity();
10760 try {
10761 Arrays.stream(PhoneFactory.getPhones()).forEach(
10762 p -> {
10763 Phone thePhone = p.getImsPhone();
10764 if (thePhone != null && thePhone instanceof ImsPhone) {
10765 ImsPhone imsPhone = (ImsPhone) thePhone;
10766 CallTracker tracker = imsPhone.getCallTracker();
10767 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10768 ImsPhoneCallTracker imsPhoneCallTracker =
10769 (ImsPhoneCallTracker) tracker;
10770 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10771 }
10772 }
10773 }
10774 );
10775 } finally {
10776 Binder.restoreCallingIdentity(identity);
10777 }
10778 }
10779
Tyler Gunn92479152021-01-20 16:30:10 -080010780 /**
Hui Wang761a6682020-10-31 05:12:53 +000010781 * Gets the config of RCS VoLTE single registration enabled for the device.
10782 */
10783 @Override
10784 public boolean getDeviceSingleRegistrationEnabled() {
10785 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10786 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10787 }
10788
10789 /**
10790 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10791 */
10792 @Override
10793 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10794 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10795 "setCarrierSingleRegistrationEnabledOverride");
10796 enforceModifyPermission();
10797
10798 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10799 : Boolean.parseBoolean(enabledStr);
10800 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10801 subId, enabled);
10802 }
10803
10804 /**
10805 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10806 */
10807 @Override
10808 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10809 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10810 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10811 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010812
10813 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010814 * Overrides the ims feature validation result
10815 */
10816 @Override
10817 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10818 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10819 "setImsFeatureValidationOverride");
10820
10821 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10822 : Boolean.parseBoolean(enabledStr);
10823 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10824 subId, enabled);
10825 }
10826
10827 /**
10828 * Gets the ims feature validation override value
10829 */
10830 @Override
10831 public boolean getImsFeatureValidationOverride(int subId) {
10832 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10833 "getImsFeatureValidationOverride");
10834 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10835 }
10836
10837 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010838 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10839 * their mobile plan.
10840 */
10841 @Override
10842 public String getMobileProvisioningUrl() {
10843 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10844 final long identity = Binder.clearCallingIdentity();
10845 try {
10846 return getDefaultPhone().getMobileProvisioningUrl();
10847 } finally {
10848 Binder.restoreCallingIdentity(identity);
10849 }
10850 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010851
James.cf Linbcdf8b32021-01-14 16:44:13 +080010852 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010853 * Get the EAB contact from the EAB database.
10854 */
10855 @Override
10856 public String getContactFromEab(String contact) {
10857 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10858 enforceModifyPermission();
10859 final long identity = Binder.clearCallingIdentity();
10860 try {
10861 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10862 } finally {
10863 Binder.restoreCallingIdentity(identity);
10864 }
10865 }
10866
10867 /**
Calvin Pana1434322021-07-01 19:27:01 +080010868 * Get the EAB capability from the EAB database.
10869 */
10870 @Override
10871 public String getCapabilityFromEab(String contact) {
10872 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10873 enforceModifyPermission();
10874 final long identity = Binder.clearCallingIdentity();
10875 try {
10876 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10877 } finally {
10878 Binder.restoreCallingIdentity(identity);
10879 }
10880 }
10881
10882 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010883 * Remove the EAB contacts from the EAB database.
10884 */
10885 @Override
10886 public int removeContactFromEab(int subId, String contacts) {
10887 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10888 enforceModifyPermission();
10889 final long identity = Binder.clearCallingIdentity();
10890 try {
10891 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10892 } finally {
10893 Binder.restoreCallingIdentity(identity);
10894 }
10895 }
10896
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010897 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010898 public boolean getDeviceUceEnabled() {
10899 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10900 final long identity = Binder.clearCallingIdentity();
10901 try {
10902 return mApp.getDeviceUceEnabled();
10903 } finally {
10904 Binder.restoreCallingIdentity(identity);
10905 }
10906 }
10907
10908 @Override
10909 public void setDeviceUceEnabled(boolean isEnabled) {
10910 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10911 final long identity = Binder.clearCallingIdentity();
10912 try {
10913 mApp.setDeviceUceEnabled(isEnabled);
10914 } finally {
10915 Binder.restoreCallingIdentity(identity);
10916 }
10917 }
10918
Brad Ebinger14d467f2021-02-12 06:18:28 +000010919 /**
10920 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10921 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10922 */
10923 // Used for SHELL command only right now.
10924 @Override
10925 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10926 List<String> featureTags) {
10927 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10928 "addUceRegistrationOverrideShell");
10929 final long identity = Binder.clearCallingIdentity();
10930 try {
10931 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10932 new ArraySet<>(featureTags));
10933 } catch (ImsException e) {
10934 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10935 } finally {
10936 Binder.restoreCallingIdentity(identity);
10937 }
10938 }
10939
10940 /**
10941 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10942 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10943 */
10944 // Used for SHELL command only right now.
10945 @Override
10946 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10947 List<String> featureTags) {
10948 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10949 "removeUceRegistrationOverrideShell");
10950 final long identity = Binder.clearCallingIdentity();
10951 try {
10952 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10953 new ArraySet<>(featureTags));
10954 } catch (ImsException e) {
10955 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10956 } finally {
10957 Binder.restoreCallingIdentity(identity);
10958 }
10959 }
10960
10961 /**
10962 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10963 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10964 */
10965 // Used for SHELL command only right now.
10966 @Override
10967 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10968 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10969 "clearUceRegistrationOverrideShell");
10970 final long identity = Binder.clearCallingIdentity();
10971 try {
10972 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10973 } catch (ImsException e) {
10974 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10975 } finally {
10976 Binder.restoreCallingIdentity(identity);
10977 }
10978 }
10979
10980 /**
10981 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10982 */
10983 // Used for SHELL command only right now.
10984 @Override
10985 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10986 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10987 "getLatestRcsContactUceCapabilityShell");
10988 final long identity = Binder.clearCallingIdentity();
10989 try {
10990 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10991 } catch (ImsException e) {
10992 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10993 } finally {
10994 Binder.restoreCallingIdentity(identity);
10995 }
10996 }
10997
10998 /**
10999 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11000 * device does not have an active PUBLISH.
11001 */
11002 // Used for SHELL command only right now.
11003 @Override
11004 public String getLastUcePidfXmlShell(int subId) {
11005 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11006 final long identity = Binder.clearCallingIdentity();
11007 try {
11008 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11009 } catch (ImsException e) {
11010 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11011 } finally {
11012 Binder.restoreCallingIdentity(identity);
11013 }
11014 }
11015
James.cf Line8713a42021-04-29 16:04:26 +080011016 /**
11017 * Remove UCE requests cannot be sent to the network status.
11018 */
11019 // Used for SHELL command only right now.
11020 @Override
11021 public boolean removeUceRequestDisallowedStatus(int subId) {
11022 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11023 final long identity = Binder.clearCallingIdentity();
11024 try {
11025 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11026 } catch (ImsException e) {
11027 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11028 } finally {
11029 Binder.restoreCallingIdentity(identity);
11030 }
11031 }
11032
James.cf Lin18bb9002021-05-25 01:37:38 +080011033 /**
11034 * Remove UCE requests cannot be sent to the network status.
11035 */
11036 // Used for SHELL command only.
11037 @Override
11038 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11039 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11040 final long identity = Binder.clearCallingIdentity();
11041 try {
11042 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11043 } catch (ImsException e) {
11044 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11045 } finally {
11046 Binder.restoreCallingIdentity(identity);
11047 }
11048 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011049
James.cf Lin4b784aa2021-01-31 03:25:15 +080011050 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011051 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11052 String callingPackage) {
11053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11054 mApp, subId, "setSignalStrengthUpdateRequest");
11055
11056 final int callingUid = Binder.getCallingUid();
11057 // Verify that tha callingPackage belongs to the calling UID
11058 mApp.getSystemService(AppOpsManager.class)
11059 .checkPackage(callingUid, callingPackage);
11060
Rambo Wang3607f502021-02-01 21:51:40 -080011061 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011062
11063 final long identity = Binder.clearCallingIdentity();
11064 try {
11065 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11066 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11067
11068 if (result instanceof IllegalStateException) {
11069 throw (IllegalStateException) result;
11070 }
11071 } finally {
11072 Binder.restoreCallingIdentity(identity);
11073 }
11074 }
11075
11076 @Override
11077 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11078 String callingPackage) {
11079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11080 mApp, subId, "clearSignalStrengthUpdateRequest");
11081
11082 final int callingUid = Binder.getCallingUid();
11083 // Verify that tha callingPackage belongs to the calling UID
11084 mApp.getSystemService(AppOpsManager.class)
11085 .checkPackage(callingUid, callingPackage);
11086
11087 final long identity = Binder.clearCallingIdentity();
11088 try {
11089 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11090 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11091
11092 if (result instanceof IllegalStateException) {
11093 throw (IllegalStateException) result;
11094 }
11095 } finally {
11096 Binder.restoreCallingIdentity(identity);
11097 }
11098 }
11099
Rambo Wang3607f502021-02-01 21:51:40 -080011100 private static void validateSignalStrengthUpdateRequest(Context context,
11101 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011102 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11103 // phone/system process do not have further restriction on request
11104 return;
11105 }
11106
11107 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011108 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011109 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011110 context.enforceCallingOrSelfPermission(
11111 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11112 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011113 }
11114
11115 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11116 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11117 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11118 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11119 || info.isEnabled()) {
11120 throw new IllegalArgumentException(
11121 "Only system can set hide fields in SignalThresholdInfo");
11122 }
11123
11124 // Thresholds length for each RAN need in range. This has been validated in
11125 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11126 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11127 final int[] thresholds = info.getThresholds();
11128 Objects.requireNonNull(thresholds);
11129 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11130 || thresholds.length
11131 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11132 throw new IllegalArgumentException(
11133 "thresholds length is out of range: " + thresholds.length);
11134 }
11135 }
11136 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011137
11138 /**
11139 * Gets the current phone capability.
11140 *
11141 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11142 * @return the PhoneCapability which describes the data connection capability of modem.
11143 * It's used to evaluate possible phone config change, for example from single
11144 * SIM device to multi-SIM device.
11145 */
11146 @Override
11147 public PhoneCapability getPhoneCapability() {
11148 enforceReadPrivilegedPermission("getPhoneCapability");
11149 final long identity = Binder.clearCallingIdentity();
11150 try {
11151 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11152 } finally {
11153 Binder.restoreCallingIdentity(identity);
11154 }
11155 }
Michele Berionne5e411512020-11-13 02:36:59 +000011156
11157 /**
11158 * Prepare TelephonyManager for an unattended reboot. The reboot is
11159 * required to be done shortly after the API is invoked.
11160 */
11161 @Override
11162 @TelephonyManager.PrepareUnattendedRebootResult
11163 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011164 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011165 enforceRebootPermission();
11166
11167 final long identity = Binder.clearCallingIdentity();
11168 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011169 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011170 } finally {
11171 Binder.restoreCallingIdentity(identity);
11172 }
11173 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011174
11175 /**
11176 * Request to get the current slicing configuration including URSP rules and
11177 * NSSAIs (configured, allowed and rejected).
11178 *
11179 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11180 */
11181 @Override
11182 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011183 TelephonyPermissions
11184 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11185 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011186
11187 final long identity = Binder.clearCallingIdentity();
11188 try {
11189 Phone phone = getDefaultPhone();
11190 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11191 } finally {
11192 Binder.restoreCallingIdentity(identity);
11193 }
11194 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011195
11196 /**
11197 * Register an IMS connection state callback
11198 */
11199 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011200 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11201 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011202 if (feature == ImsFeature.FEATURE_MMTEL) {
11203 // ImsMmTelManager
11204 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11205 TelephonyPermissions
11206 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11207 mApp, subId, "registerImsStateCallback");
11208 } else if (feature == ImsFeature.FEATURE_RCS) {
11209 // ImsRcsManager or SipDelegateManager
11210 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11211 Binder.getCallingUid(), "registerImsStateCallback",
11212 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11213 Manifest.permission.READ_PRECISE_PHONE_STATE,
11214 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11215 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11216 }
11217
11218 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11219 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11220 "IMS not available on device.");
11221 }
11222
11223 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11224 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11225 }
11226
11227 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11228 if (controller == null) {
11229 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11230 "IMS not available on device.");
11231 }
11232
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011233 if (callingPackage == null) {
11234 callingPackage = getCurrentPackageName();
11235 }
11236
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011237 final long token = Binder.clearCallingIdentity();
11238 try {
11239 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011240 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011241 } catch (ImsException e) {
11242 throw new ServiceSpecificException(e.getCode());
11243 } finally {
11244 Binder.restoreCallingIdentity(token);
11245 }
11246 }
11247
11248 /**
11249 * Unregister an IMS connection state callback
11250 */
11251 @Override
11252 public void unregisterImsStateCallback(IImsStateCallback cb) {
11253 final long token = Binder.clearCallingIdentity();
11254 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11255 if (controller == null) {
11256 return;
11257 }
11258 try {
11259 controller.unregisterImsStateCallback(cb);
11260 } finally {
11261 Binder.restoreCallingIdentity(token);
11262 }
11263 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011264
11265 /**
11266 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11267 *
11268 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11269 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11270 * SecurityException.
11271 * If there is current registered network this value will be same as the registered cell
11272 * identity. If the device goes out of service the previous cell identity is cached and
11273 * will be returned. If the cache age of the Cell identity is more than 24 hours
11274 * it will be cleared and null will be returned.
11275 *
11276 */
11277 @Override
11278 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11279 String callingFeatureId) {
11280 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11281 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11282 LocationAccessPolicy.checkLocationPermission(mApp,
11283 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11284 .setCallingPackage(callingPackage)
11285 .setCallingFeatureId(callingFeatureId)
11286 .setCallingPid(Binder.getCallingPid())
11287 .setCallingUid(Binder.getCallingUid())
11288 .setMethod("getLastKnownCellIdentity")
11289 .setLogAsInfo(true)
11290 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11291 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11292 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11293 .build());
11294
11295 boolean hasFinePermission =
11296 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11297 if (!hasFinePermission
11298 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11299 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011300 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011301 }
11302
11303 final long identity = Binder.clearCallingIdentity();
11304 try {
11305 Phone phone = getPhone(subId);
11306 if (phone == null) return null;
11307 ServiceStateTracker sst = phone.getServiceStateTracker();
11308 if (sst == null) return null;
11309 return sst.getLastKnownCellIdentity();
11310 } finally {
11311 Binder.restoreCallingIdentity(identity);
11312 }
11313 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011314
jimsun3b9ccac2021-10-26 15:01:23 +080011315 /**
11316 * Sets the modem service class Name that Telephony will bind to.
11317 *
11318 * @param serviceName The class name of the modem service.
11319 * @return true if the operation is succeed, otherwise false.
11320 */
11321 public boolean setModemService(String serviceName) {
11322 Log.d(LOG_TAG, "setModemService - " + serviceName);
11323 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11325 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11326 "setModemService");
11327 return mPhoneConfigurationManager.setModemService(serviceName);
11328 }
11329
11330 /**
11331 * Return the class name of the currently bounded modem service.
11332 *
11333 * @return the class name of the modem service.
11334 */
11335 public String getModemService() {
11336 String result;
11337 Log.d(LOG_TAG, "getModemService");
11338 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11339 TelephonyPermissions
11340 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11341 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11342 "getModemService");
11343 result = mPhoneConfigurationManager.getModemService();
11344 Log.d(LOG_TAG, "result = " + result);
11345 return result;
11346 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011347
11348 @Override
11349 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11350 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11351 mApp.enforceCallingOrSelfPermission(
11352 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11353 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11354
11355 final long identity = Binder.clearCallingIdentity();
11356 try {
11357 Phone phone = getPhone(subId);
11358 if (phone == null) return;
11359 phone.setVoiceServiceStateOverride(hasService);
11360 } finally {
11361 Binder.restoreCallingIdentity(identity);
11362 }
11363 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011364
11365 /**
11366 * set removable eSIM as default eUICC.
11367 *
11368 * @hide
11369 */
11370 @Override
11371 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11372 enforceModifyPermission();
11373 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11374
11375 final long identity = Binder.clearCallingIdentity();
11376 try {
11377 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11378 } finally {
11379 Binder.restoreCallingIdentity(identity);
11380 }
11381 }
11382
11383 /**
11384 * Returns whether the removable eSIM is default eUICC or not.
11385 *
11386 * @hide
11387 */
11388 @Override
11389 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11390 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11391 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11392
11393 final long identity = Binder.clearCallingIdentity();
11394 try {
11395 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11396 } finally {
11397 Binder.restoreCallingIdentity(identity);
11398 }
11399 }
11400
Ryan Savitskicab25c52023-03-14 14:23:49 +000011401 /**
11402 * Get the SIM state for the slot index.
11403 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11404 *
11405 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11406 */
11407 @Override
11408 @SimState
11409 public int getSimStateForSlotIndex(int slotIndex) {
11410 IccCardConstants.State simState;
11411 if (slotIndex < 0) {
11412 simState = IccCardConstants.State.UNKNOWN;
11413 } else {
11414 Phone phone = null;
11415 try {
11416 phone = PhoneFactory.getPhone(slotIndex);
11417 } catch (IllegalStateException e) {
11418 // ignore
11419 }
11420 if (phone == null) {
11421 simState = IccCardConstants.State.UNKNOWN;
11422 } else {
11423 IccCard icc = phone.getIccCard();
11424 if (icc == null) {
11425 simState = IccCardConstants.State.UNKNOWN;
11426 } else {
11427 simState = icc.getState();
11428 }
11429 }
11430 }
11431 return simState.ordinal();
11432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011433}