blob: ba0fbdba8dda7bafb1c34845c04985b2113c055a [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070034import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000035import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080036import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080053import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.Looper;
55import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080057import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070058import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070059import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080060import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080061import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070062import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070063import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080064import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070066import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070067import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070068import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070069import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080070import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070071import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090072import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080073import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080074import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070075import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080076import android.telephony.AccessNetworkConstants;
77import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070078import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070079import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080080import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070081import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080082import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070083import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080084import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070085import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080086import android.telephony.CellIdentityCdma;
87import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070089import android.telephony.CellInfoGsm;
90import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070091import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080092import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070093import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070094import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070095import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080096import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070097import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080098import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070099import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800100import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800101import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700102import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800103import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800105import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800106import android.telephony.SignalStrengthUpdateRequest;
107import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800108import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800109import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800110import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700111import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700112import android.telephony.TelephonyManager;
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;
Rambo Wanga1782702021-11-10 20:15:19 -0800169import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700170import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700171import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700172import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700174import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800175import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700176import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700177import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700178import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700179import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800180import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800181import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700182import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000183import com.android.internal.telephony.SmsApplication;
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;
Meng Wangafbc5852019-09-19 17:37:13 -0700197import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700198import com.android.internal.telephony.uicc.IccIoResult;
199import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800200import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700201import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800202import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000204import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800205import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000206import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800207import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000208import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700209import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700210import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800211import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800212import com.android.phone.callcomposer.CallComposerPictureManager;
213import com.android.phone.callcomposer.CallComposerPictureTransfer;
214import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700215import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700216import com.android.phone.slice.SlicePurchaseController;
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;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700242import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800243import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800244import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800245import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246
247/**
248 * Implementation of the ITelephony interface.
249 */
Santos Cordon117fee72014-05-16 17:56:12 -0700250public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251 private static final String LOG_TAG = "PhoneInterfaceManager";
252 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
253 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800254 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700255
256 // Message codes used with mMainThreadHandler
257 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700258 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
259 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700260 private static final int CMD_OPEN_CHANNEL = 9;
261 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
262 private static final int CMD_CLOSE_CHANNEL = 11;
263 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800264 private static final int CMD_NV_READ_ITEM = 13;
265 private static final int EVENT_NV_READ_ITEM_DONE = 14;
266 private static final int CMD_NV_WRITE_ITEM = 15;
267 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
268 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
269 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700270 private static final int CMD_RESET_MODEM_CONFIG = 19;
271 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800272 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
273 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800274 private static final int CMD_SEND_ENVELOPE = 25;
275 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000276 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
277 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700278 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
279 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
280 private static final int CMD_EXCHANGE_SIM_IO = 31;
281 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800282 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
283 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700284 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
285 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700286 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
287 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700288 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
289 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
290 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
291 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700292 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
293 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
294 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
295 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700296 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800297 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
298 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000299 private static final int CMD_SWITCH_SLOTS = 50;
300 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700301 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
302 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
303 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
304 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
305 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
306 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
307 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
308 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700309 private static final int CMD_GET_ALL_CELL_INFO = 60;
310 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
311 private static final int CMD_GET_CELL_LOCATION = 62;
312 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700313 private static final int CMD_MODEM_REBOOT = 64;
314 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700315 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
316 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800317 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
318 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700319 private static final int CMD_GET_MODEM_STATUS = 70;
320 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700321 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
322 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700323 private static final int CMD_ERASE_MODEM_CONFIG = 74;
324 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800325 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
326 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
327 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
328 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800329 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
330 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800331 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800332 private static final int CMD_GET_CALL_FORWARDING = 83;
333 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
334 private static final int CMD_SET_CALL_FORWARDING = 85;
335 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
336 private static final int CMD_GET_CALL_WAITING = 87;
337 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
338 private static final int CMD_SET_CALL_WAITING = 89;
339 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700340 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
341 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
342 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
343 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700344 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
345 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800346 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
347 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800348 private static final int CMD_SET_DATA_THROTTLING = 99;
349 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800350 private static final int CMD_SET_SIM_POWER = 101;
351 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800352 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
353 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
354 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
355 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800356 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
357 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000358 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800359 private static final int CMD_GET_SLICING_CONFIG = 110;
360 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800361 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700362 private static final int CMD_ENABLE_VONR = 113;
363 private static final int EVENT_ENABLE_VONR_DONE = 114;
364 private static final int CMD_IS_VONR_ENABLED = 115;
365 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700366 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
367 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800369 // Parameters of select command.
370 private static final int SELECT_COMMAND = 0xA4;
371 private static final int SELECT_P1 = 0x04;
372 private static final int SELECT_P2 = 0;
373 private static final int SELECT_P3 = 0x10;
374
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375 /** The singleton instance. */
376 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800377 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378
Wink Saville3ab207e2014-11-20 13:07:20 -0800379 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800380 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800381 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700382 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800383 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700384 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800385 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800386 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800387 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700388 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800389 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000390 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391
Peter Wangdafb9ac2020-01-15 14:13:38 -0800392 /** User Activity */
393 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800394 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
395
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700396 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
397
Derek Tan97ebb422014-09-05 16:55:38 -0700398 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
399 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800400 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800401 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700402
Michelecea4cf22018-12-21 15:00:11 -0800403 // String to store multi SIM allowed
404 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
405
Derek Tan740e1672017-06-27 14:56:27 -0700406 // The AID of ISD-R.
407 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
408
yinxub1bed742017-04-17 11:45:04 -0700409 private NetworkScanRequestTracker mNetworkScanRequestTracker;
410
David Kelly5e06a7f2018-03-12 14:10:59 +0000411 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
412 private static final int MANUFACTURER_CODE_LENGTH = 8;
413
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800414 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800415 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800416
Sarah Chin2ec39f62022-08-31 17:03:26 -0700417 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
418 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
419
Derek Tan89e89d42014-07-08 17:00:10 -0700420 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700421 * Experiment flag to enable erase modem config on reset network, default value is false
422 */
423 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
424 "reset_network_erase_modem_config_enabled";
425
Rambo Wang0f050d82021-02-12 11:43:36 -0800426 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800427
sandeepjsb6c87872021-09-27 15:34:44 +0000428 /**
429 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
430 * one ICCID active at the same time.
431 * Apps should use below API signatures if targeting SDK is T and beyond.
432 *
433 * @hide
434 */
435 @ChangeId
436 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
437 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800438
Naina Nallurid63128d2019-09-17 14:10:30 -0700439 /**
Chen Xu540470b2021-12-14 17:15:47 -0800440 * Apps targeting on Android T and beyond will get exception whenever icc close channel
441 * operation fails.
442 */
443 @ChangeId
444 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
445 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
446
447 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700448 * A request object to use for transmitting data to an ICC.
449 */
450 private static final class IccAPDUArgument {
451 public int channel, cla, command, p1, p2, p3;
452 public String data;
453
454 public IccAPDUArgument(int channel, int cla, int command,
455 int p1, int p2, int p3, String data) {
456 this.channel = channel;
457 this.cla = cla;
458 this.command = command;
459 this.p1 = p1;
460 this.p2 = p2;
461 this.p3 = p3;
462 this.data = data;
463 }
464 }
465
466 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700467 * A request object to use for transmitting data to an ICC.
468 */
469 private static final class ManualNetworkSelectionArgument {
470 public OperatorInfo operatorInfo;
471 public boolean persistSelection;
472
473 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
474 this.operatorInfo = operatorInfo;
475 this.persistSelection = persistSelection;
476 }
477 }
478
Sarah Chin71b3a852022-09-28 15:54:19 -0700479 private static final class PurchasePremiumCapabilityArgument {
480 public @TelephonyManager.PremiumCapability int capability;
481 public @NonNull String appName;
482 public @NonNull IIntegerConsumer callback;
483
484 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
485 @NonNull String appName, @NonNull IIntegerConsumer callback) {
486 this.capability = capability;
487 this.appName = appName;
488 this.callback = callback;
489 }
490 }
491
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700492 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700493 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
494 * request after sending. The main thread will notify the request when it is complete.
495 */
496 private static final class MainThreadRequest {
497 /** The argument to use for the request */
498 public Object argument;
499 /** The result of the request that is run on the main thread */
500 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800501 // The subscriber id that this request applies to. Defaults to
502 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
503 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504
Nathan Harold92bed182018-10-12 18:16:49 -0700505 // In cases where subId is unavailable, the caller needs to specify the phone.
506 public Phone phone;
507
vagdeviaf9a5b92018-08-15 16:01:53 -0700508 public WorkSource workSource;
509
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510 public MainThreadRequest(Object argument) {
511 this.argument = argument;
512 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800513
Nathan Harold92bed182018-10-12 18:16:49 -0700514 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
515 this.argument = argument;
516 if (phone != null) {
517 this.phone = phone;
518 }
519 this.workSource = workSource;
520 }
521
vagdeviaf9a5b92018-08-15 16:01:53 -0700522 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800523 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800524 if (subId != null) {
525 this.subId = subId;
526 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700527 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529 }
530
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800531 private static final class IncomingThirdPartyCallArgs {
532 public final ComponentName component;
533 public final String callId;
534 public final String callerDisplayName;
535
536 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
537 String callerDisplayName) {
538 this.component = component;
539 this.callId = callId;
540 this.callerDisplayName = callerDisplayName;
541 }
542 }
543
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544 /**
545 * A handler that processes messages on the main thread in the phone process. Since many
546 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
547 * inbound binder threads to the main thread in the phone process. The Binder thread
548 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
549 * on, which will be notified when the operation completes and will contain the result of the
550 * request.
551 *
552 * <p>If a MainThreadRequest object is provided in the msg.obj field,
553 * note that request.result must be set to something non-null for the calling thread to
554 * unblock.
555 */
556 private final class MainThreadHandler extends Handler {
557 @Override
558 public void handleMessage(Message msg) {
559 MainThreadRequest request;
560 Message onCompleted;
561 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000562 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800564 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700565
566 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 case CMD_HANDLE_USSD_REQUEST: {
568 request = (MainThreadRequest) msg.obj;
569 final Phone phone = getPhoneFromRequest(request);
570 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800571 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700572 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700573
Pengquan Menga1bb6272018-09-06 09:59:22 -0700574 if (!isUssdApiAllowed(request.subId)) {
575 // Carrier does not support use of this API, return failure.
576 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
577 UssdResponse response = new UssdResponse(ussdRequest, null);
578 Bundle returnData = new Bundle();
579 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
580 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700581
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 request.result = true;
583 notifyRequester(request);
584 return;
585 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700586
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 try {
588 request.result = phone != null
589 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
590 } catch (CallStateException cse) {
591 request.result = false;
592 }
593 // Wake up the requesting thread
594 notifyRequester(request);
595 break;
pkanwar32d516d2016-10-14 19:37:38 -0700596 }
597
Yorke Lee716f67e2015-06-17 15:39:16 -0700598 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700599 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700600 final Phone phone = getPhoneFromRequest(request);
601 request.result = phone != null ?
602 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
603 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700604 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700605 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700606 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700608
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000612 uiccPort = getUiccPortFromRequest(request);
613 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700614 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800615 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700617 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800619 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000620 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800621 iccArgument.channel, iccArgument.cla, iccArgument.command,
622 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
623 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 break;
626
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 ar = (AsyncResult) msg.obj;
629 request = (MainThreadRequest) ar.userObj;
630 if (ar.exception == null && ar.result != null) {
631 request.result = ar.result;
632 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800633 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 if (ar.result == null) {
635 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800636 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800638 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 } else {
640 loge("iccTransmitApduLogicalChannel: Unknown exception");
641 }
642 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700643 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 break;
645
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700646 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
647 request = (MainThreadRequest) msg.obj;
648 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000649 uiccPort = getUiccPortFromRequest(request);
650 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700651 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800652 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700653 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 } else {
655 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800656 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000657 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800658 iccArgument.cla, iccArgument.command, iccArgument.p1,
659 iccArgument.p2,
660 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700661 }
662 break;
663
664 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
665 ar = (AsyncResult) msg.obj;
666 request = (MainThreadRequest) ar.userObj;
667 if (ar.exception == null && ar.result != null) {
668 request.result = ar.result;
669 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800670 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 if (ar.result == null) {
672 loge("iccTransmitApduBasicChannel: Empty response");
673 } else if (ar.exception instanceof CommandException) {
674 loge("iccTransmitApduBasicChannel: CommandException: " +
675 ar.exception);
676 } else {
677 loge("iccTransmitApduBasicChannel: Unknown exception");
678 }
679 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700680 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 break;
682
683 case CMD_EXCHANGE_SIM_IO:
684 request = (MainThreadRequest) msg.obj;
685 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000686 uiccPort = getUiccPortFromRequest(request);
687 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800689 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 } else {
692 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
693 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000694 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
696 iccArgument.data, onCompleted);
697 }
698 break;
699
700 case EVENT_EXCHANGE_SIM_IO_DONE:
701 ar = (AsyncResult) msg.obj;
702 request = (MainThreadRequest) ar.userObj;
703 if (ar.exception == null && ar.result != null) {
704 request.result = ar.result;
705 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800706 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700708 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 break;
710
Derek Tan4d5e5c12014-02-04 11:54:58 -0800711 case CMD_SEND_ENVELOPE:
712 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000713 uiccPort = getUiccPortFromRequest(request);
714 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700715 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800716 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700718 } else {
719 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800720 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700721 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800722 break;
723
724 case EVENT_SEND_ENVELOPE_DONE:
725 ar = (AsyncResult) msg.obj;
726 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700727 if (ar.exception == null && ar.result != null) {
728 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800729 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800730 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700731 if (ar.result == null) {
732 loge("sendEnvelopeWithStatus: Empty response");
733 } else if (ar.exception instanceof CommandException) {
734 loge("sendEnvelopeWithStatus: CommandException: " +
735 ar.exception);
736 } else {
737 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
738 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800739 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800741 break;
742
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 case CMD_OPEN_CHANNEL:
744 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000745 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800746 IccLogicalChannelRequest openChannelRequest =
747 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000748 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700749 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800750 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800751 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700752 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700753 } else {
754 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800755 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
756 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700757 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 break;
759
760 case EVENT_OPEN_CHANNEL_DONE:
761 ar = (AsyncResult) msg.obj;
762 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700763 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700765 int[] result = (int[]) ar.result;
766 int channelId = result[0];
767 byte[] selectResponse = null;
768 if (result.length > 1) {
769 selectResponse = new byte[result.length - 1];
770 for (int i = 1; i < result.length; ++i) {
771 selectResponse[i - 1] = (byte) result[i];
772 }
773 }
774 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800775 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800776
777 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700778 if (uiccPort == null) {
779 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
780 } else {
781 IccLogicalChannelRequest channelRequest =
782 (IccLogicalChannelRequest) request.argument;
783 channelRequest.channel = channelId;
784 uiccPort.onLogicalChannelOpened(channelRequest);
785 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700786 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 if (ar.result == null) {
788 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700789 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700790 if (ar.exception != null) {
791 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
792 }
793
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700794 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700795 if (ar.exception instanceof CommandException) {
796 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800797 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700798 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700799 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700800 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700801 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700802 }
803 }
804 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800805 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700806 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700807 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700808 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700809 break;
810
811 case CMD_CLOSE_CHANNEL:
812 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000813 uiccPort = getUiccPortFromRequest(request);
814 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700815 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800816 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800817 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800818 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700819 } else {
820 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000821 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700822 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700823 break;
824
825 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800826 ar = (AsyncResult) msg.obj;
827 request = (MainThreadRequest) ar.userObj;
828 if (ar.exception == null) {
829 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800830 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700831 if (uiccPort == null) {
832 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
833 } else {
834 final int channelId = (Integer) request.argument;
835 uiccPort.onLogicalChannelClosed(channelId);
836 }
Chen Xu540470b2021-12-14 17:15:47 -0800837 } else {
838 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800839 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800840 if (ar.exception instanceof CommandException) {
841 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
842 CommandException.Error error =
843 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800844 if (error == CommandException.Error.INVALID_ARGUMENTS) {
845 // should only throw exceptions from the binder threads.
846 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800847 "iccCloseLogicalChannel: invalid argument ");
848 }
849 } else {
850 loge("iccCloseLogicalChannel: Unknown exception");
851 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800852 request.result = (exception != null) ? exception :
853 new IllegalStateException(
854 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800855 }
856 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800857 break;
858
859 case CMD_NV_READ_ITEM:
860 request = (MainThreadRequest) msg.obj;
861 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800862 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
863 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800864 break;
865
866 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700867 ar = (AsyncResult) msg.obj;
868 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800869 if (ar.exception == null && ar.result != null) {
870 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700871 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800872 request.result = "";
873 if (ar.result == null) {
874 loge("nvReadItem: Empty response");
875 } else if (ar.exception instanceof CommandException) {
876 loge("nvReadItem: CommandException: " +
877 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700878 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800879 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700880 }
881 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700882 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700883 break;
884
Jake Hambye994d462014-02-03 13:10:13 -0800885 case CMD_NV_WRITE_ITEM:
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
888 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800889 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700890 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800891 break;
892
893 case EVENT_NV_WRITE_ITEM_DONE:
894 handleNullReturnEvent(msg, "nvWriteItem");
895 break;
896
897 case CMD_NV_WRITE_CDMA_PRL:
898 request = (MainThreadRequest) msg.obj;
899 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800900 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800901 break;
902
903 case EVENT_NV_WRITE_CDMA_PRL_DONE:
904 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
905 break;
906
chen xu6dac5ab2018-10-26 17:39:23 -0700907 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800908 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700909 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800910 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800911 break;
912
chen xu6dac5ab2018-10-26 17:39:23 -0700913 case EVENT_RESET_MODEM_CONFIG_DONE:
914 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800915 break;
916
Sooraj Sasindran37444802020-08-11 10:40:43 -0700917 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
918 request = (MainThreadRequest) msg.obj;
919 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
920 request);
921 Phone phone = getPhoneFromRequest(request);
922 if (phone != null) {
923 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
924 } else {
925 loge("isNRDualConnectivityEnabled: No phone object");
926 request.result = false;
927 notifyRequester(request);
928 }
929 break;
930 }
931
932 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
933 ar = (AsyncResult) msg.obj;
934 request = (MainThreadRequest) ar.userObj;
935 if (ar.exception == null && ar.result != null) {
936 request.result = ar.result;
937 } else {
938 // request.result must be set to something non-null
939 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700940 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700941 request.result = ar.result;
942 } else {
943 request.result = false;
944 }
945 if (ar.result == null) {
946 loge("isNRDualConnectivityEnabled: Empty response");
947 } else if (ar.exception instanceof CommandException) {
948 loge("isNRDualConnectivityEnabled: CommandException: "
949 + ar.exception);
950 } else {
951 loge("isNRDualConnectivityEnabled: Unknown exception");
952 }
953 }
954 notifyRequester(request);
955 break;
956
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700957 case CMD_IS_VONR_ENABLED: {
958 request = (MainThreadRequest) msg.obj;
959 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
960 request);
961 Phone phone = getPhoneFromRequest(request);
962 if (phone != null) {
963 phone.isVoNrEnabled(onCompleted, request.workSource);
964 } else {
965 loge("isVoNrEnabled: No phone object");
966 request.result = false;
967 notifyRequester(request);
968 }
969 break;
970 }
971
972 case EVENT_IS_VONR_ENABLED_DONE:
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 if (ar.exception == null && ar.result != null) {
976 request.result = ar.result;
977 } else {
978 // request.result must be set to something non-null
979 // for the calling thread to unblock
980 if (ar.result != null) {
981 request.result = ar.result;
982 } else {
983 request.result = false;
984 }
985 if (ar.result == null) {
986 loge("isVoNrEnabled: Empty response");
987 } else if (ar.exception instanceof CommandException) {
988 loge("isVoNrEnabled: CommandException: "
989 + ar.exception);
990 } else {
991 loge("isVoNrEnabled: Unknown exception");
992 }
993 }
994 notifyRequester(request);
995 break;
996
Sooraj Sasindran37444802020-08-11 10:40:43 -0700997 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
998 request = (MainThreadRequest) msg.obj;
999 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1000 Phone phone = getPhoneFromRequest(request);
1001 if (phone != null) {
1002 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1003 request.workSource);
1004 } else {
1005 loge("enableNrDualConnectivity: No phone object");
1006 request.result =
1007 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1008 notifyRequester(request);
1009 }
1010 break;
1011 }
1012
1013 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1014 ar = (AsyncResult) msg.obj;
1015 request = (MainThreadRequest) ar.userObj;
1016 if (ar.exception == null) {
1017 request.result =
1018 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1019 } else {
1020 request.result =
1021 TelephonyManager
1022 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1023 if (ar.exception instanceof CommandException) {
1024 CommandException.Error error =
1025 ((CommandException) (ar.exception)).getCommandError();
1026 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1027 request.result =
1028 TelephonyManager
1029 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001030 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1031 request.result =
1032 TelephonyManager
1033 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001034 }
1035 loge("enableNrDualConnectivity" + ": CommandException: "
1036 + ar.exception);
1037 } else {
1038 loge("enableNrDualConnectivity" + ": Unknown exception");
1039 }
1040 }
1041 notifyRequester(request);
1042 break;
1043 }
1044
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001045 case CMD_ENABLE_VONR: {
1046 request = (MainThreadRequest) msg.obj;
1047 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1048 Phone phone = getPhoneFromRequest(request);
1049 if (phone != null) {
1050 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1051 request.workSource);
1052 } else {
1053 loge("setVoNrEnabled: No phone object");
1054 request.result =
1055 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1056 notifyRequester(request);
1057 }
1058 break;
1059 }
1060
1061 case EVENT_ENABLE_VONR_DONE: {
1062 ar = (AsyncResult) msg.obj;
1063 request = (MainThreadRequest) ar.userObj;
1064 if (ar.exception == null) {
1065 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1066 } else {
1067 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1068 if (ar.exception instanceof CommandException) {
1069 CommandException.Error error =
1070 ((CommandException) (ar.exception)).getCommandError();
1071 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1072 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1073 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1074 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1075 } else {
1076 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1077 }
1078 loge("setVoNrEnabled" + ": CommandException: "
1079 + ar.exception);
1080 } else {
1081 loge("setVoNrEnabled" + ": Unknown exception");
1082 }
1083 }
1084 notifyRequester(request);
1085 break;
1086 }
1087
SongFerngWang3ef3e072020-12-21 16:41:52 +08001088 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001089 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001090 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1091 request);
1092 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001093 break;
1094
SongFerngWang3ef3e072020-12-21 16:41:52 +08001095 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001096 ar = (AsyncResult) msg.obj;
1097 request = (MainThreadRequest) ar.userObj;
1098 if (ar.exception == null && ar.result != null) {
1099 request.result = ar.result; // Integer
1100 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301101 // request.result must be set to something non-null
1102 // for the calling thread to unblock
1103 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001104 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001105 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001106 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001107 loge("getAllowedNetworkTypesBitmask: CommandException: "
1108 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001109 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001110 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001111 }
1112 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001113 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001114 break;
1115
SongFerngWang3ef3e072020-12-21 16:41:52 +08001116 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001117 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001118 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1119 request);
1120 Pair<Integer, Long> reasonWithNetworkTypes =
1121 (Pair<Integer, Long>) request.argument;
1122 getPhoneFromRequest(request).setAllowedNetworkTypes(
1123 reasonWithNetworkTypes.first,
1124 reasonWithNetworkTypes.second,
1125 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001126 break;
1127
SongFerngWang3ef3e072020-12-21 16:41:52 +08001128 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1129 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001130 break;
1131
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001132 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1133 request = (MainThreadRequest)msg.obj;
1134 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001135 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001136 break;
1137
1138 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1139 ar = (AsyncResult)msg.obj;
1140 request = (MainThreadRequest)ar.userObj;
1141 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001142 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001143 break;
1144
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001145 case CMD_SET_VOICEMAIL_NUMBER:
1146 request = (MainThreadRequest) msg.obj;
1147 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1148 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001149 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1150 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001151 break;
1152
1153 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1154 handleNullReturnEvent(msg, "setVoicemailNumber");
1155 break;
1156
Stuart Scott54788802015-03-30 13:18:01 -07001157 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1158 request = (MainThreadRequest) msg.obj;
1159 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1160 request);
1161 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1162 break;
1163
1164 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1165 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1166 break;
1167
Shishir Agrawal302c8692015-06-19 13:49:39 -07001168 case CMD_PERFORM_NETWORK_SCAN:
1169 request = (MainThreadRequest) msg.obj;
1170 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1171 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1172 break;
1173
Hall Liu27d24262020-09-18 19:04:59 -07001174 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001175 request = (MainThreadRequest) msg.obj;
1176 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001177 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1178 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1179 request.argument;
1180 int callForwardingReason = args.first;
1181 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001182 break;
Hall Liu27d24262020-09-18 19:04:59 -07001183 }
1184 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001185 ar = (AsyncResult) msg.obj;
1186 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001187 TelephonyManager.CallForwardingInfoCallback callback =
1188 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1189 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001190 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001191 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001192 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1193 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1194 // Service Class is a bit mask per 3gpp 27.007. Search for
1195 // any service for voice call.
1196 if ((callForwardInfo.serviceClass
1197 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001198 callForwardingInfo = new CallForwardingInfo(
1199 callForwardInfo.status
1200 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001201 callForwardInfo.reason,
1202 callForwardInfo.number,
1203 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001204 break;
1205 }
1206 }
1207 // Didn't find a call forward info for voice call.
1208 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001209 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1210 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001211 }
Hall Liu27d24262020-09-18 19:04:59 -07001212 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001213 } else {
1214 if (ar.result == null) {
1215 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1216 }
1217 if (ar.exception != null) {
1218 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1219 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001220 int errorCode = TelephonyManager
1221 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001222 if (ar.exception instanceof CommandException) {
1223 CommandException.Error error =
1224 ((CommandException) (ar.exception)).getCommandError();
1225 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001226 errorCode = TelephonyManager
1227 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001228 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001229 errorCode = TelephonyManager
1230 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001231 }
1232 }
Hall Liu27d24262020-09-18 19:04:59 -07001233 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001234 }
Shuo Qian4a594052020-01-23 11:59:30 -08001235 break;
Hall Liu27d24262020-09-18 19:04:59 -07001236 }
Shuo Qian4a594052020-01-23 11:59:30 -08001237
Hall Liu27d24262020-09-18 19:04:59 -07001238 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001239 request = (MainThreadRequest) msg.obj;
1240 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001241 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001242 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001243 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1244 request.argument).first;
1245 request.phone.setCallForwardingOption(
1246 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001247 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001248 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001249 callForwardingInfoToSet.getReason(),
1250 callForwardingInfoToSet.getNumber(),
1251 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1252 break;
Hall Liu27d24262020-09-18 19:04:59 -07001253 }
Shuo Qian4a594052020-01-23 11:59:30 -08001254
Hall Liu27d24262020-09-18 19:04:59 -07001255 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001256 ar = (AsyncResult) msg.obj;
1257 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001258 Consumer<Integer> callback =
1259 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1260 request.argument).second;
1261 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001262 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001263 int errorCode = TelephonyManager.CallForwardingInfoCallback
1264 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001265 if (ar.exception instanceof CommandException) {
1266 CommandException.Error error =
1267 ((CommandException) (ar.exception)).getCommandError();
1268 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001269 errorCode = TelephonyManager.CallForwardingInfoCallback
1270 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001271 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001272 errorCode = TelephonyManager.CallForwardingInfoCallback
1273 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001274 }
1275 }
1276 callback.accept(errorCode);
1277 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001278 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001279 }
Shuo Qian4a594052020-01-23 11:59:30 -08001280 break;
Hall Liu27d24262020-09-18 19:04:59 -07001281 }
Shuo Qian4a594052020-01-23 11:59:30 -08001282
Hall Liu27d24262020-09-18 19:04:59 -07001283 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001284 request = (MainThreadRequest) msg.obj;
1285 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1286 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1287 break;
Hall Liu27d24262020-09-18 19:04:59 -07001288 }
Shuo Qian4a594052020-01-23 11:59:30 -08001289
Hall Liu27d24262020-09-18 19:04:59 -07001290 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001291 ar = (AsyncResult) msg.obj;
1292 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001293 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001294 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001295 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001296 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001297 // Service Class is a bit mask per 3gpp 27.007.
1298 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001299 if (callForwardResults.length > 1
1300 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001301 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001302 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001303 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1304 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001305 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001306 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001307 }
1308 } else {
1309 if (ar.result == null) {
1310 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1311 }
1312 if (ar.exception != null) {
1313 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1314 }
1315 if (ar.exception instanceof CommandException) {
1316 CommandException.Error error =
1317 ((CommandException) (ar.exception)).getCommandError();
1318 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001319 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001320 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001321 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1322 callWaitingStatus =
1323 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001324 }
1325 }
1326 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001327 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001328 break;
Hall Liu27d24262020-09-18 19:04:59 -07001329 }
Shuo Qian4a594052020-01-23 11:59:30 -08001330
Hall Liu27d24262020-09-18 19:04:59 -07001331 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001332 request = (MainThreadRequest) msg.obj;
1333 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001334 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1335 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001336 break;
Hall Liu27d24262020-09-18 19:04:59 -07001337 }
Shuo Qian4a594052020-01-23 11:59:30 -08001338
Hall Liu27d24262020-09-18 19:04:59 -07001339 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001340 ar = (AsyncResult) msg.obj;
1341 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001342 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1343 Consumer<Integer> callback =
1344 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1345 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001346 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001347 if (ar.exception instanceof CommandException) {
1348 CommandException.Error error =
1349 ((CommandException) (ar.exception)).getCommandError();
1350 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1351 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001352 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1353 callback.accept(
1354 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001355 } else {
1356 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1357 }
1358 } else {
1359 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1360 }
1361 } else {
1362 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1363 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001364 }
Shuo Qian4a594052020-01-23 11:59:30 -08001365 break;
Hall Liu27d24262020-09-18 19:04:59 -07001366 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001367 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1368 ar = (AsyncResult) msg.obj;
1369 request = (MainThreadRequest) ar.userObj;
1370 CellNetworkScanResult cellScanResult;
1371 if (ar.exception == null && ar.result != null) {
1372 cellScanResult = new CellNetworkScanResult(
1373 CellNetworkScanResult.STATUS_SUCCESS,
1374 (List<OperatorInfo>) ar.result);
1375 } else {
1376 if (ar.result == null) {
1377 loge("getCellNetworkScanResults: Empty response");
1378 }
1379 if (ar.exception != null) {
1380 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1381 }
1382 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1383 if (ar.exception instanceof CommandException) {
1384 CommandException.Error error =
1385 ((CommandException) (ar.exception)).getCommandError();
1386 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1387 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1388 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1389 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1390 }
1391 }
1392 cellScanResult = new CellNetworkScanResult(errorCode, null);
1393 }
1394 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001395 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001396 break;
1397
1398 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1399 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001400 ManualNetworkSelectionArgument selArg =
1401 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001402 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1403 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001404 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1405 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001406 break;
1407
1408 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001409 ar = (AsyncResult) msg.obj;
1410 request = (MainThreadRequest) ar.userObj;
1411 if (ar.exception == null) {
1412 request.result = true;
1413 } else {
1414 request.result = false;
1415 loge("setNetworkSelectionModeManual " + ar.exception);
1416 }
1417 notifyRequester(request);
1418 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001419 break;
1420
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001421 case CMD_GET_MODEM_ACTIVITY_INFO:
1422 request = (MainThreadRequest) msg.obj;
1423 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001424 if (defaultPhone != null) {
1425 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001426 } else {
1427 ResultReceiver result = (ResultReceiver) request.argument;
1428 Bundle bundle = new Bundle();
1429 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001430 new ModemActivityInfo(0, 0, 0,
1431 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001432 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001433 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001434 break;
1435
Hall Liud0f208c2020-10-14 16:54:44 -07001436 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001437 ar = (AsyncResult) msg.obj;
1438 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001439 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001440 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001441 if (mLastModemActivityInfo == null) {
1442 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1443 mLastModemActivitySpecificInfo[0] =
1444 new ActivityStatsTechSpecificInfo(
1445 0,
1446 0,
1447 new int[ModemActivityInfo.getNumTxPowerLevels()],
1448 0);
1449 mLastModemActivityInfo =
1450 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1451 }
1452
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001453 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001454 // Update the last modem activity info and the result of the request.
1455 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1456 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001457 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001458 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001459 mLastModemActivityInfo =
1460 new ModemActivityInfo(
1461 mLastModemActivityInfo.getTimestampMillis(),
1462 mLastModemActivityInfo.getSleepTimeMillis(),
1463 mLastModemActivityInfo.getIdleTimeMillis(),
1464 mLastModemActivitySpecificInfo);
1465
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001466 } else {
1467 if (ar.result == null) {
1468 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001469 error = TelephonyManager.ModemActivityInfoException
1470 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001471 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001472 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001473 error = TelephonyManager.ModemActivityInfoException
1474 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001475 } else {
1476 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001477 error = TelephonyManager.ModemActivityInfoException
1478 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001479 }
1480 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001481 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001482 if (mLastModemActivityInfo != null) {
1483 bundle.putParcelable(
1484 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1485 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001486 } else {
1487 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1488 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001489 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001490 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001491 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001492 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001493
Meng Wang1a7c35a2016-05-05 20:56:15 -07001494 case CMD_SET_ALLOWED_CARRIERS:
1495 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001496 CarrierRestrictionRules argument =
1497 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001498 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001499 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001500 break;
1501
1502 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1503 ar = (AsyncResult) msg.obj;
1504 request = (MainThreadRequest) ar.userObj;
1505 if (ar.exception == null && ar.result != null) {
1506 request.result = ar.result;
1507 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001508 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1509 if (ar.exception instanceof CommandException) {
1510 loge("setAllowedCarriers: CommandException: " + ar.exception);
1511 CommandException.Error error =
1512 ((CommandException) (ar.exception)).getCommandError();
1513 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1514 request.result =
1515 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1516 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001517 } else {
1518 loge("setAllowedCarriers: Unknown exception");
1519 }
1520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001521 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001522 break;
1523
1524 case CMD_GET_ALLOWED_CARRIERS:
1525 request = (MainThreadRequest) msg.obj;
1526 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001527 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001528 break;
1529
1530 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1531 ar = (AsyncResult) msg.obj;
1532 request = (MainThreadRequest) ar.userObj;
1533 if (ar.exception == null && ar.result != null) {
1534 request.result = ar.result;
1535 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001536 request.result = new IllegalStateException(
1537 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001538 if (ar.result == null) {
1539 loge("getAllowedCarriers: Empty response");
1540 } else if (ar.exception instanceof CommandException) {
1541 loge("getAllowedCarriers: CommandException: " +
1542 ar.exception);
1543 } else {
1544 loge("getAllowedCarriers: Unknown exception");
1545 }
1546 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001547 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001548 break;
1549
Nathan Haroldb3014052017-01-25 15:57:32 -08001550 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1551 ar = (AsyncResult) msg.obj;
1552 request = (MainThreadRequest) ar.userObj;
1553 if (ar.exception == null && ar.result != null) {
1554 request.result = ar.result;
1555 } else {
1556 request.result = new IllegalArgumentException(
1557 "Failed to retrieve Forbidden Plmns");
1558 if (ar.result == null) {
1559 loge("getForbiddenPlmns: Empty response");
1560 } else {
1561 loge("getForbiddenPlmns: Unknown exception");
1562 }
1563 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001564 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001565 break;
1566
1567 case CMD_GET_FORBIDDEN_PLMNS:
1568 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001569 uiccPort = getUiccPortFromRequest(request);
1570 if (uiccPort == null) {
1571 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001572 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001573 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001574 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001575 break;
1576 }
1577 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001578 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001579 if (uiccApp == null) {
1580 loge("getForbiddenPlmns() no app with specified type -- "
1581 + appType);
1582 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001583 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001584 break;
1585 } else {
1586 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1587 + " specified type -- " + appType);
1588 }
1589 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1590 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1591 onCompleted);
1592 break;
1593
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001594 case CMD_SWITCH_SLOTS:
1595 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001596 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001597 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001598 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001599 break;
1600
1601 case EVENT_SWITCH_SLOTS_DONE:
1602 ar = (AsyncResult) msg.obj;
1603 request = (MainThreadRequest) ar.userObj;
1604 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001605 notifyRequester(request);
1606 break;
1607 case CMD_GET_NETWORK_SELECTION_MODE:
1608 request = (MainThreadRequest) msg.obj;
1609 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1610 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1611 break;
1612
1613 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1614 ar = (AsyncResult) msg.obj;
1615 request = (MainThreadRequest) ar.userObj;
1616 if (ar.exception != null) {
1617 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1618 } else {
1619 int mode = ((int[]) ar.result)[0];
1620 if (mode == 0) {
1621 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1622 } else {
1623 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1624 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001625 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001626 notifyRequester(request);
1627 break;
1628 case CMD_GET_CDMA_ROAMING_MODE:
1629 request = (MainThreadRequest) msg.obj;
1630 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1631 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1632 break;
1633 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1634 ar = (AsyncResult) msg.obj;
1635 request = (MainThreadRequest) ar.userObj;
1636 if (ar.exception != null) {
1637 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1638 } else {
1639 request.result = ((int[]) ar.result)[0];
1640 }
1641 notifyRequester(request);
1642 break;
1643 case CMD_SET_CDMA_ROAMING_MODE:
1644 request = (MainThreadRequest) msg.obj;
1645 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1646 int mode = (int) request.argument;
1647 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1648 break;
1649 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1650 ar = (AsyncResult) msg.obj;
1651 request = (MainThreadRequest) ar.userObj;
1652 request.result = ar.exception == null;
1653 notifyRequester(request);
1654 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001655 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1656 request = (MainThreadRequest) msg.obj;
1657 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1658 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1659 break;
1660 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1661 ar = (AsyncResult) msg.obj;
1662 request = (MainThreadRequest) ar.userObj;
1663 if (ar.exception != null) {
1664 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1665 } else {
1666 request.result = ((int[]) ar.result)[0];
1667 }
1668 notifyRequester(request);
1669 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001670 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1671 request = (MainThreadRequest) msg.obj;
1672 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1673 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001674 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1675 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001676 break;
1677 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1678 ar = (AsyncResult) msg.obj;
1679 request = (MainThreadRequest) ar.userObj;
1680 request.result = ar.exception == null;
1681 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001682 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001683 case CMD_GET_ALL_CELL_INFO:
1684 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001685 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001686 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001687 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001688 case EVENT_GET_ALL_CELL_INFO_DONE:
1689 ar = (AsyncResult) msg.obj;
1690 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001691 // If a timeout occurs, the response will be null
1692 request.result = (ar.exception == null && ar.result != null)
1693 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001694 synchronized (request) {
1695 request.notifyAll();
1696 }
1697 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001698 case CMD_REQUEST_CELL_INFO_UPDATE:
1699 request = (MainThreadRequest) msg.obj;
1700 request.phone.requestCellInfoUpdate(request.workSource,
1701 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1702 break;
1703 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1704 ar = (AsyncResult) msg.obj;
1705 request = (MainThreadRequest) ar.userObj;
1706 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1707 try {
1708 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001709 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001710 cb.onError(
1711 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1712 ar.exception.getClass().getName(),
1713 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001714 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001715 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001716 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001717 } else {
1718 // use the result as returned
1719 cb.onCellInfo((List<CellInfo>) ar.result);
1720 }
1721 } catch (RemoteException re) {
1722 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1723 }
1724 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001725 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001726 request = (MainThreadRequest) msg.obj;
1727 WorkSource ws = (WorkSource) request.argument;
1728 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001729 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001730 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001731 }
1732 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 if (ar.exception == null) {
1736 request.result = ar.result;
1737 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001738 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001739 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001740 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001741 }
1742
1743 synchronized (request) {
1744 request.notifyAll();
1745 }
1746 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001747 }
chen xu6dac5ab2018-10-26 17:39:23 -07001748 case CMD_MODEM_REBOOT:
1749 request = (MainThreadRequest) msg.obj;
1750 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001751 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001752 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001753 case EVENT_CMD_MODEM_REBOOT_DONE:
1754 handleNullReturnEvent(msg, "rebootModem");
1755 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001756 case CMD_REQUEST_ENABLE_MODEM:
1757 request = (MainThreadRequest) msg.obj;
1758 boolean enable = (boolean) request.argument;
1759 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001760 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001761 PhoneConfigurationManager.getInstance()
1762 .enablePhone(request.phone, enable, onCompleted);
1763 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001764 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001765 ar = (AsyncResult) msg.obj;
1766 request = (MainThreadRequest) ar.userObj;
1767 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001768 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001769 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001770 if ((boolean) request.result) {
1771 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1772 updateModemStateMetrics();
1773 } else {
1774 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1775 + ar.exception);
1776 }
1777 notifyRequester(request);
1778 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001779 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001780 case CMD_GET_MODEM_STATUS:
1781 request = (MainThreadRequest) msg.obj;
1782 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1783 PhoneConfigurationManager.getInstance()
1784 .getPhoneStatusFromModem(request.phone, onCompleted);
1785 break;
1786 case EVENT_GET_MODEM_STATUS_DONE:
1787 ar = (AsyncResult) msg.obj;
1788 request = (MainThreadRequest) ar.userObj;
1789 int id = request.phone.getPhoneId();
1790 if (ar.exception == null && ar.result != null) {
1791 request.result = ar.result;
1792 //update the cache as modem status has changed
1793 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1794 (boolean) request.result);
1795 } else {
1796 // Return true if modem status cannot be retrieved. For most cases,
1797 // modem status is on. And for older version modems, GET_MODEM_STATUS
1798 // and disable modem are not supported. Modem is always on.
1799 // TODO: this should be fixed in R to support a third
1800 // status UNKNOWN b/131631629
1801 request.result = true;
1802 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1803 + ar.exception);
1804 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001805 notifyRequester(request);
1806 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001807 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1808 request = (MainThreadRequest) msg.obj;
1809 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1810 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1811 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1812 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1813 break;
1814 }
1815 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1816 ar = (AsyncResult) msg.obj;
1817 request = (MainThreadRequest) ar.userObj;
1818 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1819 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1820 args.second.accept(ar.exception == null);
1821 notifyRequester(request);
1822 break;
1823 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001824 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1825 request = (MainThreadRequest) msg.obj;
1826 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1827 Phone phone = getPhoneFromRequest(request);
1828 if (phone != null) {
1829 phone.getSystemSelectionChannels(onCompleted);
1830 } else {
1831 loge("getSystemSelectionChannels: No phone object");
1832 request.result = new ArrayList<RadioAccessSpecifier>();
1833 notifyRequester(request);
1834 }
1835 break;
1836 }
1837 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_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 {
Sarah Chin428d1d62021-03-13 03:17:40 -08001843 request.result = new IllegalStateException(
1844 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001845 if (ar.result == null) {
1846 loge("getSystemSelectionChannels: Empty response");
1847 } else {
1848 loge("getSystemSelectionChannels: Unknown exception");
1849 }
1850 }
1851 notifyRequester(request);
1852 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001853 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1854 ar = (AsyncResult) msg.obj;
1855 request = (MainThreadRequest) ar.userObj;
1856 if (ar.exception == null && ar.result != null) {
1857 request.result = ar.result;
1858 } else {
1859 request.result = -1;
1860 loge("Failed to set Forbidden Plmns");
1861 if (ar.result == null) {
1862 loge("setForbidenPlmns: Empty response");
1863 } else if (ar.exception != null) {
1864 loge("setForbiddenPlmns: Exception: " + ar.exception);
1865 request.result = -1;
1866 } else {
1867 loge("setForbiddenPlmns: Unknown exception");
1868 }
1869 }
1870 notifyRequester(request);
1871 break;
1872 case CMD_SET_FORBIDDEN_PLMNS:
1873 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001874 uiccPort = getUiccPortFromRequest(request);
1875 if (uiccPort == null) {
1876 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001877 request.result = -1;
1878 notifyRequester(request);
1879 break;
1880 }
1881 Pair<Integer, List<String>> setFplmnsArgs =
1882 (Pair<Integer, List<String>>) request.argument;
1883 appType = setFplmnsArgs.first;
1884 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001885 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001886 if (uiccApp == null) {
1887 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1888 request.result = -1;
1889 loge("Failed to get UICC App");
1890 notifyRequester(request);
1891 } else {
1892 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1893 ((SIMRecords) uiccApp.getIccRecords())
1894 .setForbiddenPlmns(onCompleted, fplmns);
1895 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001896 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001897 case CMD_ERASE_MODEM_CONFIG:
1898 request = (MainThreadRequest) msg.obj;
1899 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1900 defaultPhone.eraseModemConfig(onCompleted);
1901 break;
1902 case EVENT_ERASE_MODEM_CONFIG_DONE:
1903 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001904 break;
zoey chene02881a2019-12-30 16:11:23 +08001905
Kai Shif70f46f2021-03-03 13:59:46 -08001906 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1907 request = (MainThreadRequest) msg.obj;
1908 request.result = defaultPhone.eraseDataInSharedPreferences();
1909 notifyRequester(request);
1910 break;
1911
zoey chene02881a2019-12-30 16:11:23 +08001912 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1913 request = (MainThreadRequest) msg.obj;
1914 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1915 Pair<String, String> changed = (Pair<String, String>) request.argument;
1916 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1917 changed.first, changed.second, onCompleted);
1918 break;
1919 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1920 ar = (AsyncResult) msg.obj;
1921 request = (MainThreadRequest) ar.userObj;
1922 if (ar.exception == null) {
1923 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001924 // If the operation is successful, update the PIN storage
1925 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1926 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001927 UiccController.getInstance().getPinStorage()
1928 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001929 } else {
1930 request.result = msg.arg1;
1931 }
1932 notifyRequester(request);
1933 break;
1934
Michele Berionne5e411512020-11-13 02:36:59 +00001935 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001936 request = (MainThreadRequest) msg.obj;
1937 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1938 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1939 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1940 enabled.first, enabled.second, onCompleted);
1941 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001942 }
zoey chene02881a2019-12-30 16:11:23 +08001943 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1944 ar = (AsyncResult) msg.obj;
1945 request = (MainThreadRequest) ar.userObj;
1946 if (ar.exception == null) {
1947 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001948 // If the operation is successful, update the PIN storage
1949 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1950 int phoneId = getPhoneFromRequest(request).getPhoneId();
1951 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001952 UiccController.getInstance().getPinStorage()
1953 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001954 } else {
1955 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1956 }
zoey chene02881a2019-12-30 16:11:23 +08001957 } else {
1958 request.result = msg.arg1;
1959 }
Michele Berionne5e411512020-11-13 02:36:59 +00001960
1961
zoey chene02881a2019-12-30 16:11:23 +08001962 notifyRequester(request);
1963 break;
1964
Peter Wangdafb9ac2020-01-15 14:13:38 -08001965 case MSG_NOTIFY_USER_ACTIVITY:
1966 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001967 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001968 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1969 getDefaultPhone().getContext().sendBroadcastAsUser(
1970 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1971 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001972
1973 case CMD_SET_DATA_THROTTLING: {
1974 request = (MainThreadRequest) msg.obj;
1975 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1976 DataThrottlingRequest dataThrottlingRequest =
1977 (DataThrottlingRequest) request.argument;
1978 Phone phone = getPhoneFromRequest(request);
1979 if (phone != null) {
1980 phone.setDataThrottling(onCompleted,
1981 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1982 dataThrottlingRequest.getCompletionDurationMillis());
1983 } else {
1984 loge("setDataThrottling: No phone object");
1985 request.result =
1986 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1987 notifyRequester(request);
1988 }
1989
1990 break;
1991 }
1992 case EVENT_SET_DATA_THROTTLING_DONE:
1993 ar = (AsyncResult) msg.obj;
1994 request = (MainThreadRequest) ar.userObj;
1995
1996 if (ar.exception == null) {
1997 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1998 } else if (ar.exception instanceof CommandException) {
1999 loge("setDataThrottling: CommandException: " + ar.exception);
2000 CommandException.Error error =
2001 ((CommandException) (ar.exception)).getCommandError();
2002
2003 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2004 request.result = TelephonyManager
2005 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2006 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2007 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002008 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2009 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002010 } else {
2011 request.result =
2012 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2013 }
2014 } else {
2015 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2016 }
2017 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2018 notifyRequester(request);
2019 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002020
2021 case CMD_SET_SIM_POWER: {
2022 request = (MainThreadRequest) msg.obj;
2023 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2024 request = (MainThreadRequest) msg.obj;
2025 int stateToSet =
2026 ((Pair<Integer, IIntegerConsumer>)
2027 request.argument).first;
2028 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2029 break;
2030 }
2031 case EVENT_SET_SIM_POWER_DONE: {
2032 ar = (AsyncResult) msg.obj;
2033 request = (MainThreadRequest) ar.userObj;
2034 IIntegerConsumer callback =
2035 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2036 if (ar.exception != null) {
2037 loge("setSimPower exception: " + ar.exception);
2038 int errorCode = TelephonyManager.CallForwardingInfoCallback
2039 .RESULT_ERROR_UNKNOWN;
2040 if (ar.exception instanceof CommandException) {
2041 CommandException.Error error =
2042 ((CommandException) (ar.exception)).getCommandError();
2043 if (error == CommandException.Error.SIM_ERR) {
2044 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2045 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2046 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2047 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2048 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2049 } else {
2050 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2051 }
2052 }
2053 try {
2054 callback.accept(errorCode);
2055 } catch (RemoteException e) {
2056 // Ignore if the remote process is no longer available to call back.
2057 Log.w(LOG_TAG, "setSimPower: callback not available.");
2058 }
2059 } else {
2060 try {
2061 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2062 } catch (RemoteException e) {
2063 // Ignore if the remote process is no longer available to call back.
2064 Log.w(LOG_TAG, "setSimPower: callback not available.");
2065 }
2066 }
2067 break;
2068 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002069 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2070 request = (MainThreadRequest) msg.obj;
2071
2072 final Phone phone = getPhoneFromRequest(request);
2073 if (phone == null || phone.getServiceStateTracker() == null) {
2074 request.result = new IllegalStateException("Phone or SST is null");
2075 notifyRequester(request);
2076 break;
2077 }
2078
2079 Pair<Integer, SignalStrengthUpdateRequest> pair =
2080 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2081 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2082 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002083 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002084 request.subId, pair.first /*callingUid*/,
2085 pair.second /*request*/, onCompleted);
2086 break;
2087 }
2088 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2089 ar = (AsyncResult) msg.obj;
2090 request = (MainThreadRequest) ar.userObj;
2091 // request.result will be the exception of ar if present, true otherwise.
2092 // Be cautious not to leave result null which will wait() forever
2093 request.result = ar.exception != null ? ar.exception : true;
2094 notifyRequester(request);
2095 break;
2096 }
2097 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2098 request = (MainThreadRequest) msg.obj;
2099
2100 Phone phone = getPhoneFromRequest(request);
2101 if (phone == null || phone.getServiceStateTracker() == null) {
2102 request.result = new IllegalStateException("Phone or SST is null");
2103 notifyRequester(request);
2104 break;
2105 }
2106
2107 Pair<Integer, SignalStrengthUpdateRequest> pair =
2108 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2109 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2110 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002111 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002112 request.subId, pair.first /*callingUid*/,
2113 pair.second /*request*/, onCompleted);
2114 break;
2115 }
2116 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2117 ar = (AsyncResult) msg.obj;
2118 request = (MainThreadRequest) ar.userObj;
2119 request.result = ar.exception != null ? ar.exception : true;
2120 notifyRequester(request);
2121 break;
2122 }
Jordan Liu109698e2020-11-24 14:50:34 -08002123
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002124 case CMD_GET_SLICING_CONFIG: {
2125 request = (MainThreadRequest) msg.obj;
2126 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2127 request.phone.getSlicingConfig(onCompleted);
2128 break;
2129 }
2130 case EVENT_GET_SLICING_CONFIG_DONE: {
2131 ar = (AsyncResult) msg.obj;
2132 request = (MainThreadRequest) ar.userObj;
2133 ResultReceiver result = (ResultReceiver) request.argument;
2134
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002135 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002136 Bundle bundle = new Bundle();
2137 int resultCode = 0;
2138 if (ar.exception != null) {
2139 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2140 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002141 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002142 } else if (ar.result == null) {
2143 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002144 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002145 } else {
2146 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002147 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2148 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002149 }
2150
2151 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002152 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002153 }
2154 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2155 result.send(resultCode, bundle);
2156 notifyRequester(request);
2157 break;
2158 }
2159
Sarah Chin71b3a852022-09-28 15:54:19 -07002160 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002161 request = (MainThreadRequest) msg.obj;
2162 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002163 PurchasePremiumCapabilityArgument arg =
2164 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002165 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002166 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002167 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002168 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002169
Sarah Chin71b3a852022-09-28 15:54:19 -07002170 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002171 ar = (AsyncResult) msg.obj;
2172 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002173 PurchasePremiumCapabilityArgument arg =
2174 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002175 try {
2176 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002177 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002178 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002179 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002180 + ", result= "
2181 + TelephonyManager.convertPurchaseResultToString(result));
2182 } catch (RemoteException e) {
2183 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002184 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002185 + " failed: " + e;
2186 if (DBG) log(logStr);
2187 AnomalyReporter.reportAnomaly(
2188 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2189 }
2190 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002191 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002192
Michele Berionne5e411512020-11-13 02:36:59 +00002193 case CMD_PREPARE_UNATTENDED_REBOOT:
2194 request = (MainThreadRequest) msg.obj;
2195 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002196 UiccController.getInstance().getPinStorage()
2197 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002198 notifyRequester(request);
2199 break;
2200
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 default:
2202 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2203 break;
2204 }
2205 }
Jake Hambye994d462014-02-03 13:10:13 -08002206
Pengquan Menga1bb6272018-09-06 09:59:22 -07002207 private void notifyRequester(MainThreadRequest request) {
2208 synchronized (request) {
2209 request.notifyAll();
2210 }
2211 }
2212
Jake Hambye994d462014-02-03 13:10:13 -08002213 private void handleNullReturnEvent(Message msg, String command) {
2214 AsyncResult ar = (AsyncResult) msg.obj;
2215 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2216 if (ar.exception == null) {
2217 request.result = true;
2218 } else {
2219 request.result = false;
2220 if (ar.exception instanceof CommandException) {
2221 loge(command + ": CommandException: " + ar.exception);
2222 } else {
2223 loge(command + ": Unknown exception");
2224 }
2225 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002226 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -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) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002236 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2237 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002238 }
2239
2240 /**
2241 * Posts the specified command to be executed on the main thread,
2242 * waits for the request to complete, and returns the result.
2243 * @see #sendRequestAsync
2244 */
2245 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2246 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002247 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002248 }
2249
2250 /**
2251 * Posts the specified command to be executed on the main thread,
2252 * waits for the request to complete, and returns the result.
2253 * @see #sendRequestAsync
2254 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002255 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002256 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2257 }
2258
2259 /**
2260 * Posts the specified command to be executed on the main thread,
2261 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2262 * if not timeout or null otherwise.
2263 * @see #sendRequestAsync
2264 */
2265 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2266 long timeoutInMs) {
2267 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002268 }
2269
2270 /**
2271 * Posts the specified command to be executed on the main thread,
2272 * waits for the request to complete, and returns the result.
2273 * @see #sendRequestAsync
2274 */
Nathan Harold92bed182018-10-12 18:16:49 -07002275 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002276 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002277 }
2278
2279 /**
2280 * Posts the specified command to be executed on the main thread,
2281 * waits for the request to complete, and returns the result.
2282 * @see #sendRequestAsync
2283 */
2284 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002285 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2286 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002287 }
2288
2289 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002290 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2291 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2292 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002293 * @see #sendRequestAsync
2294 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002295 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2296 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2298 throw new RuntimeException("This method will deadlock if called from the main thread.");
2299 }
2300
Nathan Harold92bed182018-10-12 18:16:49 -07002301 MainThreadRequest request = null;
2302 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2303 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2304 } else if (phone != null) {
2305 request = new MainThreadRequest(argument, phone, workSource);
2306 } else {
2307 request = new MainThreadRequest(argument, subId, workSource);
2308 }
2309
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310 Message msg = mMainThreadHandler.obtainMessage(command, request);
2311 msg.sendToTarget();
2312
Rambo Wang0f050d82021-02-12 11:43:36 -08002313
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002315 if (timeoutInMs >= 0) {
2316 // Wait for at least timeoutInMs before returning null request result
2317 long now = SystemClock.elapsedRealtime();
2318 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002319 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002320 try {
2321 request.wait(deadline - now);
2322 } catch (InterruptedException e) {
2323 // Do nothing, go back and check if request is completed or timeout
2324 } finally {
2325 now = SystemClock.elapsedRealtime();
2326 }
2327 }
2328 } else {
2329 // Wait for the request to complete
2330 while (request.result == null) {
2331 try {
2332 request.wait();
2333 } catch (InterruptedException e) {
2334 // Do nothing, go back and wait until the request is complete
2335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 }
2337 }
2338 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002339 if (request.result == null) {
2340 Log.wtf(LOG_TAG,
2341 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 return request.result;
2344 }
2345
2346 /**
2347 * Asynchronous ("fire and forget") version of sendRequest():
2348 * Posts the specified command to be executed on the main thread, and
2349 * returns immediately.
2350 * @see #sendRequest
2351 */
2352 private void sendRequestAsync(int command) {
2353 mMainThreadHandler.sendEmptyMessage(command);
2354 }
2355
2356 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002357 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002358 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002359 */
2360 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002361 sendRequestAsync(command, argument, null, null);
2362 }
2363
2364 /**
2365 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2366 * @see {@link #sendRequest(int,Object)}
2367 */
2368 private void sendRequestAsync(
2369 int command, Object argument, Phone phone, WorkSource workSource) {
2370 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002371 Message msg = mMainThreadHandler.obtainMessage(command, request);
2372 msg.sendToTarget();
2373 }
2374
2375 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 * Initialize the singleton PhoneInterfaceManager instance.
2377 * This is only done once, at startup, from PhoneApp.onCreate().
2378 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002379 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 synchronized (PhoneInterfaceManager.class) {
2381 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002382 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 } else {
2384 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2385 }
2386 return sInstance;
2387 }
2388 }
2389
2390 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002391 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002394 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002395 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002397 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002398 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002399 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002400 mTelephonySharedPreferences =
2401 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002402 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002403 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002404 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002405 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002406 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002407 mTelephony2gUpdater = new Telephony2gUpdater(
2408 Executors.newSingleThreadExecutor(), mApp);
2409 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 publish();
2411 }
2412
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002413 private Phone getDefaultPhone() {
2414 Phone thePhone = getPhone(getDefaultSubscription());
2415 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2416 }
2417
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 private void publish() {
2419 if (DBG) log("publish: " + this);
2420
Peter Wangc035ce42020-01-08 21:00:22 -08002421 TelephonyFrameworkInitializer
2422 .getTelephonyServiceManager()
2423 .getTelephonyServiceRegisterer()
2424 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 }
2426
Stuart Scott584921c2015-01-15 17:10:34 -08002427 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002428 if (request.phone != null) {
2429 return request.phone;
2430 } else {
2431 return getPhoneFromSubId(request.subId);
2432 }
2433 }
2434
2435 private Phone getPhoneFromSubId(int subId) {
2436 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2437 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002438 }
2439
Rambo Wange53e07d2022-05-10 13:01:13 -07002440 @Nullable
2441 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002442 Phone phone = getPhoneFromRequest(request);
2443 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002444 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002445 }
2446
Wink Saville36469e72014-06-11 15:17:00 -07002447 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002448 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002449 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451
Kai Shif70f46f2021-03-03 13:59:46 -08002452 private void sendEraseModemConfig(@NonNull Phone phone) {
2453 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2454 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2455 }
2456
2457 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2458 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2459 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002460 }
2461
Peter Wang44b186e2020-01-13 23:33:09 -08002462 private boolean isImsAvailableOnDevice() {
2463 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2464 if (pm == null) {
2465 // For some reason package manger is not available.. This will fail internally anyway,
2466 // so do not throw error and allow.
2467 return true;
2468 }
2469 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2470 }
2471
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002473 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002474 }
2475
Wink Savilleb564aae2014-10-23 10:18:09 -07002476 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 if (DBG) log("dial: " + number);
2478 // No permission check needed here: This is just a wrapper around the
2479 // ACTION_DIAL intent, which is available to any app since it puts up
2480 // the UI before it does anything.
2481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482 final long identity = Binder.clearCallingIdentity();
2483 try {
2484 String url = createTelUrl(number);
2485 if (url == null) {
2486 return;
2487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002489 // PENDING: should we just silently fail if phone is offhook or ringing?
2490 PhoneConstants.State state = mCM.getState(subId);
2491 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2492 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2493 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2494 mApp.startActivity(intent);
2495 }
2496 } finally {
2497 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 }
2499 }
2500
2501 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002502 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002503 }
2504
Wink Savilleb564aae2014-10-23 10:18:09 -07002505 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506 if (DBG) log("call: " + number);
2507
2508 // This is just a wrapper around the ACTION_CALL intent, but we still
2509 // need to do a permission check since we're calling startActivity()
2510 // from the context of the phone app.
2511 enforceCallPermission();
2512
Jordan Liu1617b712019-07-10 15:06:26 -07002513 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002514 != AppOpsManager.MODE_ALLOWED) {
2515 return;
2516 }
2517
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002518 final long identity = Binder.clearCallingIdentity();
2519 try {
2520 String url = createTelUrl(number);
2521 if (url == null) {
2522 return;
2523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002524
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002525 boolean isValid = false;
2526 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2527 if (slist != null) {
2528 for (SubscriptionInfo subInfoRecord : slist) {
2529 if (subInfoRecord.getSubscriptionId() == subId) {
2530 isValid = true;
2531 break;
2532 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002533 }
Wink Saville08874612014-08-31 19:19:58 -07002534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002535 if (!isValid) {
2536 return;
2537 }
Wink Saville08874612014-08-31 19:19:58 -07002538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002539 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2540 intent.putExtra(SUBSCRIPTION_KEY, subId);
2541 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2542 mApp.startActivity(intent);
2543 } finally {
2544 Binder.restoreCallingIdentity(identity);
2545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 }
2547
Wink Savilleb564aae2014-10-23 10:18:09 -07002548 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002549 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002550 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2551 }
2552
Wink Savilleb564aae2014-10-23 10:18:09 -07002553 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002554 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002555 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2556 }
2557
Wink Savilleb564aae2014-10-23 10:18:09 -07002558 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002559 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002560
2561 final long identity = Binder.clearCallingIdentity();
2562 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002563 Phone phone = getPhone(subId);
2564 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565 checkSimPin.start();
2566 return checkSimPin.unlockSim(null, pin);
2567 } finally {
2568 Binder.restoreCallingIdentity(identity);
2569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570 }
2571
Wink Savilleb564aae2014-10-23 10:18:09 -07002572 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574
2575 final long identity = Binder.clearCallingIdentity();
2576 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002577 Phone phone = getPhone(subId);
2578 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002579 checkSimPuk.start();
2580 return checkSimPuk.unlockSim(puk, pin);
2581 } finally {
2582 Binder.restoreCallingIdentity(identity);
2583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002584 }
2585
2586 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002587 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002588 * a synchronous one.
2589 */
2590 private static class UnlockSim extends Thread {
2591
2592 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002593 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594
2595 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002596 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2597 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002598
2599 // For replies from SimCard interface
2600 private Handler mHandler;
2601
2602 // For async handler to identify request type
2603 private static final int SUPPLY_PIN_COMPLETE = 100;
2604
Michele Berionne5e411512020-11-13 02:36:59 +00002605 UnlockSim(int phoneId, IccCard simCard) {
2606 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002607 mSimCard = simCard;
2608 }
2609
2610 @Override
2611 public void run() {
2612 Looper.prepare();
2613 synchronized (UnlockSim.this) {
2614 mHandler = new Handler() {
2615 @Override
2616 public void handleMessage(Message msg) {
2617 AsyncResult ar = (AsyncResult) msg.obj;
2618 switch (msg.what) {
2619 case SUPPLY_PIN_COMPLETE:
2620 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2621 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002622 mRetryCount = msg.arg1;
2623 if (ar.exception != null) {
2624 if (ar.exception instanceof CommandException &&
2625 ((CommandException)(ar.exception)).getCommandError()
2626 == CommandException.Error.PASSWORD_INCORRECT) {
2627 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002628 } //When UiccCardApp dispose,handle message and return exception
2629 else if (ar.exception instanceof CommandException &&
2630 ((CommandException) (ar.exception)).getCommandError()
2631 == CommandException.Error.ABORTED) {
2632 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002633 } else {
2634 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2635 }
2636 } else {
2637 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 mDone = true;
2640 UnlockSim.this.notifyAll();
2641 }
2642 break;
2643 }
2644 }
2645 };
2646 UnlockSim.this.notifyAll();
2647 }
2648 Looper.loop();
2649 }
2650
2651 /*
2652 * Use PIN or PUK to unlock SIM card
2653 *
2654 * If PUK is null, unlock SIM card with PIN
2655 *
2656 * If PUK is not null, unlock SIM card with PUK and set PIN code
2657 */
Wink Saville9de0f752013-10-22 19:04:03 -07002658 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659
2660 while (mHandler == null) {
2661 try {
2662 wait();
2663 } catch (InterruptedException e) {
2664 Thread.currentThread().interrupt();
2665 }
2666 }
2667 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2668
2669 if (puk == null) {
2670 mSimCard.supplyPin(pin, callback);
2671 } else {
2672 mSimCard.supplyPuk(puk, pin, callback);
2673 }
2674
2675 while (!mDone) {
2676 try {
2677 Log.d(LOG_TAG, "wait for done");
2678 wait();
2679 } catch (InterruptedException e) {
2680 // Restore the interrupted status
2681 Thread.currentThread().interrupt();
2682 }
2683 }
2684 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002685 int[] resultArray = new int[2];
2686 resultArray[0] = mResult;
2687 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002688
2689 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002690 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002691 }
2692
Wink Saville9de0f752013-10-22 19:04:03 -07002693 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 }
2695 }
2696
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002697 /**
2698 * This method has been removed due to privacy and stability concerns.
2699 */
2700 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002702 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2703 return;
Wink Saville36469e72014-06-11 15:17:00 -07002704 }
2705
Nathan Harold1f889d82020-06-04 17:05:26 -07002706 @Override
2707 public void updateServiceLocationWithPackageName(String callingPackage) {
2708 mApp.getSystemService(AppOpsManager.class)
2709 .checkPackage(Binder.getCallingUid(), callingPackage);
2710
Nathan Haroldf096d982020-11-18 17:18:06 -08002711 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002712 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2713 // Callers targeting S have no business invoking this method.
2714 return;
2715 }
2716
2717 LocationAccessPolicy.LocationPermissionResult locationResult =
2718 LocationAccessPolicy.checkLocationPermission(mApp,
2719 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2720 .setCallingPackage(callingPackage)
2721 .setCallingFeatureId(null)
2722 .setCallingPid(Binder.getCallingPid())
2723 .setCallingUid(Binder.getCallingUid())
2724 .setMethod("updateServiceLocation")
2725 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2726 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2727 .build());
2728 // Apps that lack location permission have no business calling this method;
2729 // however, because no permission was declared in the public API, denials must
2730 // all be "soft".
2731 switch (locationResult) {
2732 case DENIED_HARD: /* fall through */
2733 case DENIED_SOFT:
2734 return;
2735 }
2736
2737 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738 final long identity = Binder.clearCallingIdentity();
2739 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002740 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002742 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002743 }
2744 } finally {
2745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002747 }
2748
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002749 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002750 @Override
2751 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002752 return isRadioOnWithFeature(callingPackage, null);
2753 }
2754
2755
2756 @Override
2757 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2758 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2759 callingFeatureId);
2760 }
2761
2762 @Deprecated
2763 @Override
2764 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2765 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002766 }
2767
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002768 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002769 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2770 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002771 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002772 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002773 return false;
2774 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002775
2776 final long identity = Binder.clearCallingIdentity();
2777 try {
2778 return isRadioOnForSubscriber(subId);
2779 } finally {
2780 Binder.restoreCallingIdentity(identity);
2781 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002782 }
2783
2784 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 final long identity = Binder.clearCallingIdentity();
2786 try {
2787 final Phone phone = getPhone(subId);
2788 if (phone != null) {
2789 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2790 } else {
2791 return false;
2792 }
2793 } finally {
2794 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 }
2797
2798 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002799 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002800 }
Wink Saville36469e72014-06-11 15:17:00 -07002801
Wink Savilleb564aae2014-10-23 10:18:09 -07002802 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002803 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804
2805 final long identity = Binder.clearCallingIdentity();
2806 try {
2807 final Phone phone = getPhone(subId);
2808 if (phone != null) {
2809 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002813 }
Wink Saville36469e72014-06-11 15:17:00 -07002814 }
2815
2816 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002817 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002818 }
2819
Wink Savilleb564aae2014-10-23 10:18:09 -07002820 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002821 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822
2823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 final Phone phone = getPhone(subId);
2826 if (phone == null) {
2827 return false;
2828 }
2829 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2830 toggleRadioOnOffForSubscriber(subId);
2831 }
2832 return true;
2833 } finally {
2834 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002835 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002836 }
Wink Saville36469e72014-06-11 15:17:00 -07002837
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002838 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002839 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002840 /*
2841 * If any of the Radios are available, it will need to be
2842 * shutdown. So return true if any Radio is available.
2843 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2847 Phone phone = PhoneFactory.getPhone(i);
2848 if (phone != null && phone.isRadioAvailable()) return true;
2849 }
2850 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2851 return false;
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002854 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002855 }
2856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002858 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859 enforceModifyPermission();
2860
2861 final long identity = Binder.clearCallingIdentity();
2862 try {
2863 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2864 logv("Shutting down Phone " + i);
2865 shutdownRadioUsingPhoneId(i);
2866 }
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002869 }
2870 }
2871
2872 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002873 Phone phone = PhoneFactory.getPhone(phoneId);
2874 if (phone != null && phone.isRadioAvailable()) {
2875 phone.shutdownRadio();
2876 }
2877 }
2878
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002879 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002880 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881
2882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2885 if (defaultPhone != null) {
2886 defaultPhone.setRadioPower(turnOn);
2887 return true;
2888 } else {
2889 loge("There's no default phone.");
2890 return false;
2891 }
2892 } finally {
2893 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002894 }
Wink Saville36469e72014-06-11 15:17:00 -07002895 }
2896
Wink Savilleb564aae2014-10-23 10:18:09 -07002897 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002898 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 final Phone phone = getPhone(subId);
2903 if (phone != null) {
2904 phone.setRadioPower(turnOn);
2905 return true;
2906 } else {
2907 return false;
2908 }
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 }
2913
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002914 /**
2915 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2916 * no reason to power it off. When any of the voters want to power it off, it will be turned
2917 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2918 * powering it off, and these radio off votes will be cleared.
2919 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2920 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2921 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2922 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2923 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2924 * check its vote.
2925 *
2926 * @param subId The subscription ID.
2927 * @param reason The reason for powering off radio.
2928 * @return true on success and false on failure.
2929 */
2930 public boolean requestRadioPowerOffForReason(int subId,
2931 @TelephonyManager.RadioPowerReason int reason) {
2932 enforceModifyPermission();
2933
2934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 final Phone phone = getPhone(subId);
2937 if (phone != null) {
2938 phone.setRadioPowerForReason(false, reason);
2939 return true;
2940 } else {
2941 return false;
2942 }
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
2945 }
2946 }
2947
2948 /**
2949 * Remove the vote on powering off the radio for a reason, as requested by
2950 * {@link requestRadioPowerOffForReason}.
2951 *
2952 * @param subId The subscription ID.
2953 * @param reason The reason for powering off radio.
2954 * @return true on success and false on failure.
2955 */
2956 public boolean clearRadioPowerOffForReason(int subId,
2957 @TelephonyManager.RadioPowerReason int reason) {
2958 enforceModifyPermission();
2959
2960 final long identity = Binder.clearCallingIdentity();
2961 try {
2962 final Phone phone = getPhone(subId);
2963 if (phone != null) {
2964 phone.setRadioPowerForReason(true, reason);
2965 return true;
2966 } else {
2967 return false;
2968 }
2969 } finally {
2970 Binder.restoreCallingIdentity(identity);
2971 }
2972 }
2973
2974 /**
2975 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2976 *
2977 * @param subId The subscription ID.
2978 * @param callingPackage The package making the call.
2979 * @param callingFeatureId The feature in the package.
2980 * @return List of reasons for powering off radio.
2981 */
2982 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
2983 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
2984
2985 final long identity = Binder.clearCallingIdentity();
2986 List result = new ArrayList();
2987 try {
2988 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
2989 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
2990 return result;
2991 }
2992
2993 final Phone phone = getPhone(subId);
2994 if (phone != null) {
2995 result.addAll(phone.getRadioPowerOffReasons());
2996 }
2997 } finally {
2998 Binder.restoreCallingIdentity(identity);
2999 }
3000 return result;
3001 }
3002
Wink Saville36469e72014-06-11 15:17:00 -07003003 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003004 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003005 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003006 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003007
3008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 int subId = mSubscriptionController.getDefaultDataSubId();
3011 final Phone phone = getPhone(subId);
3012 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003013 phone.getDataSettingsManager().setDataEnabled(
3014 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 return true;
3016 } else {
3017 return false;
3018 }
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003021 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003022 }
3023
Wink Saville36469e72014-06-11 15:17:00 -07003024 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003025 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003026 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003027 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028
3029 final long identity = Binder.clearCallingIdentity();
3030 try {
3031 int subId = mSubscriptionController.getDefaultDataSubId();
3032 final Phone phone = getPhone(subId);
3033 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003034 phone.getDataSettingsManager().setDataEnabled(
3035 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003036 return true;
3037 } else {
3038 return false;
3039 }
3040 } finally {
3041 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003042 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003043 }
3044
Sanket Padawe356d7632015-06-22 14:03:32 -07003045 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003046 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 final Phone phone = getPhone(subId);
3050 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003051 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003052 } else {
3053 return false;
3054 }
3055 } finally {
3056 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003057 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003058 }
3059
3060 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003061 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003062 }
3063
pkanwarae03a6b2016-11-06 20:37:09 -08003064 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065 enforceCallPermission();
3066
3067 final long identity = Binder.clearCallingIdentity();
3068 try {
3069 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3070 return;
3071 }
3072 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3073 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3074 } finally {
3075 Binder.restoreCallingIdentity(identity);
3076 }
pkanwar32d516d2016-10-14 19:37:38 -07003077 };
3078
Wink Savilleb564aae2014-10-23 10:18:09 -07003079 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003080 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081
3082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3085 return false;
3086 }
3087 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3088 } finally {
3089 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003091 }
3092
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003093 /**
3094 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3095 * tag on getCallState Binder call.
3096 */
3097 @Deprecated
3098 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003099 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003100 if (CompatChanges.isChangeEnabled(
3101 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3102 Binder.getCallingUid())) {
3103 // Do not allow this API to be called on API version 31+, it should only be
3104 // called on old apps using this Binder call directly.
3105 throw new SecurityException("This method can only be used for applications "
3106 + "targeting API version 30 or less.");
3107 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003108 final long identity = Binder.clearCallingIdentity();
3109 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003110 Phone phone = getPhone(getDefaultSubscription());
3111 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3112 PhoneConstantConversions.convertCallState(phone.getState());
3113 } finally {
3114 Binder.restoreCallingIdentity(identity);
3115 }
3116 }
3117
3118 @Override
3119 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3120 if (CompatChanges.isChangeEnabled(
3121 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3122 Binder.getCallingUid())) {
3123 // Check READ_PHONE_STATE for API version 31+
3124 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3125 featureId, "getCallStateForSubscription")) {
3126 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3127 + "targeting API level 31+.");
3128 }
3129 }
3130 final long identity = Binder.clearCallingIdentity();
3131 try {
3132 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003133 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3134 PhoneConstantConversions.convertCallState(phone.getState());
3135 } finally {
3136 Binder.restoreCallingIdentity(identity);
3137 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003138 }
3139
Sanket Padawe356d7632015-06-22 14:03:32 -07003140 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003141 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003142 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3143 }
3144
3145 @Override
3146 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003147 final long identity = Binder.clearCallingIdentity();
3148 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003149 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003151 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152 } else {
3153 return PhoneConstantConversions.convertDataState(
3154 PhoneConstants.DataState.DISCONNECTED);
3155 }
3156 } finally {
3157 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003159 }
3160
Sanket Padawe356d7632015-06-22 14:03:32 -07003161 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003162 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003163 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3164 }
3165
3166 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003167 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003168 final long identity = Binder.clearCallingIdentity();
3169 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003170 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003171 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003172 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003173 } else {
3174 return TelephonyManager.DATA_ACTIVITY_NONE;
3175 }
3176 } finally {
3177 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003178 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003179 }
3180
3181 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003182 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003183 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003184 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003185
3186 LocationAccessPolicy.LocationPermissionResult locationResult =
3187 LocationAccessPolicy.checkLocationPermission(mApp,
3188 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3189 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003190 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003191 .setCallingPid(Binder.getCallingPid())
3192 .setCallingUid(Binder.getCallingUid())
3193 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003194 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003195 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3196 .build());
3197 switch (locationResult) {
3198 case DENIED_HARD:
3199 throw new SecurityException("Not allowed to access cell location");
3200 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003201 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3202 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003203 }
3204
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003205 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206 final long identity = Binder.clearCallingIdentity();
3207 try {
3208 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003209 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003210 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003211 } finally {
3212 Binder.restoreCallingIdentity(identity);
3213 }
Svetoslav64fad262015-04-14 14:35:21 -07003214 }
3215
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003216 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003217 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003218 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3219 // registered cell info, so return a NULL country instead.
3220 final long identity = Binder.clearCallingIdentity();
3221 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003222 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3223 // Get default phone in this case.
3224 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3225 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003226 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003228 if (phone == null) return "";
3229 ServiceStateTracker sst = phone.getServiceStateTracker();
3230 if (sst == null) return "";
3231 LocaleTracker lt = sst.getLocaleTracker();
3232 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003233 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003234 } finally {
3235 Binder.restoreCallingIdentity(identity);
3236 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003237 }
3238
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003239 /**
3240 * This method was removed due to potential issues caused by performing partial
3241 * updates of service state, and lack of a credible use case.
3242 *
3243 * This has the ability to break the telephony implementation by disabling notification of
3244 * changes in device connectivity. DO NOT USE THIS!
3245 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003246 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003247 public void enableLocationUpdates() {
3248 mApp.enforceCallingOrSelfPermission(
3249 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003250 }
3251
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003252 /**
3253 * This method was removed due to potential issues caused by performing partial
3254 * updates of service state, and lack of a credible use case.
3255 *
3256 * This has the ability to break the telephony implementation by disabling notification of
3257 * changes in device connectivity. DO NOT USE THIS!
3258 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003259 @Override
3260 public void disableLocationUpdates() {
3261 mApp.enforceCallingOrSelfPermission(
3262 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003263 }
3264
3265 @Override
3266 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003267 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3268 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003269 try {
3270 mApp.getSystemService(AppOpsManager.class)
3271 .checkPackage(Binder.getCallingUid(), callingPackage);
3272 } catch (SecurityException e) {
3273 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3274 throw e;
3275 }
3276
Nathan Haroldf096d982020-11-18 17:18:06 -08003277 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003278 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3279 throw new SecurityException(
3280 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3281 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003282
Jordan Liu1617b712019-07-10 15:06:26 -07003283 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003284 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3285 return null;
3286 }
Svetoslav64fad262015-04-14 14:35:21 -07003287
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003288 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003289
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003290 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003291 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003292
Nathan Haroldf180aac2018-06-01 18:43:55 -07003293 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3294 for (CellInfo ci : info) {
3295 if (ci instanceof CellInfoGsm) {
3296 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3297 } else if (ci instanceof CellInfoWcdma) {
3298 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003300 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003301 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003302 }
3303
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003304 private List<CellInfo> getCachedCellInfo() {
3305 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3306 for (Phone phone : PhoneFactory.getPhones()) {
3307 List<CellInfo> info = phone.getAllCellInfo();
3308 if (info != null) cellInfos.addAll(info);
3309 }
3310 return cellInfos;
3311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003312
3313 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003314 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003315 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003316 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003317
3318 LocationAccessPolicy.LocationPermissionResult locationResult =
3319 LocationAccessPolicy.checkLocationPermission(mApp,
3320 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3321 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003322 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003323 .setCallingPid(Binder.getCallingPid())
3324 .setCallingUid(Binder.getCallingUid())
3325 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003326 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003327 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3328 .build());
3329 switch (locationResult) {
3330 case DENIED_HARD:
3331 throw new SecurityException("Not allowed to access cell info");
3332 case DENIED_SOFT:
3333 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003334 }
3335
Nathan Haroldf096d982020-11-18 17:18:06 -08003336 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003337 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3338 return getCachedCellInfo();
3339 }
3340
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003341 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003342 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3346 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003347 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003348 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003349 if (info != null) cellInfos.addAll(info);
3350 }
3351 return cellInfos;
3352 } finally {
3353 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003354 }
3355 }
3356
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003357 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003358 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3359 String callingFeatureId) {
3360 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3361 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003362 }
3363
3364 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003365 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3366 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003367 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003368 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003369 }
3370
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003371 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3372 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003373 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003374 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003375
3376 LocationAccessPolicy.LocationPermissionResult locationResult =
3377 LocationAccessPolicy.checkLocationPermission(mApp,
3378 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3379 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003380 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003381 .setCallingPid(Binder.getCallingPid())
3382 .setCallingUid(Binder.getCallingUid())
3383 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003384 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3385 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003386 .build());
3387 switch (locationResult) {
3388 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003389 if (TelephonyPermissions
3390 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003391 // Safetynet logging for b/154934934
3392 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3393 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003394 throw new SecurityException("Not allowed to access cell info");
3395 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003396 if (TelephonyPermissions
3397 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003398 // Safetynet logging for b/154934934
3399 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3400 }
Nathan Harold5320c422019-05-09 10:26:08 -07003401 try {
3402 cb.onCellInfo(new ArrayList<CellInfo>());
3403 } catch (RemoteException re) {
3404 // Drop without consequences
3405 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003406 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003407 }
3408
Nathan Harolda939a962019-05-09 10:13:47 -07003409
3410 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003411 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3412
3413 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3414 }
3415
3416 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003417 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003418 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003419 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420
3421 final long identity = Binder.clearCallingIdentity();
3422 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003423 Phone phone = getPhone(subId);
3424 if (phone == null) {
3425 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3426 } else {
3427 phone.setCellInfoListRate(rateInMillis, workSource);
3428 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 } finally {
3430 Binder.restoreCallingIdentity(identity);
3431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003432 }
3433
Shishir Agrawala9f32182016-04-12 12:00:16 -07003434 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003435 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003436 Phone phone = PhoneFactory.getPhone(slotIndex);
3437 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003438 return null;
3439 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003440 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003441 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003442 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003443 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003444 return null;
3445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003446
3447 final long identity = Binder.clearCallingIdentity();
3448 try {
3449 return phone.getImei();
3450 } finally {
3451 Binder.restoreCallingIdentity(identity);
3452 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003453 }
3454
3455 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003456 public String getTypeAllocationCodeForSlot(int slotIndex) {
3457 Phone phone = PhoneFactory.getPhone(slotIndex);
3458 String tac = null;
3459 if (phone != null) {
3460 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003461 try {
3462 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3463 } catch (IndexOutOfBoundsException e) {
3464 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3465 return null;
3466 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003467 }
3468 return tac;
3469 }
3470
3471 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003472 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003473 try {
3474 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3475 } catch (SecurityException se) {
3476 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3477 throw new SecurityException("Package " + callingPackage + " does not belong to "
3478 + Binder.getCallingUid());
3479 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003480 Phone phone = PhoneFactory.getPhone(slotIndex);
3481 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003482 return null;
3483 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003484
Jeff Davidson913390f2018-02-23 17:11:49 -08003485 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003486 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003487 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003488 return null;
3489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003490
3491 final long identity = Binder.clearCallingIdentity();
3492 try {
3493 return phone.getMeid();
3494 } finally {
3495 Binder.restoreCallingIdentity(identity);
3496 }
Jack Yu2af8d712017-03-15 17:14:14 -07003497 }
3498
3499 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003500 public String getManufacturerCodeForSlot(int slotIndex) {
3501 Phone phone = PhoneFactory.getPhone(slotIndex);
3502 String manufacturerCode = null;
3503 if (phone != null) {
3504 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003505 try {
3506 manufacturerCode =
3507 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3508 } catch (IndexOutOfBoundsException e) {
3509 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3510 return null;
3511 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003512 }
3513 return manufacturerCode;
3514 }
3515
3516 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003517 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3518 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003519 Phone phone = PhoneFactory.getPhone(slotIndex);
3520 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003521 return null;
3522 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003523 int subId = phone.getSubId();
3524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003525 mApp, subId, callingPackage, callingFeatureId,
3526 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003527 return null;
3528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529
3530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 return phone.getDeviceSvn();
3533 } finally {
3534 Binder.restoreCallingIdentity(identity);
3535 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003536 }
3537
fionaxu43304da2017-11-27 22:51:16 -08003538 @Override
3539 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540 final long identity = Binder.clearCallingIdentity();
3541 try {
3542 final Phone phone = getPhone(subId);
3543 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
3546 }
fionaxu43304da2017-11-27 22:51:16 -08003547 }
3548
3549 @Override
3550 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 final Phone phone = getPhone(subId);
3554 return phone == null ? null : phone.getCarrierName();
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
fionaxu43304da2017-11-27 22:51:16 -08003558 }
3559
calvinpanffe225e2018-11-01 19:43:06 +08003560 @Override
chen xu0026ca62019-03-06 15:28:50 -08003561 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 final Phone phone = getPhone(subId);
3565 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003566 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003567 } finally {
3568 Binder.restoreCallingIdentity(identity);
3569 }
3570 }
3571
3572 @Override
chen xu0026ca62019-03-06 15:28:50 -08003573 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003577 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003578 } finally {
3579 Binder.restoreCallingIdentity(identity);
3580 }
3581 }
3582
chen xu651eec72018-11-11 19:03:44 -08003583 @Override
chen xu864e11c2018-12-06 22:10:03 -08003584 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3585 if (!isSubscriptionMccMnc) {
3586 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3587 }
chen xu651eec72018-11-11 19:03:44 -08003588 final Phone phone = PhoneFactory.getPhone(slotIndex);
3589 if (phone == null) {
3590 return TelephonyManager.UNKNOWN_CARRIER_ID;
3591 }
3592 final long identity = Binder.clearCallingIdentity();
3593 try {
3594 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3595 } finally {
3596 Binder.restoreCallingIdentity(identity);
3597 }
3598 }
3599
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003600 //
3601 // Internal helper methods.
3602 //
3603
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003604 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003605 * Make sure the caller is the calling package itself
3606 *
3607 * @throws SecurityException if the caller is not the calling package
3608 */
3609 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3610 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003611 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3612 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003613 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003614 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003615 } catch (PackageManager.NameNotFoundException e) {
3616 // packageUid is -1
3617 }
3618 if (packageUid != callingUid) {
3619 throw new SecurityException(message + ": Package " + callingPackage
3620 + " does not belong to " + callingUid);
3621 }
3622 }
3623
3624 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003625 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3626 *
3627 * @throws SecurityException if the caller does not have the required permission
3628 */
3629 private void enforceModifyPermission() {
3630 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3631 }
3632
Shuo Qian3b6ee772019-11-13 17:43:31 -08003633 private void enforceActiveEmergencySessionPermission() {
3634 mApp.enforceCallingOrSelfPermission(
3635 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3636 }
3637
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003638 /**
3639 * Make sure the caller has the CALL_PHONE permission.
3640 *
3641 * @throws SecurityException if the caller does not have the required permission
3642 */
3643 private void enforceCallPermission() {
3644 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3645 }
3646
paulhu5a773602019-08-23 19:17:33 +08003647 private void enforceSettingsPermission() {
3648 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003649 }
3650
Michele Berionne5e411512020-11-13 02:36:59 +00003651 private void enforceRebootPermission() {
3652 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3653 }
3654
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003655 private String createTelUrl(String number) {
3656 if (TextUtils.isEmpty(number)) {
3657 return null;
3658 }
3659
Jake Hambye994d462014-02-03 13:10:13 -08003660 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003661 }
3662
Ihab Awadf9e92732013-12-05 18:02:52 -08003663 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003664 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3665 }
3666
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003667 private static void logv(String msg) {
3668 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3669 }
3670
Ihab Awadf9e92732013-12-05 18:02:52 -08003671 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003672 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3673 }
3674
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003675 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003676 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003677 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003678 }
3679
Sanket Padawe356d7632015-06-22 14:03:32 -07003680 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003681 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003682 final long identity = Binder.clearCallingIdentity();
3683 try {
3684 final Phone phone = PhoneFactory.getPhone(slotIndex);
3685 if (phone == null) {
3686 return PhoneConstants.PHONE_TYPE_NONE;
3687 } else {
3688 return phone.getPhoneType();
3689 }
3690 } finally {
3691 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003693 }
3694
3695 /**
3696 * Returns the CDMA ERI icon index to display
3697 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003698 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003699 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3700 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3701 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003702 }
3703
Sanket Padawe356d7632015-06-22 14:03:32 -07003704 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003705 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3706 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003707 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003708 mApp, subId, callingPackage, callingFeatureId,
3709 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003710 return -1;
3711 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003712
3713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 final Phone phone = getPhone(subId);
3716 if (phone != null) {
3717 return phone.getCdmaEriIconIndex();
3718 } else {
3719 return -1;
3720 }
3721 } finally {
3722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003724 }
3725
3726 /**
3727 * Returns the CDMA ERI icon mode,
3728 * 0 - ON
3729 * 1 - FLASHING
3730 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003731 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003732 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3733 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3734 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003735 }
3736
Sanket Padawe356d7632015-06-22 14:03:32 -07003737 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003738 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3739 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003740 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003741 mApp, subId, callingPackage, callingFeatureId,
3742 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003743 return -1;
3744 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003745
3746 final long identity = Binder.clearCallingIdentity();
3747 try {
3748 final Phone phone = getPhone(subId);
3749 if (phone != null) {
3750 return phone.getCdmaEriIconMode();
3751 } else {
3752 return -1;
3753 }
3754 } finally {
3755 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003757 }
3758
3759 /**
3760 * Returns the CDMA ERI text,
3761 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003763 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3764 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3765 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003766 }
3767
Sanket Padawe356d7632015-06-22 14:03:32 -07003768 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003769 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3770 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003771 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003772 mApp, subId, callingPackage, callingFeatureId,
3773 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003774 return null;
3775 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003776
3777 final long identity = Binder.clearCallingIdentity();
3778 try {
3779 final Phone phone = getPhone(subId);
3780 if (phone != null) {
3781 return phone.getCdmaEriText();
3782 } else {
3783 return null;
3784 }
3785 } finally {
3786 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003788 }
3789
3790 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003791 * Returns the CDMA MDN.
3792 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003793 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003794 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3796 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797
3798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003801 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003802 return phone.getLine1Number();
3803 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003804 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805 return null;
3806 }
3807 } finally {
3808 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003809 }
3810 }
3811
3812 /**
3813 * Returns the CDMA MIN.
3814 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003815 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003816 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3818 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003819
3820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 final Phone phone = getPhone(subId);
3823 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3824 return phone.getCdmaMin();
3825 } else {
3826 return null;
3827 }
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003830 }
3831 }
3832
Hall Liud892bec2018-11-30 14:51:45 -08003833 @Override
3834 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3835 INumberVerificationCallback callback, String callingPackage) {
3836 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3837 != PERMISSION_GRANTED) {
3838 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3839 }
3840 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3841
3842 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3843 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003844 throw new SecurityException("Calling package must be configured in the device config: "
3845 + "calling package: " + callingPackage
3846 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003847 }
3848
3849 if (range == null) {
3850 throw new NullPointerException("Range must be non-null");
3851 }
3852
3853 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003854 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003855
3856 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3857 }
3858
Junda Liuca05d5d2014-08-14 22:36:34 -07003859 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003860 * Returns true if CDMA provisioning needs to run.
3861 */
3862 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003863 final long identity = Binder.clearCallingIdentity();
3864 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003865 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003866 } finally {
3867 Binder.restoreCallingIdentity(identity);
3868 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003869 }
3870
3871 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003872 * Sets the voice mail number of a given subId.
3873 */
3874 @Override
3875 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003876 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3877 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003878
3879 final long identity = Binder.clearCallingIdentity();
3880 try {
3881 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3882 new Pair<String, String>(alphaTag, number), new Integer(subId));
3883 return success;
3884 } finally {
3885 Binder.restoreCallingIdentity(identity);
3886 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003887 }
3888
Ta-wei Yen87c49842016-05-13 21:19:52 -07003889 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003890 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3891 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003892 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3893 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003894 if (!TextUtils.equals(callingPackage, systemDialer)) {
3895 throw new SecurityException("caller must be system dialer");
3896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897
3898 final long identity = Binder.clearCallingIdentity();
3899 try {
3900 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3901 if (phoneAccountHandle == null) {
3902 return null;
3903 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003904 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003905 } finally {
3906 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003907 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003908 }
3909
3910 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003911 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3912 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003913 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003914 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003915 mApp, subId, callingPackage, callingFeatureId,
3916 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003917 return null;
3918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003919
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003920 final long identity = Binder.clearCallingIdentity();
3921 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003922 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003923 } finally {
3924 Binder.restoreCallingIdentity(identity);
3925 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003926 }
3927
3928 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003929 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3930 VisualVoicemailSmsFilterSettings settings) {
3931 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003932
3933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003936 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003937 } finally {
3938 Binder.restoreCallingIdentity(identity);
3939 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003940 }
3941
3942 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003943 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3944 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003945
3946 final long identity = Binder.clearCallingIdentity();
3947 try {
3948 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003949 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003950 } finally {
3951 Binder.restoreCallingIdentity(identity);
3952 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003953 }
3954
3955 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003956 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3957 String callingPackage, int subId) {
3958 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003959
3960 final long identity = Binder.clearCallingIdentity();
3961 try {
3962 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003963 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003964 } finally {
3965 Binder.restoreCallingIdentity(identity);
3966 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003967 }
3968
3969 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003970 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003971 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003972
3973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003976 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003977 } finally {
3978 Binder.restoreCallingIdentity(identity);
3979 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003980 }
3981
3982 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003983 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3984 String callingAttributionTag, int subId, String number, int port, String text,
3985 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003986 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003987 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003988 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003989 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003990 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3991 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003992 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003993
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003994 /**
fionaxu0152e512016-11-14 13:36:14 -08003995 * Sets the voice activation state of a given subId.
3996 */
3997 @Override
3998 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4000 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004001
4002 final long identity = Binder.clearCallingIdentity();
4003 try {
4004 final Phone phone = getPhone(subId);
4005 if (phone != null) {
4006 phone.setVoiceActivationState(activationState);
4007 } else {
4008 loge("setVoiceActivationState fails with invalid subId: " + subId);
4009 }
4010 } finally {
4011 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004012 }
4013 }
4014
4015 /**
4016 * Sets the data activation state of a given subId.
4017 */
4018 @Override
4019 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004020 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4021 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004022
4023 final long identity = Binder.clearCallingIdentity();
4024 try {
4025 final Phone phone = getPhone(subId);
4026 if (phone != null) {
4027 phone.setDataActivationState(activationState);
4028 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004029 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004030 }
4031 } finally {
4032 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004033 }
4034 }
4035
4036 /**
4037 * Returns the voice activation state of a given subId.
4038 */
4039 @Override
4040 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042
fionaxu0152e512016-11-14 13:36:14 -08004043 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004044 final long identity = Binder.clearCallingIdentity();
4045 try {
4046 if (phone != null) {
4047 return phone.getVoiceActivationState();
4048 } else {
4049 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4050 }
4051 } finally {
4052 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004053 }
4054 }
4055
4056 /**
4057 * Returns the data activation state of a given subId.
4058 */
4059 @Override
4060 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004061 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004062
fionaxu0152e512016-11-14 13:36:14 -08004063 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004064 final long identity = Binder.clearCallingIdentity();
4065 try {
4066 if (phone != null) {
4067 return phone.getDataActivationState();
4068 } else {
4069 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4070 }
4071 } finally {
4072 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004073 }
4074 }
4075
4076 /**
Wink Saville36469e72014-06-11 15:17:00 -07004077 * Returns the unread count of voicemails for a subId
4078 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004079 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004080 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4081 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004082 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004083 mApp, subId, callingPackage, callingFeatureId,
4084 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004085 return 0;
4086 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087 final long identity = Binder.clearCallingIdentity();
4088 try {
4089 final Phone phone = getPhone(subId);
4090 if (phone != null) {
4091 return phone.getVoiceMessageCount();
4092 } else {
4093 return 0;
4094 }
4095 } finally {
4096 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004097 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004098 }
4099
4100 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004101 * returns true, if the device is in a state where both voice and data
4102 * are supported simultaneously. This can change based on location or network condition.
4103 */
4104 @Override
4105 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004106 final long identity = Binder.clearCallingIdentity();
4107 try {
4108 final Phone phone = getPhone(subId);
4109 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4110 } finally {
4111 Binder.restoreCallingIdentity(identity);
4112 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004113 }
4114
4115 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004116 * Send the dialer code if called from the current default dialer or the caller has
4117 * carrier privilege.
4118 * @param inputCode The dialer code to send
4119 */
4120 @Override
4121 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004122 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004123 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004124 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4125 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004126 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004127 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004128 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004129 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004130
4131 final long identity = Binder.clearCallingIdentity();
4132 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004133 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004134 } finally {
4135 Binder.restoreCallingIdentity(identity);
4136 }
fionaxu235cc5e2017-03-06 22:25:57 -08004137 }
4138
Pengquan Menga1bb6272018-09-06 09:59:22 -07004139 @Override
4140 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004141 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004142 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004143 mApp, subId, "getNetworkSelectionMode");
4144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 if (!isActiveSubscription(subId)) {
4147 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4148 }
4149 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4150 } finally {
4151 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004152 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004153 }
4154
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004156 public boolean isInEmergencySmsMode() {
4157 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4158 final long identity = Binder.clearCallingIdentity();
4159 try {
4160 for (Phone phone : PhoneFactory.getPhones()) {
4161 if (phone.isInEmergencySmsMode()) {
4162 return true;
4163 }
4164 }
4165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
4168 return false;
4169 }
4170
shilu366312e2019-12-17 09:28:10 -08004171 /**
4172 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4173 * @param subId The subscription to use to check the configuration.
4174 * @param c The callback that will be used to send the result.
4175 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004176 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004177 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4178 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004179 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004180 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004181
4182 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4183 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4184 "IMS not available on device.");
4185 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004186 final long token = Binder.clearCallingIdentity();
4187 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004188 int slotId = getSlotIndexOrException(subId);
4189 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004190
4191 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4192 if (controller != null) {
4193 ImsManager imsManager = controller.getImsManager(subId);
4194 if (imsManager != null) {
4195 imsManager.addRegistrationCallbackForSubscription(c, subId);
4196 } else {
4197 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4198 }
4199 } else {
4200 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4201 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004202 } catch (ImsException e) {
4203 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004204 } finally {
4205 Binder.restoreCallingIdentity(token);
4206 }
4207 }
4208
shilu366312e2019-12-17 09:28:10 -08004209 /**
4210 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4211 * @param subId The subscription to use to check the configuration.
4212 * @param c The callback that will be used to send the result.
4213 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004215 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004216 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004217 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004218 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4219 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4220 }
Meng Wangafbc5852019-09-19 17:37:13 -07004221 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004222
Meng Wangafbc5852019-09-19 17:37:13 -07004223 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004224 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4225 if (controller != null) {
4226 ImsManager imsManager = controller.getImsManager(subId);
4227 if (imsManager != null) {
4228 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4229 } else {
4230 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4231 + "is inactive, ignoring unregister.");
4232 // If the ImsManager is not valid, just return, since the callback
4233 // will already have been removed internally.
4234 }
4235 }
Meng Wangafbc5852019-09-19 17:37:13 -07004236 } finally {
4237 Binder.restoreCallingIdentity(token);
4238 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004239 }
4240
Brad Ebingera34a6c22019-10-22 17:36:18 -07004241 /**
4242 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4243 */
4244 @Override
4245 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4246 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4247 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4248 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4249 "IMS not available on device.");
4250 }
4251 final long token = Binder.clearCallingIdentity();
4252 try {
4253 Phone phone = getPhone(subId);
4254 if (phone == null) {
4255 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4256 + subId + "'");
4257 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4258 }
4259 phone.getImsRegistrationState(regState -> {
4260 try {
4261 consumer.accept((regState == null)
4262 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4263 } catch (RemoteException e) {
4264 // Ignore if the remote process is no longer available to call back.
4265 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4266 }
4267 });
4268 } finally {
4269 Binder.restoreCallingIdentity(token);
4270 }
4271 }
4272
4273 /**
4274 * Get the transport type for the IMS service registration state.
4275 */
4276 @Override
4277 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004278 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004279 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004280 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4281 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4282 "IMS not available on device.");
4283 }
4284 final long token = Binder.clearCallingIdentity();
4285 try {
4286 Phone phone = getPhone(subId);
4287 if (phone == null) {
4288 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4289 + subId + "'");
4290 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4291 }
4292 phone.getImsRegistrationTech(regTech -> {
4293 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4294 int regTechConverted = (regTech == null)
4295 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4296 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4297 regTechConverted);
4298 try {
4299 consumer.accept(regTechConverted);
4300 } catch (RemoteException e) {
4301 // Ignore if the remote process is no longer available to call back.
4302 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4303 }
4304 });
4305 } finally {
4306 Binder.restoreCallingIdentity(token);
4307 }
4308 }
4309
shilu366312e2019-12-17 09:28:10 -08004310 /**
4311 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4312 * @param subId The subscription to use to check the configuration.
4313 * @param c The callback that will be used to send the result.
4314 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004315 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004316 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4317 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004318 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004319 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004320 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4321 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4322 "IMS not available on device.");
4323 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004324 final long token = Binder.clearCallingIdentity();
4325 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004326 int slotId = getSlotIndexOrException(subId);
4327 verifyImsMmTelConfiguredOrThrow(slotId);
4328 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004329 } catch (ImsException e) {
4330 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004331 } finally {
4332 Binder.restoreCallingIdentity(token);
4333 }
4334 }
4335
shilu366312e2019-12-17 09:28:10 -08004336 /**
4337 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4338 * @param subId The subscription to use to check the configuration.
4339 * @param c The callback that will be used to send the result.
4340 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004341 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004342 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004343 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004344 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004345 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4346 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4347 }
Meng Wangafbc5852019-09-19 17:37:13 -07004348
4349 final long token = Binder.clearCallingIdentity();
4350 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004351 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004352 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004353 } catch (ImsException e) {
4354 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4355 + "is inactive, ignoring unregister.");
4356 // If the subscription is no longer active, just return, since the callback
4357 // will already have been removed internally.
4358 } finally {
4359 Binder.restoreCallingIdentity(token);
4360 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004361 }
4362
4363 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004364 public boolean isCapable(int subId, int capability, int regTech) {
4365 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004366 final long token = Binder.clearCallingIdentity();
4367 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004368 int slotId = getSlotIndexOrException(subId);
4369 verifyImsMmTelConfiguredOrThrow(slotId);
4370 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4371 } catch (com.android.ims.ImsException e) {
4372 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4373 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004374 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004375 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4376 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004377 } finally {
4378 Binder.restoreCallingIdentity(token);
4379 }
4380 }
4381
4382 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004383 public boolean isAvailable(int subId, int capability, int regTech) {
4384 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004385 final long token = Binder.clearCallingIdentity();
4386 try {
4387 Phone phone = getPhone(subId);
4388 if (phone == null) return false;
4389 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004390 } catch (com.android.ims.ImsException e) {
4391 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4392 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004393 } finally {
4394 Binder.restoreCallingIdentity(token);
4395 }
4396 }
4397
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004398 /**
4399 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4400 * subscription.
4401 * @param subId The subscription to use to check the configuration.
4402 * @param callback The callback that will be used to send the result.
4403 * @param capability The MmTelFeature capability that will be used to send the result.
4404 * @param transportType The transport type of the MmTelFeature capability.
4405 */
4406 @Override
4407 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4408 int transportType) {
4409 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004410 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4411 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4412 "IMS not available on device.");
4413 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004414 final long token = Binder.clearCallingIdentity();
4415 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004416 int slotId = getSlotIndex(subId);
4417 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4418 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4419 + subId + "'");
4420 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4421 }
4422 verifyImsMmTelConfiguredOrThrow(slotId);
4423 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4424 transportType, aBoolean -> {
4425 try {
4426 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4427 } catch (RemoteException e) {
4428 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4429 + "running. Ignore");
4430 }
4431 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004432 } catch (ImsException e) {
4433 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004434 } finally {
4435 Binder.restoreCallingIdentity(token);
4436 }
4437 }
4438
shilu366312e2019-12-17 09:28:10 -08004439 /**
4440 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4441 * @param subId The subscription to use to check the configuration.
4442 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004443 @Override
4444 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004445 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004446 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004447
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 final long token = Binder.clearCallingIdentity();
4449 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004450 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004451 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004452 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004453 } catch (ImsException e) {
4454 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004455 } finally {
4456 Binder.restoreCallingIdentity(token);
4457 }
4458 }
4459
4460 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004461 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004463 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004464 final long identity = Binder.clearCallingIdentity();
4465 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004466 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004467 // This setting doesn't require an active ImsService connection, so do not verify. The
4468 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004469 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004470 } catch (ImsException e) {
4471 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004472 } finally {
4473 Binder.restoreCallingIdentity(identity);
4474 }
4475 }
4476
shilu366312e2019-12-17 09:28:10 -08004477 /**
4478 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4479 * @param subId The subscription to use to check the configuration.
4480 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004481 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004482 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004483 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004484 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004485 final long identity = Binder.clearCallingIdentity();
4486 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004487 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004488 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004489 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004490 } catch (ImsException e) {
4491 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 } finally {
4493 Binder.restoreCallingIdentity(identity);
4494 }
4495 }
4496
4497 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004498 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004499 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004500 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004501 final long identity = Binder.clearCallingIdentity();
4502 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004503 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004504 // This setting doesn't require an active ImsService connection, so do not verify. The
4505 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004506 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004507 } catch (ImsException e) {
4508 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004509 } finally {
4510 Binder.restoreCallingIdentity(identity);
4511 }
4512 }
4513
shilu366312e2019-12-17 09:28:10 -08004514 /**
4515 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4516 * @param subId The subscription to use to check the configuration.
4517 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004518 @Override
4519 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004520 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004521 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004522 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.
Brad Ebinger919631e2021-06-02 17:46:35 -07004526 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004527 } catch (ImsException e) {
4528 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004529 } finally {
4530 Binder.restoreCallingIdentity(identity);
4531 }
4532 }
4533
4534 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004535 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004537 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004538 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. The
4542 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004543 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004544 } catch (ImsException e) {
4545 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004546 } finally {
4547 Binder.restoreCallingIdentity(identity);
4548 }
4549 }
4550
shilu366312e2019-12-17 09:28:10 -08004551 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004552 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4553 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4554 * @param subId The subscription to use to check the configuration.
4555 */
4556 @Override
4557 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004558 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004559 mApp, subId, "isCrossSimCallingEnabledByUser");
4560 final long identity = Binder.clearCallingIdentity();
4561 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004562 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004563 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004564 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004565 } catch (ImsException e) {
4566 throw new ServiceSpecificException(e.getCode());
4567 } finally {
4568 Binder.restoreCallingIdentity(identity);
4569 }
4570 }
4571
4572 /**
4573 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4574 * Requires MODIFY_PHONE_STATE permission.
4575 * @param subId The subscription to use to check the configuration.
4576 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4577 * false otherwise
4578 */
4579 @Override
4580 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4582 "setCrossSimCallingEnabled");
4583 final long identity = Binder.clearCallingIdentity();
4584 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004585 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004586 // This setting doesn't require an active ImsService connection, so do not verify. The
4587 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004588 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004589 } catch (ImsException e) {
4590 throw new ServiceSpecificException(e.getCode());
4591 } finally {
4592 Binder.restoreCallingIdentity(identity);
4593 }
4594 }
4595
4596 /**
shilu366312e2019-12-17 09:28:10 -08004597 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4598 * @param subId The subscription to use to check the configuration.
4599 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004600 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004601
Brad Ebinger35c841c2018-10-01 10:40:55 -07004602 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004603 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004604 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004605 final long identity = Binder.clearCallingIdentity();
4606 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004607 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004608 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004609 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004610 } catch (ImsException e) {
4611 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004612 } finally {
4613 Binder.restoreCallingIdentity(identity);
4614 }
4615 }
4616
4617 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004618 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004620 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004621 final long identity = Binder.clearCallingIdentity();
4622 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004623 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004624 // This setting doesn't require an active ImsService connection, so do not verify. The
4625 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004626 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004627 } catch (ImsException e) {
4628 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004629 } finally {
4630 Binder.restoreCallingIdentity(identity);
4631 }
4632 }
4633
4634 @Override
4635 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4637 "setVoWiFiNonPersistent");
4638 final long identity = Binder.clearCallingIdentity();
4639 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004640 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004641 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004642 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004643 } catch (ImsException e) {
4644 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004645 } finally {
4646 Binder.restoreCallingIdentity(identity);
4647 }
4648 }
4649
shilu366312e2019-12-17 09:28:10 -08004650 /**
4651 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4652 * @param subId The subscription to use to check the configuration.
4653 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004654 @Override
4655 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004656 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004657 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004658 final long identity = Binder.clearCallingIdentity();
4659 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004660 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004661 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004662 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004663 } catch (ImsException e) {
4664 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004665 } finally {
4666 Binder.restoreCallingIdentity(identity);
4667 }
4668 }
4669
4670 @Override
4671 public void setVoWiFiModeSetting(int subId, int mode) {
4672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4673 "setVoWiFiModeSetting");
4674 final long identity = Binder.clearCallingIdentity();
4675 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004676 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004677 // This setting doesn't require an active ImsService connection, so do not verify. The
4678 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004679 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004680 } catch (ImsException e) {
4681 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004682 } finally {
4683 Binder.restoreCallingIdentity(identity);
4684 }
4685 }
4686
4687 @Override
4688 public int getVoWiFiRoamingModeSetting(int subId) {
4689 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4690 final long identity = Binder.clearCallingIdentity();
4691 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004692 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004693 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004694 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004695 } catch (ImsException e) {
4696 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004697 } finally {
4698 Binder.restoreCallingIdentity(identity);
4699 }
4700 }
4701
4702 @Override
4703 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4705 "setVoWiFiRoamingModeSetting");
4706 final long identity = Binder.clearCallingIdentity();
4707 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004708 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004709 // This setting doesn't require an active ImsService connection, so do not verify. The
4710 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004711 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004712 } catch (ImsException e) {
4713 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004714 } finally {
4715 Binder.restoreCallingIdentity(identity);
4716 }
4717 }
4718
4719 @Override
4720 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4722 "setRttCapabilityEnabled");
4723 final long identity = Binder.clearCallingIdentity();
4724 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004725 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004726 // This setting doesn't require an active ImsService connection, so do not verify. The
4727 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004728 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004729 } catch (ImsException e) {
4730 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004731 } finally {
4732 Binder.restoreCallingIdentity(identity);
4733 }
4734 }
4735
shilu366312e2019-12-17 09:28:10 -08004736 /**
4737 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4738 * @param subId The subscription to use to check the configuration.
4739 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004740 @Override
4741 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004742 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004743 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004744 final long identity = Binder.clearCallingIdentity();
4745 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004746 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004747 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004748 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004749 } catch (ImsException e) {
4750 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004751 } finally {
4752 Binder.restoreCallingIdentity(identity);
4753 }
4754 }
4755
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004756 @Override
4757 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4758 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004759
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004760 final long identity = Binder.clearCallingIdentity();
4761 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004762 if (!isImsAvailableOnDevice()) {
4763 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4764 "IMS not available on device.");
4765 }
4766 int slotId = getSlotIndexOrException(subId);
4767 verifyImsMmTelConfiguredOrThrow(slotId);
4768 ImsManager.getInstance(mApp, slotId)
4769 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004770 } catch (ImsException e) {
4771 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004772 } finally {
4773 Binder.restoreCallingIdentity(identity);
4774 }
4775 }
4776
4777 @Override
4778 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4779 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004780
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004781 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004782 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4783 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4784 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004785 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004786 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004787 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004788 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004789 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4790 + "is inactive, ignoring unregister.");
4791 // If the subscription is no longer active, just return, since the callback will already
4792 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004793 } finally {
4794 Binder.restoreCallingIdentity(identity);
4795 }
4796 }
4797
joonhunshincffb7fc2021-11-28 07:32:01 +00004798 @Override
4799 public void registerFeatureProvisioningChangedCallback(int subId,
4800 IFeatureProvisioningCallback callback) {
4801 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4802 mApp, subId, "registerFeatureProvisioningChangedCallback");
4803
4804 final long identity = Binder.clearCallingIdentity();
4805 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4806 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4807 }
4808
joonhunshin91bc1952022-04-29 08:47:15 +00004809 try {
4810 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4811 if (controller == null) {
4812 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4813 "Device does not support IMS");
4814 }
4815 controller.addFeatureProvisioningChangedCallback(subId, callback);
4816 } finally {
4817 Binder.restoreCallingIdentity(identity);
4818 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004819 }
4820
4821 @Override
4822 public void unregisterFeatureProvisioningChangedCallback(int subId,
4823 IFeatureProvisioningCallback callback) {
4824 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4825 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4826
4827 final long identity = Binder.clearCallingIdentity();
4828 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4829 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4830 }
4831
joonhunshin91bc1952022-04-29 08:47:15 +00004832 try {
4833 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4834 if (controller == null) {
4835 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4836 return;
4837 }
4838 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4839 } finally {
4840 Binder.restoreCallingIdentity(identity);
4841 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004842 }
allenwtsu99c623b2020-01-03 18:24:23 +08004843
4844 private void checkModifyPhoneStatePermission(int subId, String message) {
4845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4846 message);
4847 }
4848
allenwtsu99c623b2020-01-03 18:24:23 +08004849 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004850 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004851 boolean isProvisioned) {
4852 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4853
4854 final long identity = Binder.clearCallingIdentity();
4855 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004856 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4857 if (controller == null) {
4858 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4859 return;
4860 }
4861 controller.setRcsProvisioningStatusForCapability(
4862 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004863 } finally {
4864 Binder.restoreCallingIdentity(identity);
4865 }
allenwtsu99c623b2020-01-03 18:24:23 +08004866 }
4867
4868
4869 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004870 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4871 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4872 mApp, subId, "getRcsProvisioningStatusForCapability");
4873
allenwtsu99c623b2020-01-03 18:24:23 +08004874 final long identity = Binder.clearCallingIdentity();
4875 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004876 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4877 if (controller == null) {
4878 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4879
4880 // device does not support IMS, this method will return true always.
4881 return true;
4882 }
4883 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004884 } finally {
4885 Binder.restoreCallingIdentity(identity);
4886 }
4887 }
4888
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004889 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004890 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4891 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004892 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004893
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004894 final long identity = Binder.clearCallingIdentity();
4895 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004896 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4897 if (controller == null) {
4898 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4899 return;
4900 }
4901 controller.setImsProvisioningStatusForCapability(
4902 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
4906 }
4907
4908 @Override
4909 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004910 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4911 mApp, subId, "getProvisioningStatusForCapability");
4912
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004913 final long identity = Binder.clearCallingIdentity();
4914 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004915 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4916 if (controller == null) {
4917 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004918
joonhunshin91bc1952022-04-29 08:47:15 +00004919 // device does not support IMS, this method will return true always.
4920 return true;
4921 }
4922 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004923 } finally {
4924 Binder.restoreCallingIdentity(identity);
4925 }
4926 }
4927
4928 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004929 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4930 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4931 mApp, subId, "isProvisioningRequiredForCapability");
4932
4933 final long identity = Binder.clearCallingIdentity();
4934 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004935 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4936 if (controller == null) {
4937 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4938
4939 // device does not support IMS, this method will return false
4940 return false;
4941 }
4942 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004943 } finally {
4944 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004945 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004946 }
4947
4948 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004949 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4950 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4951 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004952
joonhunshincffb7fc2021-11-28 07:32:01 +00004953 final long identity = Binder.clearCallingIdentity();
4954 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004955 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4956 if (controller == null) {
4957 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4958
4959 // device does not support IMS, this method will return false
4960 return false;
4961 }
4962 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004963 } finally {
4964 Binder.restoreCallingIdentity(identity);
4965 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004966 }
4967
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004968 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004969 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004970 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4971 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4972 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004973 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4974 mApp, subId, "getImsProvisioningInt");
4975
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004976 final long identity = Binder.clearCallingIdentity();
4977 try {
4978 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004979 int slotId = getSlotIndex(subId);
4980 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4981 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4982 + subId + "' for key:" + key);
4983 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4984 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004985
joonhunshin91bc1952022-04-29 08:47:15 +00004986 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4987 if (controller == null) {
4988 loge("getImsProvisioningInt: Device does not support IMS");
4989
4990 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4991 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4992 }
4993 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004994 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4995 return retVal;
4996 }
4997
calvinpanb5a34062021-02-08 19:59:36 +08004998 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004999 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005000 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5001 + subId + "' for key:" + key);
5002 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005003 } finally {
5004 Binder.restoreCallingIdentity(identity);
5005 }
5006 }
5007
5008 @Override
5009 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005010 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5011 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5012 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005013 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5014 mApp, subId, "getImsProvisioningString");
5015
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005016 final long identity = Binder.clearCallingIdentity();
5017 try {
5018 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005019 int slotId = getSlotIndex(subId);
5020 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5021 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5022 + subId + "' for key:" + key);
5023 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5024 }
calvinpanb5a34062021-02-08 19:59:36 +08005025 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005026 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005027 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5028 + subId + "' for key:" + key);
5029 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005030 } finally {
5031 Binder.restoreCallingIdentity(identity);
5032 }
5033 }
5034
5035 @Override
5036 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005037 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5038 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5039 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5041 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005042
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005043 final long identity = Binder.clearCallingIdentity();
5044 try {
5045 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005046 int slotId = getSlotIndex(subId);
5047 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5048 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5049 + subId + "' for key:" + key);
5050 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5051 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005052
joonhunshin91bc1952022-04-29 08:47:15 +00005053 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5054 if (controller == null) {
5055 loge("setImsProvisioningInt: Device does not support IMS");
5056
5057 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5058 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5059 }
5060 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005061 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5062 return retVal;
5063 }
5064
calvinpanb5a34062021-02-08 19:59:36 +08005065 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5066 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005067 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005068 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005069 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005070 } finally {
5071 Binder.restoreCallingIdentity(identity);
5072 }
5073 }
5074
5075 @Override
5076 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005077 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5078 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5079 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5081 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005082 final long identity = Binder.clearCallingIdentity();
5083 try {
5084 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005085 int slotId = getSlotIndex(subId);
5086 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5087 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5088 + subId + "' for key:" + key);
5089 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5090 }
calvinpanb5a34062021-02-08 19:59:36 +08005091 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5092 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005093 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005094 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005095 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005096 } finally {
5097 Binder.restoreCallingIdentity(identity);
5098 }
5099 }
5100
Brad Ebinger919631e2021-06-02 17:46:35 -07005101 /**
5102 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5103 * for the given slot ID or no ImsResolver instance has been created.
5104 * @param slotId The slot ID that the IMS service is created for.
5105 * @throws ImsException If there is no ImsService configured for this slot.
5106 */
5107 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5108 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5109 ImsFeature.FEATURE_MMTEL)) {
5110 throw new ImsException("This subscription does not support MMTEL over IMS",
5111 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5112 }
5113 }
5114
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005115 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005116 int slotId = SubscriptionManager.getSlotIndex(subId);
5117 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005118 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5119 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005120 }
5121 return slotId;
5122 }
5123
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005124 private int getSlotIndex(int subId) {
5125 int slotId = SubscriptionManager.getSlotIndex(subId);
5126 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5127 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5128 }
5129 return slotId;
5130 }
5131
Wink Saville36469e72014-06-11 15:17:00 -07005132 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005133 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005134 */
5135 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005136 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5137 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005138 try {
5139 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5140 } catch (SecurityException se) {
5141 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5142 throw new SecurityException("Package " + callingPackage + " does not belong to "
5143 + Binder.getCallingUid());
5144 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005145 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005146 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005147 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005148 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005149 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005150 mApp, subId, callingPackage, callingFeatureId,
5151 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005152 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5153 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005155 final long identity = Binder.clearCallingIdentity();
5156 try {
5157 final Phone phone = getPhone(subId);
5158 if (phone != null) {
5159 return phone.getServiceState().getDataNetworkType();
5160 } else {
5161 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5162 }
5163 } finally {
5164 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005166 }
5167
5168 /**
5169 * Returns the data network type
5170 */
5171 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005172 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005173 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5174 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005175 }
5176
5177 /**
5178 * Returns the data network type for a subId
5179 */
5180 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005181 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5182 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005183 String functionName = "getDataNetworkTypeForSubscriber";
5184 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5185 mApp, functionName)) {
5186 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5187 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5188 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5189 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005190 }
5191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 final long identity = Binder.clearCallingIdentity();
5193 try {
5194 final Phone phone = getPhone(subId);
5195 if (phone != null) {
5196 return phone.getServiceState().getDataNetworkType();
5197 } else {
5198 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5199 }
5200 } finally {
5201 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005202 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005203 }
5204
5205 /**
Wink Saville36469e72014-06-11 15:17:00 -07005206 * Returns the Voice network type for a subId
5207 */
5208 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005209 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5210 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005211 String functionName = "getVoiceNetworkTypeForSubscriber";
5212 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5213 mApp, functionName)) {
5214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5215 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5216 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5217 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005218 }
5219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220 final long identity = Binder.clearCallingIdentity();
5221 try {
5222 final Phone phone = getPhone(subId);
5223 if (phone != null) {
5224 return phone.getServiceState().getVoiceNetworkType();
5225 } else {
5226 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5227 }
5228 } finally {
5229 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005231 }
5232
5233 /**
5234 * @return true if a ICC card is present
5235 */
5236 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005237 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005238 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5239 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005240 }
5241
5242 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005243 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005244 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005245 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005246 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 final long identity = Binder.clearCallingIdentity();
5248 try {
5249 final Phone phone = PhoneFactory.getPhone(slotIndex);
5250 if (phone != null) {
5251 return phone.getIccCard().hasIccCard();
5252 } else {
5253 return false;
5254 }
5255 } finally {
5256 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005258 }
5259
5260 /**
5261 * Return if the current radio is LTE on CDMA. This
5262 * is a tri-state return value as for a period of time
5263 * the mode may be unknown.
5264 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005265 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005266 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005267 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005268 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005269 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005270 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5271 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5272 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005273 }
5274
Sanket Padawe356d7632015-06-22 14:03:32 -07005275 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005276 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5277 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005278 try {
5279 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5280 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005281 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5282 }
5283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 final long identity = Binder.clearCallingIdentity();
5285 try {
5286 final Phone phone = getPhone(subId);
5287 if (phone == null) {
5288 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5289 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005290 return TelephonyProperties.lte_on_cdma_device()
5291 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292 }
5293 } finally {
5294 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005295 }
Wink Saville36469e72014-06-11 15:17:00 -07005296 }
5297
Wink Saville36469e72014-06-11 15:17:00 -07005298 /**
5299 * {@hide}
5300 * Returns Default subId, 0 in the case of single standby.
5301 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005302 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005303 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005304 }
5305
Shishir Agrawala9f32182016-04-12 12:00:16 -07005306 private int getSlotForDefaultSubscription() {
5307 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5308 }
5309
Wink Savilleb564aae2014-10-23 10:18:09 -07005310 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005311 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005312 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005313
Pengquan Menge92a50d2018-09-21 15:54:48 -07005314 private boolean isActiveSubscription(int subId) {
5315 return mSubscriptionController.isActiveSubId(subId);
5316 }
5317
Ihab Awadf2177b72013-11-25 13:33:23 -08005318 /**
5319 * @see android.telephony.TelephonyManager.WifiCallingChoices
5320 */
5321 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322 final long identity = Binder.clearCallingIdentity();
5323 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005324 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5326 getWhenToMakeWifiCallsDefaultPreference());
5327 } finally {
5328 Binder.restoreCallingIdentity(identity);
5329 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005330 }
5331
5332 /**
5333 * @see android.telephony.TelephonyManager.WifiCallingChoices
5334 */
5335 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 final long identity = Binder.clearCallingIdentity();
5337 try {
5338 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005339 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5341 } finally {
5342 Binder.restoreCallingIdentity(identity);
5343 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005344 }
5345
Sailesh Nepald1e68152013-12-12 19:08:02 -08005346 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005347 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005348 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005349 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005350
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005351 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5352 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5353 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005354 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005355 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5356 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005357 }
5358 return PhoneFactory.getPhone(phoneId);
5359 }
5360
Shishir Agrawal566b7612013-10-28 14:41:00 -07005361 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005362 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005363 @NonNull IccLogicalChannelRequest request) {
5364 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5365 /*message=*/ "iccOpenLogicalChannel");
5366
5367 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5368 // Verify that the callingPackage in the request belongs to the calling UID
5369 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5370
5371 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005372 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005373
Rambo Wanga1782702021-11-10 20:15:19 -08005374 private Phone getPhoneFromValidIccLogicalChannelRequest(
5375 @NonNull IccLogicalChannelRequest request, String message) {
5376 Phone phone;
5377 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5379 mApp, request.subId, message);
5380 phone = getPhoneFromSubId(request.subId);
5381 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5382 enforceModifyPermission();
5383 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5384 } else {
5385 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005386 }
Rambo Wanga1782702021-11-10 20:15:19 -08005387 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005388 }
5389
5390 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005391 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005392 final long identity = Binder.clearCallingIdentity();
5393 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005394 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005396 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5397 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005398 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5399 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 loge("The calling package is not allowed to access ISD-R.");
5401 throw new SecurityException(
5402 "The calling package is not allowed to access ISD-R.");
5403 }
Derek Tan740e1672017-06-27 14:56:27 -07005404 }
Derek Tan740e1672017-06-27 14:56:27 -07005405
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005407 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5408 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005409 return response;
5410 } finally {
5411 Binder.restoreCallingIdentity(identity);
5412 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005413 }
5414
5415 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005416 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5417 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5418 /*message=*/"iccCloseLogicalChannel");
5419
5420 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5421
5422 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005423 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005424
Rambo Wanga1782702021-11-10 20:15:19 -08005425 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5426 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005427 // before this feature is enabled, this API should only return false if
5428 // the operation fails instead of throwing runtime exception for
5429 // backward-compatibility.
5430 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5431 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432 final long identity = Binder.clearCallingIdentity();
5433 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005434 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005435 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005436 }
Chen Xue9d737e2022-01-01 23:41:31 -08005437 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005438 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005439 Boolean success = false;
5440 if (result instanceof RuntimeException) {
5441 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005442 if (shouldThrowExceptionOnFailure) {
5443 throw (RuntimeException) result;
5444 } else {
5445 return false;
5446 }
Chen Xue9d737e2022-01-01 23:41:31 -08005447 } else if (result instanceof Boolean) {
5448 success = (Boolean) result;
5449 } else {
5450 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5451 }
Rambo Wanga1782702021-11-10 20:15:19 -08005452 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005453 return success;
5454 } finally {
5455 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005456 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005457 }
5458
5459 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005460 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005461 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5463 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005464 if (DBG) {
5465 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5466 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5467 + p3 + " data=" + data);
5468 }
5469 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5470 command, p1, p2, p3, data);
5471 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005472
Jordan Liu4c733742019-02-28 12:03:40 -08005473 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005474 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5475 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005476 enforceModifyPermission();
5477 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005478 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5479 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5480 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005481 }
5482 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005483 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5484 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005485 }
5486
5487 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5488 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489 final long identity = Binder.clearCallingIdentity();
5490 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005491 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492 return "";
5493 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005496 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5497 null /* workSource */);
5498 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 // Append the returned status code to the end of the response payload.
5501 String s = Integer.toHexString(
5502 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5503 if (response.payload != null) {
5504 s = IccUtils.bytesToHexString(response.payload) + s;
5505 }
5506 return s;
5507 } finally {
5508 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005509 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005510 }
Jake Hambye994d462014-02-03 13:10:13 -08005511
Evan Charltonc66da362014-05-16 14:06:40 -07005512 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005513 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5514 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5516 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005517 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005518 if (DBG) {
5519 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5520 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5521 }
5522 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5523 cla, command, p1, p2, p3, data);
5524 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005525
Jordan Liu4c733742019-02-28 12:03:40 -08005526 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005527 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5528 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005529 enforceModifyPermission();
5530 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5531 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005532 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5533 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5534 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005535 }
5536
5537 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005538 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5539 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005540 }
5541
5542 // open APDU basic channel assuming the caller has sufficient permissions
5543 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5544 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545 final long identity = Binder.clearCallingIdentity();
5546 try {
5547 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5548 && TextUtils.equals(ISDR_AID, data)) {
5549 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005550 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5551 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005552 if (bestComponent == null
5553 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5554 loge("The calling package is not allowed to select ISD-R.");
5555 throw new SecurityException(
5556 "The calling package is not allowed to select ISD-R.");
5557 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005558 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005559
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005561 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5562 null /* workSource */);
5563 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 // Append the returned status code to the end of the response payload.
5566 String s = Integer.toHexString(
5567 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5568 if (response.payload != null) {
5569 s = IccUtils.bytesToHexString(response.payload) + s;
5570 }
5571 return s;
5572 } finally {
5573 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005574 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005575 }
5576
5577 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005578 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005579 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5581 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005582
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 final long identity = Binder.clearCallingIdentity();
5584 try {
5585 if (DBG) {
5586 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5587 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5588 }
5589
5590 IccIoResult response =
5591 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5592 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5593 subId);
5594
5595 if (DBG) {
5596 log("Exchange SIM_IO [R]" + response);
5597 }
5598
5599 byte[] result = null;
5600 int length = 2;
5601 if (response.payload != null) {
5602 length = 2 + response.payload.length;
5603 result = new byte[length];
5604 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5605 } else {
5606 result = new byte[length];
5607 }
5608
5609 result[length - 1] = (byte) response.sw2;
5610 result[length - 2] = (byte) response.sw1;
5611 return result;
5612 } finally {
5613 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005614 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005615 }
5616
Nathan Haroldb3014052017-01-25 15:57:32 -08005617 /**
5618 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5619 * on a particular subscription
5620 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005621 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5622 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005624 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005625 return null;
5626 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627
5628 final long identity = Binder.clearCallingIdentity();
5629 try {
5630 if (appType != TelephonyManager.APPTYPE_USIM
5631 && appType != TelephonyManager.APPTYPE_SIM) {
5632 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5633 return null;
5634 }
5635 Object response = sendRequest(
5636 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5637 if (response instanceof String[]) {
5638 return (String[]) response;
5639 }
yincheng zhao2737e882019-09-06 17:06:54 -07005640 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005642 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643 } finally {
5644 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005645 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005646 }
5647
yincheng zhao2737e882019-09-06 17:06:54 -07005648 /**
5649 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5650 * subscription.
5651 *
5652 * @param subId the id of the subscription.
5653 * @param appType the uicc app type, must be USIM or SIM.
5654 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5655 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005656 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005657 * @return number of fplmns that is successfully written to the SIM.
5658 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005659 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5660 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5662 mApp, subId, "setForbiddenPlmns");
5663
yincheng zhao2737e882019-09-06 17:06:54 -07005664 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5665 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5666 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5667 }
5668 if (fplmns == null) {
5669 throw new IllegalArgumentException("Fplmn List provided is null");
5670 }
5671 for (String fplmn : fplmns) {
5672 if (!CellIdentity.isValidPlmn(fplmn)) {
5673 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5674 }
5675 }
5676 final long identity = Binder.clearCallingIdentity();
5677 try {
5678 Object response = sendRequest(
5679 CMD_SET_FORBIDDEN_PLMNS,
5680 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5681 subId);
5682 return (int) response;
5683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
5686 }
5687
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005688 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005689 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5691 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693 final long identity = Binder.clearCallingIdentity();
5694 try {
5695 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5696 if (response.payload == null) {
5697 return "";
5698 }
Evan Charltonc66da362014-05-16 14:06:40 -07005699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 // Append the returned status code to the end of the response payload.
5701 String s = Integer.toHexString(
5702 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5703 s = IccUtils.bytesToHexString(response.payload) + s;
5704 return s;
5705 } finally {
5706 Binder.restoreCallingIdentity(identity);
5707 }
Evan Charltonc66da362014-05-16 14:06:40 -07005708 }
5709
Jake Hambye994d462014-02-03 13:10:13 -08005710 /**
5711 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5712 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5713 *
5714 * @param itemID the ID of the item to read
5715 * @return the NV item as a String, or null on error.
5716 */
5717 @Override
5718 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005719 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5721 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722
5723 final long identity = Binder.clearCallingIdentity();
5724 try {
5725 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005726 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5728 return value;
5729 } finally {
5730 Binder.restoreCallingIdentity(identity);
5731 }
Jake Hambye994d462014-02-03 13:10:13 -08005732 }
5733
5734 /**
5735 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5736 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5737 *
5738 * @param itemID the ID of the item to read
5739 * @param itemValue the value to write, as a String
5740 * @return true on success; false on any failure
5741 */
5742 @Override
5743 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005744 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5746 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747
5748 final long identity = Binder.clearCallingIdentity();
5749 try {
5750 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5751 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005752 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005753 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5754 return success;
5755 } finally {
5756 Binder.restoreCallingIdentity(identity);
5757 }
Jake Hambye994d462014-02-03 13:10:13 -08005758 }
5759
5760 /**
5761 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5762 * Used for device configuration by some CDMA operators.
5763 *
5764 * @param preferredRoamingList byte array containing the new PRL
5765 * @return true on success; false on any failure
5766 */
5767 @Override
5768 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5770 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771
5772 final long identity = Binder.clearCallingIdentity();
5773 try {
5774 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5775 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5776 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5777 return success;
5778 } finally {
5779 Binder.restoreCallingIdentity(identity);
5780 }
Jake Hambye994d462014-02-03 13:10:13 -08005781 }
5782
5783 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005784 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005785 * Used for device configuration by some CDMA operators.
5786 *
chen xu6dac5ab2018-10-26 17:39:23 -07005787 * @param slotIndex - device slot.
5788 *
Jake Hambye994d462014-02-03 13:10:13 -08005789 * @return true on success; false on any failure
5790 */
5791 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005792 public boolean resetModemConfig(int slotIndex) {
5793 Phone phone = PhoneFactory.getPhone(slotIndex);
5794 if (phone != null) {
5795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5796 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797
chen xu6dac5ab2018-10-26 17:39:23 -07005798 final long identity = Binder.clearCallingIdentity();
5799 try {
5800 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5801 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5802 return success;
5803 } finally {
5804 Binder.restoreCallingIdentity(identity);
5805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 }
chen xu6dac5ab2018-10-26 17:39:23 -07005807 return false;
5808 }
5809
5810 /**
5811 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5812 *
5813 * @param slotIndex - device slot.
5814 *
5815 * @return true on success; false on any failure
5816 */
5817 @Override
5818 public boolean rebootModem(int slotIndex) {
5819 Phone phone = PhoneFactory.getPhone(slotIndex);
5820 if (phone != null) {
5821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5822 mApp, phone.getSubId(), "rebootModem");
5823
5824 final long identity = Binder.clearCallingIdentity();
5825 try {
5826 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5827 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5828 return success;
5829 } finally {
5830 Binder.restoreCallingIdentity(identity);
5831 }
5832 }
5833 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005834 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005835
Brad Ebinger51f743a2017-01-23 13:50:20 -08005836 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005837 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5838 * {@link #disableIms(int)}.
5839 * @param slotIndex device slot.
5840 */
5841 public void resetIms(int slotIndex) {
5842 enforceModifyPermission();
5843
5844 final long identity = Binder.clearCallingIdentity();
5845 try {
5846 if (mImsResolver == null) {
5847 // may happen if the does not support IMS.
5848 return;
5849 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005850 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005851 } finally {
5852 Binder.restoreCallingIdentity(identity);
5853 }
5854 }
5855
5856 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005857 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5858 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005859 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005860 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005861 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005862
5863 final long identity = Binder.clearCallingIdentity();
5864 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005865 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005866 // may happen if the device does not support IMS.
5867 return;
5868 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005869 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005870 } finally {
5871 Binder.restoreCallingIdentity(identity);
5872 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005873 }
5874
5875 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005876 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5877 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005878 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005879 public void disableIms(int slotId) {
5880 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881
5882 final long identity = Binder.clearCallingIdentity();
5883 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005884 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005885 // may happen if the device does not support IMS.
5886 return;
5887 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005888 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005889 } finally {
5890 Binder.restoreCallingIdentity(identity);
5891 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005892 }
5893
5894 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005895 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5896 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005897 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005898 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005899 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005900 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901
5902 final long identity = Binder.clearCallingIdentity();
5903 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005904 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005905 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5906 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005907 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005908 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005909 } finally {
5910 Binder.restoreCallingIdentity(identity);
5911 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005912 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005913 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005914 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5915 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005916 @Override
5917 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005918 enforceModifyPermission();
5919
5920 final long identity = Binder.clearCallingIdentity();
5921 try {
5922 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005923 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005924 } finally {
5925 Binder.restoreCallingIdentity(identity);
5926 }
5927 }
5928
5929 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005930 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005931 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005932 */
5933 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5934 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935
5936 final long identity = Binder.clearCallingIdentity();
5937 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005938 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005939 // may happen if the device does not support IMS.
5940 return null;
5941 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005942 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 } finally {
5944 Binder.restoreCallingIdentity(identity);
5945 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005946 }
5947
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005948 /**
5949 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005950 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005951 */
5952 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5953 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005954
5955 final long identity = Binder.clearCallingIdentity();
5956 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005957 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005958 // may happen if the device does not support IMS.
5959 return null;
5960 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005961 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 } finally {
5963 Binder.restoreCallingIdentity(identity);
5964 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005965 }
5966
Brad Ebinger884c07b2018-02-15 16:17:40 -08005967 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005968 * Sets the ImsService Package Name that Telephony will bind to.
5969 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005970 * @param slotIndex the slot ID that the ImsService should bind for.
5971 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005972 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005973 * @param featureTypes An integer array of feature types associated with a packageName.
5974 * @param packageName The name of the package that the current configuration will be replaced
5975 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005976 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005977 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005978 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5979 int[] featureTypes, String packageName) {
5980 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5981 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5983 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005984 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005985
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986 final long identity = Binder.clearCallingIdentity();
5987 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005988 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005989 // may happen if the device does not support IMS.
5990 return false;
5991 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005992 Map<Integer, String> featureConfig = new HashMap<>();
5993 for (int featureType : featureTypes) {
5994 featureConfig.put(featureType, packageName);
5995 }
5996 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5997 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 } finally {
5999 Binder.restoreCallingIdentity(identity);
6000 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006001 }
6002
6003 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006004 * Clears any carrier ImsService overrides for the slot index specified that were previously
6005 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6006 *
6007 * This should only be used for testing.
6008 *
6009 * @param slotIndex the slot ID that the ImsService should bind for.
6010 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6011 */
6012 @Override
6013 public boolean clearCarrierImsServiceOverride(int slotIndex) {
6014 int[] subIds = SubscriptionManager.getSubId(slotIndex);
6015 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6016 "clearCarrierImsServiceOverride");
6017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
6018 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6019 "clearCarrierImsServiceOverride");
6020
6021 final long identity = Binder.clearCallingIdentity();
6022 try {
6023 if (mImsResolver == null) {
6024 // may happen if the device does not support IMS.
6025 return false;
6026 }
6027 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6028 } finally {
6029 Binder.restoreCallingIdentity(identity);
6030 }
6031 }
6032
6033 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006034 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006035 *
6036 * @param slotId The slot that the ImsService is associated with.
6037 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6038 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006039 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006040 * @return the package name of the ImsService configuration.
6041 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006042 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6043 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07006044 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08006045 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006046 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08006047 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6048 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006050 final long identity = Binder.clearCallingIdentity();
6051 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006052 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006053 // may happen if the device does not support IMS.
6054 return "";
6055 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006056 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006057 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6058 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059 } finally {
6060 Binder.restoreCallingIdentity(identity);
6061 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006062 }
6063
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006064 /**
6065 * Get the MmTelFeature state associated with the requested subscription id.
6066 * @param subId The subscription that the MmTelFeature is associated with.
6067 * @param callback A callback with an integer containing the
6068 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6069 */
6070 @Override
6071 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6072 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006073 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6074 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6075 "IMS not available on device.");
6076 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006077 final long token = Binder.clearCallingIdentity();
6078 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006079 int slotId = getSlotIndex(subId);
6080 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6081 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6082 + subId + "'");
6083 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6084 }
6085 verifyImsMmTelConfiguredOrThrow(slotId);
6086 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6087 try {
6088 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6089 } catch (RemoteException e) {
6090 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6091 + "Ignore");
6092 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006093 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006094 } catch (ImsException e) {
6095 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006096 } finally {
6097 Binder.restoreCallingIdentity(token);
6098 }
6099 }
6100
Daniel Brightbb5840b2021-01-12 15:48:18 -08006101 /**
6102 * Sets the ims registration state on all valid {@link Phone}s.
6103 */
6104 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006105 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106
6107 final long identity = Binder.clearCallingIdentity();
6108 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006109 // NOTE: Before S, this method only set the default phone.
6110 for (final Phone phone : PhoneFactory.getPhones()) {
6111 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6112 phone.setImsRegistrationState(registered);
6113 }
6114 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 } finally {
6116 Binder.restoreCallingIdentity(identity);
6117 }
Wink Saville36469e72014-06-11 15:17:00 -07006118 }
6119
6120 /**
Stuart Scott54788802015-03-30 13:18:01 -07006121 * Set the network selection mode to automatic.
6122 *
6123 */
6124 @Override
6125 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6127 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128
6129 final long identity = Binder.clearCallingIdentity();
6130 try {
shilufc958392020-01-20 11:36:01 -08006131 if (!isActiveSubscription(subId)) {
6132 return;
6133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006135 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6136 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 } finally {
6138 Binder.restoreCallingIdentity(identity);
6139 }
Stuart Scott54788802015-03-30 13:18:01 -07006140 }
6141
Jack Yud10cdd42020-09-28 20:28:01 -07006142 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006143 * Ask the radio to connect to the input network and change selection mode to manual.
6144 *
6145 * @param subId the id of the subscription.
6146 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6147 * the operator to attach to.
6148 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6149 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6150 * normal network selection next time.
6151 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006152 */
6153 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006154 public boolean setNetworkSelectionModeManual(
6155 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6157 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006158
6159 if (!isActiveSubscription(subId)) {
6160 return false;
6161 }
6162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 final long identity = Binder.clearCallingIdentity();
6164 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006165 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006167 if (DBG) {
6168 log("setNetworkSelectionModeManual: subId: " + subId
6169 + " operator: " + operatorInfo);
6170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6172 } finally {
6173 Binder.restoreCallingIdentity(identity);
6174 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006175 }
shilu84f6e8b2019-12-19 13:58:01 -08006176 /**
6177 * Get the manual network selection
6178 *
6179 * @param subId the id of the subscription.
6180 *
6181 * @return the previously saved user selected PLMN
6182 */
6183 @Override
6184 public String getManualNetworkSelectionPlmn(int subId) {
6185 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006186 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006187 mApp, subId, "getManualNetworkSelectionPlmn");
6188
6189 final long identity = Binder.clearCallingIdentity();
6190 try {
6191 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006192 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006193 }
6194
6195 final Phone phone = getPhone(subId);
6196 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006197 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006198 }
6199 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6200 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6201 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6202 } finally {
6203 Binder.restoreCallingIdentity(identity);
6204 }
6205 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006206
6207 /**
6208 * Scans for available networks.
6209 */
6210 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006211 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6212 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6214 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006215 LocationAccessPolicy.LocationPermissionResult locationResult =
6216 LocationAccessPolicy.checkLocationPermission(mApp,
6217 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6218 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006219 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006220 .setCallingPid(Binder.getCallingPid())
6221 .setCallingUid(Binder.getCallingUid())
6222 .setMethod("getCellNetworkScanResults")
6223 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006224 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6225 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006226 .build());
6227 switch (locationResult) {
6228 case DENIED_HARD:
6229 throw new SecurityException("Not allowed to access scan results -- location");
6230 case DENIED_SOFT:
6231 return null;
6232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233
Pengquan Menga1bb6272018-09-06 09:59:22 -07006234 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006235 try {
6236 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006237 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 } finally {
6240 Binder.restoreCallingIdentity(identity);
6241 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006242 }
6243
6244 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006245 * Get the call forwarding info, given the call forwarding reason.
6246 */
6247 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006248 public void getCallForwarding(int subId, int callForwardingReason,
6249 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006250 enforceReadPrivilegedPermission("getCallForwarding");
6251 long identity = Binder.clearCallingIdentity();
6252 try {
6253 if (DBG) {
6254 log("getCallForwarding: subId " + subId
6255 + " callForwardingReason" + callForwardingReason);
6256 }
Hall Liu27d24262020-09-18 19:04:59 -07006257
6258 Phone phone = getPhone(subId);
6259 if (phone == null) {
6260 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006261 callback.onError(
6262 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006263 } catch (RemoteException e) {
6264 // ignore
6265 }
6266 return;
6267 }
6268
6269 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6270 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6271 @Override
6272 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6273 try {
6274 callback.onCallForwardingInfoAvailable(info);
6275 } catch (RemoteException e) {
6276 // ignore
6277 }
6278 }
6279
6280 @Override
6281 public void onError(int error) {
6282 try {
6283 callback.onError(error);
6284 } catch (RemoteException e) {
6285 // ignore
6286 }
6287 }
6288 });
6289 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006290 } finally {
6291 Binder.restoreCallingIdentity(identity);
6292 }
6293 }
6294
6295 /**
6296 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6297 * reason, the number to forward, and the timeout before the forwarding is attempted.
6298 */
6299 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006300 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6301 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006302 enforceModifyPermission();
6303 long identity = Binder.clearCallingIdentity();
6304 try {
6305 if (DBG) {
6306 log("setCallForwarding: subId " + subId
6307 + " callForwardingInfo" + callForwardingInfo);
6308 }
Hall Liu27d24262020-09-18 19:04:59 -07006309
6310 Phone phone = getPhone(subId);
6311 if (phone == null) {
6312 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006313 callback.accept(
6314 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006315 } catch (RemoteException e) {
6316 // ignore
6317 }
6318 return;
6319 }
6320
6321 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6322 FunctionalUtils.ignoreRemoteException(callback::accept));
6323
6324 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006325 } finally {
6326 Binder.restoreCallingIdentity(identity);
6327 }
6328 }
6329
6330 /**
Hall Liu27d24262020-09-18 19:04:59 -07006331 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006332 */
6333 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006334 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006335 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006336 long identity = Binder.clearCallingIdentity();
6337 try {
Hall Liu27d24262020-09-18 19:04:59 -07006338 Phone phone = getPhone(subId);
6339 if (phone == null) {
6340 try {
6341 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6342 } catch (RemoteException e) {
6343 // ignore
6344 }
6345 return;
6346 }
SongFerngWang0e767992021-03-31 22:08:45 +08006347 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6348 PersistableBundle c = configManager.getConfigForSubId(subId);
6349 boolean requireUssd = c.getBoolean(
6350 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006351
Shuo Qian4a594052020-01-23 11:59:30 -08006352 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006353 if (requireUssd) {
6354 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6355 getSubscriptionCarrierId(subId));
6356 String newUssdCommand = "";
6357 try {
6358 newUssdCommand = carrierXmlParser.getFeature(
6359 CarrierXmlParser.FEATURE_CALL_WAITING)
6360 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6361 } catch (NullPointerException e) {
6362 loge("Failed to generate USSD number" + e);
6363 }
6364 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6365 mMainThreadHandler, callback, carrierXmlParser,
6366 CarrierXmlParser.SsEntry.SSAction.QUERY);
6367 final String ussdCommand = newUssdCommand;
6368 Executors.newSingleThreadExecutor().execute(() -> {
6369 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6370 });
6371 } else {
6372 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6373 callback::accept);
6374 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6375 }
Shuo Qian4a594052020-01-23 11:59:30 -08006376 } finally {
6377 Binder.restoreCallingIdentity(identity);
6378 }
6379 }
6380
6381 /**
Hall Liu27d24262020-09-18 19:04:59 -07006382 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006383 */
6384 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006385 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006386 enforceModifyPermission();
6387 long identity = Binder.clearCallingIdentity();
6388 try {
Hall Liu27d24262020-09-18 19:04:59 -07006389 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6390
6391 Phone phone = getPhone(subId);
6392 if (phone == null) {
6393 try {
6394 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6395 } catch (RemoteException e) {
6396 // ignore
6397 }
6398 return;
6399 }
6400
SongFerngWang0e767992021-03-31 22:08:45 +08006401 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6402 PersistableBundle c = configManager.getConfigForSubId(subId);
6403 boolean requireUssd = c.getBoolean(
6404 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006405
SongFerngWang0e767992021-03-31 22:08:45 +08006406 if (DBG) log("getCallWaitingStatus: subId " + subId);
6407 if (requireUssd) {
6408 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6409 getSubscriptionCarrierId(subId));
6410 CarrierXmlParser.SsEntry.SSAction ssAction =
6411 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6412 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6413 String newUssdCommand = "";
6414 try {
6415 newUssdCommand = carrierXmlParser.getFeature(
6416 CarrierXmlParser.FEATURE_CALL_WAITING)
6417 .makeCommand(ssAction, null);
6418 } catch (NullPointerException e) {
6419 loge("Failed to generate USSD number" + e);
6420 }
6421 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6422 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6423 final String ussdCommand = newUssdCommand;
6424 Executors.newSingleThreadExecutor().execute(() -> {
6425 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6426 });
6427 } else {
6428 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6429 FunctionalUtils.ignoreRemoteException(callback::accept));
6430
6431 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6432 }
Shuo Qian4a594052020-01-23 11:59:30 -08006433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435 }
6436 }
6437
6438 /**
yinxub1bed742017-04-17 11:45:04 -07006439 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006440 *
yinxub1bed742017-04-17 11:45:04 -07006441 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006442 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6443 * location related information which will be sent if the caller already possess
6444 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006445 * @param request contains the radio access networks with bands/channels to scan
6446 * @param messenger callback messenger for scan results or errors
6447 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006448 * @return the id of the requested scan which can be used to stop the scan.
6449 */
6450 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006451 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6452 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006453 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6455 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006456 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006457 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6458 if (!renounceFineLocationAccess) {
6459 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6460 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6461 .setCallingPackage(callingPackage)
6462 .setCallingFeatureId(callingFeatureId)
6463 .setCallingPid(Binder.getCallingPid())
6464 .setCallingUid(Binder.getCallingUid())
6465 .setMethod("requestNetworkScan")
6466 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6467 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6468 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6469 .build());
6470 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006471 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006472 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6473 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006474 if (e != null) {
6475 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6476 throw e;
6477 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006478 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006479 return TelephonyScanManager.INVALID_SCAN_ID;
6480 }
6481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006482 }
Hall Liu912dfd32019-04-25 14:02:26 -07006483 int callingUid = Binder.getCallingUid();
6484 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006485 final long identity = Binder.clearCallingIdentity();
6486 try {
6487 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006488 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006489 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006490 } finally {
6491 Binder.restoreCallingIdentity(identity);
6492 }
yinxu504e1392017-04-12 16:03:22 -07006493 }
6494
Hall Liub2ac8ef2019-02-28 15:56:23 -08006495 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006496 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006497 boolean hasCarrierPriv;
6498 final long identity = Binder.clearCallingIdentity();
6499 try {
6500 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6501 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6502 } finally {
6503 Binder.restoreCallingIdentity(identity);
6504 }
Hall Liu558027f2019-05-15 19:14:05 -07006505 boolean hasNetworkScanPermission =
6506 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6507 == PERMISSION_GRANTED;
6508
6509 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6510 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6511 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006512 }
6513
6514 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6515 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006516 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6517 return new SecurityException("Specific channels must not be"
6518 + " scanned without location access.");
6519 }
6520 }
6521 }
6522
Hall Liub2ac8ef2019-02-28 15:56:23 -08006523 return null;
6524 }
6525
yinxu504e1392017-04-12 16:03:22 -07006526 /**
6527 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006528 *
6529 * @param subId id of the subscription
6530 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006531 */
6532 @Override
6533 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6535 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536
Hall Liu912dfd32019-04-25 14:02:26 -07006537 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006538 final long identity = Binder.clearCallingIdentity();
6539 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006540 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006541 } finally {
6542 Binder.restoreCallingIdentity(identity);
6543 }
yinxu504e1392017-04-12 16:03:22 -07006544 }
6545
6546 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006547 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006548 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006549 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006550 */
6551 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006552 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006553 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006554 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006555 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556
6557 final long identity = Binder.clearCallingIdentity();
6558 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006559 if (DBG) log("getAllowedNetworkTypesBitmask");
6560 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6561 int networkTypesBitmask = (result != null ? result[0] : -1);
6562 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6563 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564 } finally {
6565 Binder.restoreCallingIdentity(identity);
6566 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006567 }
6568
6569 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006570 * Get the allowed network types for certain reason.
6571 *
6572 * @param subId the id of the subscription.
6573 * @param reason the reason the allowed network type change is taking place
6574 * @return the allowed network types.
6575 */
6576 @Override
6577 public long getAllowedNetworkTypesForReason(int subId,
6578 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006579 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006580 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006581 final long identity = Binder.clearCallingIdentity();
6582 try {
6583 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6584 } finally {
6585 Binder.restoreCallingIdentity(identity);
6586 }
6587 }
6588
6589 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006590 * Enable/Disable E-UTRA-NR Dual Connectivity
6591 * @param subId subscription id of the sim card
6592 * @param nrDualConnectivityState expected NR dual connectivity state
6593 * This can be passed following states
6594 * <ol>
6595 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6596 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6597 * <li>Disable NR dual connectivity and force secondary cell to be released
6598 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6599 * </ol>
6600 * @return operation result.
6601 */
6602 @Override
6603 public int setNrDualConnectivityState(int subId,
6604 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6606 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006607 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006608 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6609 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6610 }
6611
Sooraj Sasindran37444802020-08-11 10:40:43 -07006612 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6613 final long identity = Binder.clearCallingIdentity();
6614 try {
6615 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6616 nrDualConnectivityState, subId,
6617 workSource);
6618 if (DBG) log("enableNRDualConnectivity result: " + result);
6619 return result;
6620 } finally {
6621 Binder.restoreCallingIdentity(identity);
6622 }
6623 }
6624
6625 /**
6626 * Is E-UTRA-NR Dual Connectivity enabled
6627 * @return true if dual connectivity is enabled else false
6628 */
6629 @Override
6630 public boolean isNrDualConnectivityEnabled(int subId) {
6631 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006632 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006633 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006634 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006635 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6636 return false;
6637 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006638 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6639 final long identity = Binder.clearCallingIdentity();
6640 try {
6641 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6642 null, subId, workSource);
6643 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6644 return isEnabled;
6645 } finally {
6646 Binder.restoreCallingIdentity(identity);
6647 }
6648 }
6649
6650 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006651 * Set the allowed network types of the device and
6652 * provide the reason triggering the allowed network change.
6653 *
6654 * @param subId the id of the subscription.
6655 * @param reason the reason the allowed network type change is taking place
6656 * @param allowedNetworkTypes the allowed network types.
6657 * @return true on success; false on any failure.
6658 */
6659 @Override
6660 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006661 @TelephonyManager.AllowedNetworkTypesReason int reason,
6662 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6664 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006665 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006666 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6667 return false;
6668 }
6669 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6670 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006671 return false;
6672 }
6673
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006674 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6675 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6676
6677
6678 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6679 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6680 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006681 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006682
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006683 final long identity = Binder.clearCallingIdentity();
6684 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006685 Boolean success = (Boolean) sendRequest(
6686 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6687 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6688
6689 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6690 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006691 } finally {
6692 Binder.restoreCallingIdentity(identity);
6693 }
6694 }
6695
6696 /**
Miaoa84611c2019-03-15 09:21:10 +08006697 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006698 *
Miaoa84611c2019-03-15 09:21:10 +08006699 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006700 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006701 * @hide
6702 */
6703 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006704 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006705 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006707 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 try {
Miaoa84611c2019-03-15 09:21:10 +08006709 if (phone != null) {
6710 return phone.hasMatchedTetherApnSetting();
6711 } else {
6712 return false;
6713 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 } finally {
6715 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006716 }
Junda Liu475951f2014-11-07 16:45:03 -08006717 }
6718
6719 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006720 * Get the user enabled state of Mobile Data.
6721 *
6722 * TODO: remove and use isUserDataEnabled.
6723 * This can't be removed now because some vendor codes
6724 * calls through ITelephony directly while they should
6725 * use TelephonyManager.
6726 *
6727 * @return true on enabled
6728 */
6729 @Override
6730 public boolean getDataEnabled(int subId) {
6731 return isUserDataEnabled(subId);
6732 }
6733
6734 /**
6735 * Get whether mobile data is enabled per user setting.
6736 *
6737 * There are other factors deciding whether mobile data is actually enabled, but they are
6738 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006739 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006740 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6741 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006742 *
6743 * @return {@code true} if data is enabled else {@code false}
6744 */
6745 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006746 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006747 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006748 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006749 try {
6750 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6751 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006752 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006753 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6754 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006755 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006757 mApp, subId, functionName);
6758
Robert Greenwalt646120a2014-05-23 11:54:03 -07006759 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760
6761 final long identity = Binder.clearCallingIdentity();
6762 try {
6763 int phoneId = mSubscriptionController.getPhoneId(subId);
6764 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6765 Phone phone = PhoneFactory.getPhone(phoneId);
6766 if (phone != null) {
6767 boolean retVal = phone.isUserDataEnabled();
6768 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6769 return retVal;
6770 } else {
6771 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6772 return false;
6773 }
6774 } finally {
6775 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006776 }
6777 }
6778
6779 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006780 * Checks if the device is capable of mobile data by considering whether whether the
6781 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6782 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006783 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006784 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006785 */
6786 @Override
6787 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006788 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006789 try {
6790 try {
6791 mApp.enforceCallingOrSelfPermission(
6792 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006793 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006794 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006795 try {
6796 mApp.enforceCallingOrSelfPermission(
6797 android.Manifest.permission.READ_PHONE_STATE,
6798 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006799 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006800 mApp.enforceCallingOrSelfPermission(
6801 permission.READ_BASIC_PHONE_STATE, functionName);
6802 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006803 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006804 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006805 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006807
6808 final long identity = Binder.clearCallingIdentity();
6809 try {
6810 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811 Phone phone = PhoneFactory.getPhone(phoneId);
6812 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006813 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006814 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006815 return retVal;
6816 } else {
6817 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6818 return false;
6819 }
6820 } finally {
6821 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006822 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006823 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006824
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006825 /**
6826 * Check if data is enabled for a specific reason
6827 * @param subId Subscription index
6828 * @param reason the reason the data enable change is taking place
6829 * @return {@code true} if the overall data is enabled; {@code false} if not.
6830 */
6831 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006832 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006833 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006834 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006835 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006836 try {
6837 mApp.enforceCallingOrSelfPermission(
6838 android.Manifest.permission.ACCESS_NETWORK_STATE,
6839 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006840 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006841 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6842 functionName);
6843 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006844 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006845 try {
6846 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006847 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006848 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006850 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006851 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006852 }
6853
6854
6855 final long identity = Binder.clearCallingIdentity();
6856 try {
6857 int phoneId = mSubscriptionController.getPhoneId(subId);
6858 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006859 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006860 + " reason=" + reason);
6861 }
6862 Phone phone = PhoneFactory.getPhone(phoneId);
6863 if (phone != null) {
6864 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006865 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006866 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006867 return retVal;
6868 } else {
6869 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006870 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006871 + subId + " retVal=false");
6872 }
6873 return false;
6874 }
6875 } finally {
6876 Binder.restoreCallingIdentity(identity);
6877 }
6878 }
6879
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006880 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006881 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006882 // No permission needed; this only lets the caller inspect their own status.
6883 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006884 }
Junda Liu29340342014-07-10 15:23:27 -07006885
6886 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006887 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006888 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006889 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6890 }
6891
6892 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6893 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006894 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006895 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006896 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6897 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006898 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6899 if (cpt == null) {
6900 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006901 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6902 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006903 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006904 }
6905
6906 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006907 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006908 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006909 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006910 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006911 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006912 Phone phone = getPhone(subId);
6913 if (phone == null) {
6914 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6915 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6916 }
6917 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6918 if (cpt == null) {
6919 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006920 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6921 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006922 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006923 }
6924
6925 @Override
6926 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006927 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006928 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6929 }
6930
6931 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006932 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006933 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006934 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006935 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006936 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6937 Phone phone = PhoneFactory.getPhone(phoneId);
6938 if (phone == null) {
6939 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006940 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006941 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6942 if (cpt == null) {
6943 continue;
6944 }
6945 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006946 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6947 break;
6948 }
6949 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006950 return result;
Junda Liu29340342014-07-10 15:23:27 -07006951 }
Derek Tan89e89d42014-07-08 17:00:10 -07006952
6953 @Override
Junda Liue64de782015-04-16 17:19:16 -07006954 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006955 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006956 Phone phone = PhoneFactory.getPhone(phoneId);
6957 if (phone == null) {
6958 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006959 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006960 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6961 if (cpt == null) {
6962 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006963 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006964 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006965 }
6966
Amith Yamasani6e118872016-02-19 12:53:51 -08006967 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006968 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006969 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006970 Phone phone = PhoneFactory.getPhone(phoneId);
6971 if (phone == null) {
6972 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006973 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006974 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6975 if (cpt == null) {
6976 return Collections.emptyList();
6977 }
6978 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006979 }
6980
chen xuf7e9fe82019-05-09 19:31:02 -07006981 @Override
6982 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006983 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006984 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006985 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006986 try {
6987 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6988 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6989 }
6990 } finally {
6991 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006992 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006993 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006994 }
6995
Rambo Wang6812ffb2022-03-15 16:54:17 -07006996 @Override
6997 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6998 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6999
7000 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7001 if (phone == null) {
7002 return null;
7003 }
7004 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7005 if (cpt == null) {
7006 return null;
7007 }
7008 return cpt.getCarrierServicePackageName();
7009 }
7010
Wink Savilleb564aae2014-10-23 10:18:09 -07007011 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007012 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007013 UiccPort port = phone == null ? null : phone.getUiccPort();
7014 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007015 return null;
7016 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007017 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007018 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007019 return null;
7020 }
7021 return iccId;
7022 }
7023
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007024 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007025 public void setCallComposerStatus(int subId, int status) {
7026 enforceModifyPermission();
7027
7028 final long identity = Binder.clearCallingIdentity();
7029 try {
7030 Phone phone = getPhone(subId);
7031 if (phone != null) {
7032 Phone defaultPhone = phone.getImsPhone();
7033 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7034 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7035 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007036 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7037 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007038 }
7039 }
Shuo Qian284ae752020-12-22 19:10:14 -08007040 } catch (ImsException e) {
7041 throw new ServiceSpecificException(e.getCode());
7042 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007043 Binder.restoreCallingIdentity(identity);
7044 }
7045 }
7046
7047 @Override
7048 public int getCallComposerStatus(int subId) {
7049 enforceReadPrivilegedPermission("getCallComposerStatus");
7050
7051 final long identity = Binder.clearCallingIdentity();
7052 try {
7053 Phone phone = getPhone(subId);
7054 if (phone != null) {
7055 Phone defaultPhone = phone.getImsPhone();
7056 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7057 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7058 return imsPhone.getCallComposerStatus();
7059 }
7060 }
7061 } finally {
7062 Binder.restoreCallingIdentity(identity);
7063 }
7064 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7065 }
7066
7067 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007068 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7069 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007070 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007071 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 final long identity = Binder.clearCallingIdentity();
7074 try {
7075 final String iccId = getIccId(subId);
7076 final Phone phone = getPhone(subId);
7077 if (phone == null) {
7078 return false;
7079 }
7080 final String subscriberId = phone.getSubscriberId();
7081
7082 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007083 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084 + subscriberId + " to " + number);
7085 }
7086
7087 if (TextUtils.isEmpty(iccId)) {
7088 return false;
7089 }
7090
7091 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7092
7093 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7094 if (alphaTag == null) {
7095 editor.remove(alphaTagPrefKey);
7096 } else {
7097 editor.putString(alphaTagPrefKey, alphaTag);
7098 }
7099
7100 // Record both the line number and IMSI for this ICCID, since we need to
7101 // track all merged IMSIs based on line number
7102 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7103 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7104 if (number == null) {
7105 editor.remove(numberPrefKey);
7106 editor.remove(subscriberPrefKey);
7107 } else {
7108 editor.putString(numberPrefKey, number);
7109 editor.putString(subscriberPrefKey, subscriberId);
7110 }
7111
7112 editor.commit();
7113 return true;
7114 } finally {
7115 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007116 }
Derek Tan7226c842014-07-02 17:42:23 -07007117 }
7118
7119 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007120 public String getLine1NumberForDisplay(int subId, String callingPackage,
7121 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007122 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007123 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007124 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007125 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007126 return null;
7127 }
Derek Tan97ebb422014-09-05 16:55:38 -07007128
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007129 final long identity = Binder.clearCallingIdentity();
7130 try {
7131 String iccId = getIccId(subId);
7132 if (iccId != null) {
7133 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7134 if (DBG_MERGE) {
7135 log("getLine1NumberForDisplay returning "
7136 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7137 }
7138 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007139 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7141 return null;
7142 } finally {
7143 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007144 }
Derek Tan7226c842014-07-02 17:42:23 -07007145 }
7146
7147 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007148 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7149 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007151 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007152 return null;
7153 }
Derek Tan97ebb422014-09-05 16:55:38 -07007154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007155 final long identity = Binder.clearCallingIdentity();
7156 try {
7157 String iccId = getIccId(subId);
7158 if (iccId != null) {
7159 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7160 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7161 }
7162 return null;
7163 } finally {
7164 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007165 }
Derek Tan7226c842014-07-02 17:42:23 -07007166 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007167
7168 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007169 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7170 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007171 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7172 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007174 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007175 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007176 return null;
7177 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007178
Jordan Liub49b04b2019-05-06 14:45:15 -07007179 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7180 // the process, where TelephonyManager was instantiated.
7181 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007182 final long identity = Binder.clearCallingIdentity();
7183 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007184 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007185 final TelephonyManager tele = TelephonyManager.from(context);
7186 final SubscriptionManager sub = SubscriptionManager.from(context);
7187
7188 // Figure out what subscribers are currently active
7189 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007190
Jordan Liub49b04b2019-05-06 14:45:15 -07007191 // Only consider subs which match the current subId
7192 // This logic can be simplified. See b/131189269 for progress.
7193 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007194 activeSubscriberIds.add(tele.getSubscriberId(subId));
7195 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196
7197 // First pass, find a number override for an active subscriber
7198 String mergeNumber = null;
7199 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7200 for (String key : prefs.keySet()) {
7201 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7202 final String subscriberId = (String) prefs.get(key);
7203 if (activeSubscriberIds.contains(subscriberId)) {
7204 final String iccId = key.substring(
7205 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7206 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7207 mergeNumber = (String) prefs.get(numberKey);
7208 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007209 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007210 + " for active subscriber " + subscriberId);
7211 }
7212 if (!TextUtils.isEmpty(mergeNumber)) {
7213 break;
7214 }
7215 }
7216 }
7217 }
7218
7219 // Shortcut when no active merged subscribers
7220 if (TextUtils.isEmpty(mergeNumber)) {
7221 return null;
7222 }
7223
7224 // Second pass, find all subscribers under that line override
7225 final ArraySet<String> result = new ArraySet<>();
7226 for (String key : prefs.keySet()) {
7227 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7228 final String number = (String) prefs.get(key);
7229 if (mergeNumber.equals(number)) {
7230 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7231 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7232 final String subscriberId = (String) prefs.get(subscriberKey);
7233 if (!TextUtils.isEmpty(subscriberId)) {
7234 result.add(subscriberId);
7235 }
7236 }
7237 }
7238 }
7239
7240 final String[] resultArray = result.toArray(new String[result.size()]);
7241 Arrays.sort(resultArray);
7242 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007243 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007244 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7245 }
7246 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007247 } finally {
7248 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007249 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007250 }
7251
7252 @Override
zoey chen38003472019-12-13 17:16:31 +08007253 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7254 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007255
7256 final long identity = Binder.clearCallingIdentity();
7257 try {
7258 final TelephonyManager telephonyManager = mApp.getSystemService(
7259 TelephonyManager.class);
7260 String subscriberId = telephonyManager.getSubscriberId(subId);
7261 if (subscriberId == null) {
7262 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007263 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007264 + subId);
7265 }
7266 return null;
7267 }
7268
7269 final SubscriptionInfo info = SubscriptionController.getInstance()
7270 .getSubscriptionInfo(subId);
7271 final ParcelUuid groupUuid = info.getGroupUuid();
7272 // If it doesn't belong to any group, return just subscriberId of itself.
7273 if (groupUuid == null) {
7274 return new String[]{subscriberId};
7275 }
7276
7277 // Get all subscriberIds from the group.
7278 final List<String> mergedSubscriberIds = new ArrayList<>();
7279 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007280 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007281 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007282 for (SubscriptionInfo subInfo : groupInfos) {
7283 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7284 if (subscriberId != null) {
7285 mergedSubscriberIds.add(subscriberId);
7286 }
7287 }
7288
7289 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7290 } finally {
7291 Binder.restoreCallingIdentity(identity);
7292
7293 }
7294 }
7295
7296 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007297 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007298 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007299 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007300
7301 final long identity = Binder.clearCallingIdentity();
7302 try {
7303 final Phone phone = getPhone(subId);
7304 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7305 } finally {
7306 Binder.restoreCallingIdentity(identity);
7307 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007308 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007309
7310 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007311 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007312 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7313 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007314 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7315 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007316
7317 final long identity = Binder.clearCallingIdentity();
7318 try {
7319 final Phone phone = getPhone(subId);
7320 if (phone == null) {
7321 return false;
7322 }
7323 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7324 cdmaNonRoamingList);
7325 } finally {
7326 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007327 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007328 }
7329
7330 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007331 @Deprecated
7332 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7333 enforceModifyPermission();
7334
7335 int returnValue = 0;
7336 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007337 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007338 if(result.exception == null) {
7339 if (result.result != null) {
7340 byte[] responseData = (byte[])(result.result);
7341 if(responseData.length > oemResp.length) {
7342 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7343 responseData.length + "bytes. Buffer Size is " +
7344 oemResp.length + "bytes.");
7345 }
7346 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7347 returnValue = responseData.length;
7348 }
7349 } else {
7350 CommandException ex = (CommandException) result.exception;
7351 returnValue = ex.getCommandError().ordinal();
7352 if(returnValue > 0) returnValue *= -1;
7353 }
7354 } catch (RuntimeException e) {
7355 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7356 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7357 if(returnValue > 0) returnValue *= -1;
7358 }
7359
7360 return returnValue;
7361 }
7362
7363 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007364 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007365 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007366 try {
7367 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007368 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007369 mApp, phone.getSubId(), "getRadioAccessFamily");
7370 } catch (SecurityException e) {
7371 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7372 throw e;
7373 }
chen xub97461a2018-10-26 14:17:57 -07007374 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007375 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007376 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378 final long identity = Binder.clearCallingIdentity();
7379 try {
chen xub97461a2018-10-26 14:17:57 -07007380 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007381 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007382 mApp, phone.getSubId(), "getRadioAccessFamily");
7383 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384 } finally {
7385 Binder.restoreCallingIdentity(identity);
7386 }
chen xub97461a2018-10-26 14:17:57 -07007387 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007388 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007389
7390 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007391 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007392 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007393 try {
7394 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7395 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007396 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007397 }
7398 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007399 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007400 }
7401 RoleManager rm = mApp.getSystemService(RoleManager.class);
7402 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7403 if (!dialerRoleHolders.contains(callingPackage)) {
7404 throw new SecurityException("App must be the dialer role holder to"
7405 + " upload a call composer pic");
7406 }
7407
7408 Executors.newSingleThreadExecutor().execute(() -> {
7409 ByteArrayOutputStream output = new ByteArrayOutputStream(
7410 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7411 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7412 boolean readUntilEnd = false;
7413 int totalBytesRead = 0;
7414 byte[] buffer = new byte[16 * 1024];
7415 while (true) {
7416 int numRead;
7417 try {
7418 numRead = input.read(buffer);
7419 } catch (IOException e) {
7420 try {
7421 fd.checkError();
7422 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7423 null);
7424 } catch (IOException e1) {
7425 // This means that the other side closed explicitly with an error. If this
7426 // happens, log and ignore.
7427 loge("Remote end of call composer picture pipe closed: " + e1);
7428 }
7429 break;
7430 }
7431 if (numRead == -1) {
7432 readUntilEnd = true;
7433 break;
7434 }
7435 totalBytesRead += numRead;
7436 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7437 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7438 try {
7439 input.close();
7440 } catch (IOException e) {
7441 // ignore
7442 }
7443 break;
7444 }
7445 output.write(buffer, 0, numRead);
7446 }
7447 // Generally, the remote end will close the file descriptors. The only case where we
7448 // close is above, where the picture size is too big.
7449
7450 try {
7451 fd.checkError();
7452 } catch (IOException e) {
7453 loge("Remote end for call composer closed with an error: " + e);
7454 return;
7455 }
7456
Hall Liuaa4211e2021-01-20 15:43:39 -08007457 if (!readUntilEnd) {
7458 loge("Did not finish reading entire image; aborting");
7459 return;
7460 }
Hall Liu82694d52020-12-11 18:22:04 -08007461
Hall Liuaa4211e2021-01-20 15:43:39 -08007462 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7463 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7464 new CallComposerPictureTransfer.Factory() {},
7465 imageData,
7466 (result) -> {
7467 if (result.first != null) {
7468 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7469 Bundle outputResult = new Bundle();
7470 outputResult.putParcelable(
7471 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7472 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7473 outputResult);
7474 } else {
7475 callback.send(result.second, null);
7476 }
7477 }
7478 );
Hall Liu82694d52020-12-11 18:22:04 -08007479 });
7480 }
7481
7482 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007483 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007484 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007485 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486
7487 final long identity = Binder.clearCallingIdentity();
7488 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007489 ImsManager.getInstance(defaultPhone.getContext(),
7490 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491 } finally {
7492 Binder.restoreCallingIdentity(identity);
7493 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007494 }
7495
7496 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007497 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007498 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7500 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007501 return false;
7502 }
Svet Ganovb320e182015-04-16 12:30:10 -07007503
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 final long identity = Binder.clearCallingIdentity();
7505 try {
7506 // Check the user preference and the system-level IMS setting. Even if the user has
7507 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7508 // In the long run, we may instead need to check if there exists a connection service
7509 // which can support video calling.
7510 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007511 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 return imsManager.isVtEnabledByPlatform()
7513 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7514 && imsManager.isVtEnabledByUser();
7515 } finally {
7516 Binder.restoreCallingIdentity(identity);
7517 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007518 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007519
Andrew Leea1239f22015-03-02 17:44:07 -08007520 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007521 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7522 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007524 mApp, subId, callingPackage, callingFeatureId,
7525 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526 return false;
7527 }
7528
7529 final long identity = Binder.clearCallingIdentity();
7530 try {
7531 CarrierConfigManager configManager =
7532 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007533 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7535 } finally {
7536 Binder.restoreCallingIdentity(identity);
7537 }
Andrew Leea1239f22015-03-02 17:44:07 -08007538 }
7539
7540 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007541 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007543 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 return false;
7545 }
7546
7547 final long identity = Binder.clearCallingIdentity();
7548 try {
7549 CarrierConfigManager configManager =
7550 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007551 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7553 } finally {
7554 Binder.restoreCallingIdentity(identity);
7555 }
Andrew Leea1239f22015-03-02 17:44:07 -08007556 }
7557
Andrew Lee9431b832015-03-09 18:46:45 -07007558 @Override
7559 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007560 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007561 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007562 }
7563
7564 @Override
7565 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 final long identity = Binder.clearCallingIdentity();
7567 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007568 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007569 } finally {
7570 Binder.restoreCallingIdentity(identity);
7571 }
Andrew Lee9431b832015-03-09 18:46:45 -07007572 }
7573
Hall Liuf6668912018-10-31 17:05:23 -07007574 /**
7575 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7576 * support for the feature and device firmware support.
7577 *
7578 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7579 */
7580 @Override
7581 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007582 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007583 final Phone phone = getPhone(subscriptionId);
7584 if (phone == null) {
7585 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7586 return false;
7587 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007588 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007589 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007590 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7591 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007592 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 return isCarrierSupported && isDeviceSupported;
7594 } finally {
7595 Binder.restoreCallingIdentity(identity);
7596 }
Hall Liu98187582018-01-22 19:15:32 -08007597 }
7598
Hall Liuf6668912018-10-31 17:05:23 -07007599 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007600 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7601 * RTT setting, will return true if the device and carrier both support RTT.
7602 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007603 */
7604 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007605 final long identity = Binder.clearCallingIdentity();
7606 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007607 boolean isRttSupported = isRttSupported(subscriptionId);
7608 boolean isUserRttSettingOn = Settings.Secure.getInt(
7609 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7610 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7611 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7612 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007613 } finally {
7614 Binder.restoreCallingIdentity(identity);
7615 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007616 }
7617
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007618 @Deprecated
7619 @Override
7620 public String getDeviceId(String callingPackage) {
7621 return getDeviceIdWithFeature(callingPackage, null);
7622 }
7623
Sanket Padawe7310cc72015-01-14 09:53:20 -08007624 /**
7625 * Returns the unique device ID of phone, for example, the IMEI for
7626 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7627 *
7628 * <p>Requires Permission:
7629 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7630 */
7631 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007632 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007633 try {
7634 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7635 } catch (SecurityException se) {
7636 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7637 throw new SecurityException("Package " + callingPackage + " does not belong to "
7638 + Binder.getCallingUid());
7639 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007640 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007641 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007642 return null;
7643 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007644 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007645 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007646 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007647 return null;
7648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007649
7650 final long identity = Binder.clearCallingIdentity();
7651 try {
7652 return phone.getDeviceId();
7653 } finally {
7654 Binder.restoreCallingIdentity(identity);
7655 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007656 }
7657
Ping Sunc67b7c22016-03-02 19:16:45 +08007658 /**
7659 * {@hide}
7660 * Returns the IMS Registration Status on a particular subid
7661 *
7662 * @param subId
7663 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007664 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007665 Phone phone = getPhone(subId);
7666 if (phone != null) {
7667 return phone.isImsRegistered();
7668 } else {
7669 return false;
7670 }
7671 }
7672
Santos Cordon7a1885b2015-02-03 11:15:19 -08007673 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007674 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007675 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007676 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007677 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007678 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7679 }
7680 final long identity = Binder.clearCallingIdentity();
7681 try {
7682 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7683 } finally {
7684 Binder.restoreCallingIdentity(identity);
7685 }
7686 }
7687
7688 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007689 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007690 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007691 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007692 mApp,
7693 subscriptionId,
7694 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007695 final long identity = Binder.clearCallingIdentity();
7696 try {
7697 Phone phone = getPhone(subscriptionId);
7698 if (phone == null) {
7699 return null;
7700 }
7701 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7702 } finally {
7703 Binder.restoreCallingIdentity(identity);
7704 }
7705 }
7706
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007707 /**
7708 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007709 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007710 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007711 final long identity = Binder.clearCallingIdentity();
7712 try {
7713 Phone phone = getPhone(subId);
7714 if (phone != null) {
7715 return phone.isWifiCallingEnabled();
7716 } else {
7717 return false;
7718 }
7719 } finally {
7720 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007721 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007722 }
7723
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007724 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007725 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007726 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007727 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007728 final long identity = Binder.clearCallingIdentity();
7729 try {
7730 Phone phone = getPhone(subId);
7731 if (phone != null) {
7732 return phone.isVideoEnabled();
7733 } else {
7734 return false;
7735 }
7736 } finally {
7737 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007738 }
7739 }
7740
7741 /**
7742 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7743 * defined in {@link ImsRegistrationImplBase}.
7744 */
7745 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746 final long identity = Binder.clearCallingIdentity();
7747 try {
7748 Phone phone = getPhone(subId);
7749 if (phone != null) {
7750 return phone.getImsRegistrationTech();
7751 } else {
7752 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7753 }
7754 } finally {
7755 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007756 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007757 }
7758
Stuart Scott8eef64f2015-04-08 15:13:54 -07007759 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007760 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007761 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007762 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7763 return;
7764 }
Kai Shif70f46f2021-03-03 13:59:46 -08007765 Phone defaultPhone = getDefaultPhone();
7766 if (defaultPhone != null) {
7767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7768 mApp, getDefaultPhone().getSubId(), "factoryReset");
7769 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007770 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007771
Svet Ganovcc087f82015-05-12 20:35:54 -07007772 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007773 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7774 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007775 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007776 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007777 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007778 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007779 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007780 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007781 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007782 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007783 // There has been issues when Sms raw table somehow stores orphan
7784 // fragments. They lead to garbled message when new fragments come
7785 // in and combined with those stale ones. In case this happens again,
7786 // user can reset all network settings which will clean up this table.
7787 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007788 // Clean up IMS settings as well here.
7789 int slotId = getSlotIndex(subId);
7790 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7791 ImsManager.getInstance(mApp, slotId).factoryReset();
7792 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007793
Kai Shif70f46f2021-03-03 13:59:46 -08007794 if (defaultPhone == null) {
7795 return;
7796 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007797 // Erase modem config if erase modem on network setting is enabled.
7798 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7799 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7800 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007801 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007802 }
Kai Shif70f46f2021-03-03 13:59:46 -08007803
7804 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007805 } finally {
7806 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007807 }
7808 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007809
SongFerngWangfd89b102021-05-27 22:44:54 +08007810 @VisibleForTesting
7811 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7812 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7813 return;
7814 }
7815 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7816 RILConstants.PREFERRED_NETWORK_MODE);
7817 SubscriptionManager.setSubscriptionProperty(subId,
7818 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7819 "user=" + defaultNetworkType);
7820 phone.loadAllowedNetworksFromSubscriptionDatabase();
7821 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7822 defaultNetworkType, null);
7823 }
7824
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007825 private void cleanUpSmsRawTable(Context context) {
7826 ContentResolver resolver = context.getContentResolver();
7827 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7828 resolver.delete(uri, null, null);
7829 }
7830
Narayan Kamath1c496c22015-04-16 14:40:19 +01007831 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007832 public String getSimLocaleForSubscriber(int subId) {
7833 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7834 final Phone phone = getPhone(subId);
7835 if (phone == null) {
7836 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007837 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007838 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007839 final long identity = Binder.clearCallingIdentity();
7840 try {
chen xu5d3637b2019-01-21 23:31:38 -08007841 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007842 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007843 if (info == null) {
7844 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7845 return null;
7846 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007847 // Try and fetch the locale from the carrier properties or from the SIM language
7848 // preferences (EF-PL and EF-LI)...
7849 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007851 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7852 if (localeFromDefaultSim != null) {
7853 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7854 if (DBG) log("Using locale from subId: " + subId + " locale: "
7855 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08007856 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007857 } else {
7858 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007859 }
7860 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007861
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007862 // The SIM language preferences only store a language (e.g. fr = French), not an
7863 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7864 // the SIM and carrier preferences does not include a country we add the country
7865 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007866 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007867 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007868 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08007869 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007870 }
7871
7872 if (DBG) log("No locale found - returning null");
7873 return null;
7874 } finally {
7875 Binder.restoreCallingIdentity(identity);
7876 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007877 }
7878
tom hsu0b59d292022-09-29 23:49:21 +08007879 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08007880 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007881 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08007882 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007883 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08007884 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7885 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08007886 Locale.forLanguageTag(localeTag).getCountry())) {
7887 return localeTag;
7888 }
7889 }
7890 return inputLocale.toLanguageTag();
7891 }
7892
Narayan Kamath1c496c22015-04-16 14:40:19 +01007893 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007894 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007895 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007896 }
7897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007898 /**
7899 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7900 */
7901 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007902 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007903 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007904 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007905
Gary Jian3aa9a762022-01-24 16:41:19 +08007906 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7907 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007908
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007909 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007910 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7911 * representing the state of the modem.
7912 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007913 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7914 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007915 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007916 */
7917 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007918 public void requestModemActivityInfo(ResultReceiver result) {
7919 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007920 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007921
7922 final long identity = Binder.clearCallingIdentity();
7923 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007924 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925 } finally {
7926 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007927 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007928 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007929
Siddharth Rayb8114062018-06-17 15:02:38 -07007930 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7931 // less than total activity duration.
7932 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7933 if (info == null) {
7934 return false;
7935 }
7936 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007937 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7938 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7939
Siddharth Rayb8114062018-06-17 15:02:38 -07007940 return (info.isValid()
7941 && (info.getSleepTimeMillis() <= activityDurationMs)
7942 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007943 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007944 && (totalTxTimeMs <= activityDurationMs));
7945 }
7946
Gary Jian3aa9a762022-01-24 16:41:19 +08007947 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7948 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7949 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7950 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7951
7952 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7953 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7954 }
7955
7956 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7957 mLastModemActivityInfo.setReceiveTimeMillis(
7958 rat,
7959 freq,
7960 info.getReceiveTimeMillis(rat, freq)
7961 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7962 }
7963
7964 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7965 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7966 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7967 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7968
7969 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7970 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7971 }
7972 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7973 mLastModemActivityInfo.setReceiveTimeMillis(
7974 rat,
7975 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7976 }
7977
7978 /**
7979 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7980 * @param info recent ModemActivityInfo
7981 */
7982 private void mergeModemActivityInfo(ModemActivityInfo info) {
7983 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7984 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7985 boolean matched;
7986 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7987 matched = false;
7988 int rat = info.getSpecificInfoRat(i);
7989 int freq = info.getSpecificInfoFrequencyRange(i);
7990 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7991 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7992 //if it already exists
7993 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7994 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7995 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7996 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7997 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7998 updateLastModemActivityInfo(info, rat, freq);
7999 matched = true;
8000 }
8001 } else {
8002 updateLastModemActivityInfo(info, rat);
8003 matched = true;
8004 }
8005 }
8006 }
8007
8008 if (!matched) {
8009 mDeltaSpecificInfo =
8010 new ActivityStatsTechSpecificInfo(
8011 rat,
8012 freq,
8013 info.getTransmitTimeMillis(rat, freq),
8014 (int) info.getReceiveTimeMillis(rat, freq));
8015 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
8016 }
8017 }
8018 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8019 mLastModemActivitySpecificInfo =
8020 new ActivityStatsTechSpecificInfo[merged.size()];
8021 merged.toArray(mLastModemActivitySpecificInfo);
8022
8023 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8024 mLastModemActivityInfo.setSleepTimeMillis(
8025 info.getSleepTimeMillis()
8026 + mLastModemActivityInfo.getSleepTimeMillis());
8027 mLastModemActivityInfo.setIdleTimeMillis(
8028 info.getIdleTimeMillis()
8029 + mLastModemActivityInfo.getIdleTimeMillis());
8030 }
8031
Jack Yu85bd38a2015-11-09 11:34:32 -08008032 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008033 * Returns the service state information on specified subscription.
8034 */
8035 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008036 public ServiceState getServiceStateForSubscriber(int subId,
8037 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8038 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008039 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008040 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008041 return null;
8042 }
8043
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008044 boolean hasFinePermission = false;
8045 boolean hasCoarsePermission = false;
8046 if (!renounceFineLocationAccess) {
8047 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8048 LocationAccessPolicy.checkLocationPermission(mApp,
8049 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8050 .setCallingPackage(callingPackage)
8051 .setCallingFeatureId(callingFeatureId)
8052 .setCallingPid(Binder.getCallingPid())
8053 .setCallingUid(Binder.getCallingUid())
8054 .setMethod("getServiceStateForSubscriber")
8055 .setLogAsInfo(true)
8056 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8057 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8058 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8059 .build());
8060 hasFinePermission =
8061 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8062 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008063
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008064 if (!renounceCoarseLocationAccess) {
8065 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8066 LocationAccessPolicy.checkLocationPermission(mApp,
8067 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8068 .setCallingPackage(callingPackage)
8069 .setCallingFeatureId(callingFeatureId)
8070 .setCallingPid(Binder.getCallingPid())
8071 .setCallingUid(Binder.getCallingUid())
8072 .setMethod("getServiceStateForSubscriber")
8073 .setLogAsInfo(true)
8074 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8075 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8076 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8077 .build());
8078 hasCoarsePermission =
8079 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8080 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008081
Jack Yu479f40e2020-10-27 21:29:25 -07008082 final Phone phone = getPhone(subId);
8083 if (phone == null) {
8084 return null;
8085 }
8086
Jordan Liu0f2bc442020-11-18 16:47:37 -08008087 final long identity = Binder.clearCallingIdentity();
8088
Jack Yu479f40e2020-10-27 21:29:25 -07008089 boolean isCallingPackageDataService = phone.getDataServicePackages()
8090 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008092 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8093 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8094 Rlog.d(LOG_TAG,
8095 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8096 return null;
8097 }
8098
Hall Liuf19c44f2018-11-27 14:38:17 -08008099 ServiceState ss = phone.getServiceState();
8100
8101 // Scrub out the location info in ServiceState depending on what level of access
8102 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008103 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008104 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8105 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008106 } finally {
8107 Binder.restoreCallingIdentity(identity);
8108 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008109 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008110
8111 /**
8112 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8113 *
8114 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8115 * voicemail ringtone.
8116 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8117 * PhoneAccount.
8118 */
8119 @Override
8120 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008121 final long identity = Binder.clearCallingIdentity();
8122 try {
8123 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8124 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008125 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008126 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008128 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8129 } finally {
8130 Binder.restoreCallingIdentity(identity);
8131 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008132 }
8133
8134 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008135 * Sets the per-account voicemail ringtone.
8136 *
8137 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8138 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8139 *
8140 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8141 * voicemail ringtone.
8142 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8143 * PhoneAccount.
8144 */
8145 @Override
8146 public void setVoicemailRingtoneUri(String callingPackage,
8147 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008148 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008149 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008150 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8151 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8153 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8154 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008155 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008156
8157 final long identity = Binder.clearCallingIdentity();
8158 try {
8159 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8160 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008161 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162 }
8163 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8164 } finally {
8165 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008166 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008167 }
8168
8169 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008170 * Returns whether vibration is set for voicemail notification in Phone settings.
8171 *
8172 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8173 * voicemail vibration setting.
8174 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8175 */
8176 @Override
8177 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008178 final long identity = Binder.clearCallingIdentity();
8179 try {
8180 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8181 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008182 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008183 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008185 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8186 } finally {
8187 Binder.restoreCallingIdentity(identity);
8188 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008189 }
8190
Youhan Wange64578a2016-05-02 15:32:42 -07008191 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008192 * Sets the per-account voicemail vibration.
8193 *
8194 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8195 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8196 *
8197 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8198 * voicemail vibration setting.
8199 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8200 * specific PhoneAccount.
8201 */
8202 @Override
8203 public void setVoicemailVibrationEnabled(String callingPackage,
8204 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008205 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008206 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008207 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8208 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8210 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8211 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008212 }
8213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214 final long identity = Binder.clearCallingIdentity();
8215 try {
8216 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8217 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008218 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008219 }
8220 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8221 } finally {
8222 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008223 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008224 }
8225
8226 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008227 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8228 *
8229 * @throws SecurityException if the caller does not have the required permission
8230 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008231 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008232 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008233 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008234 }
8235
8236 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008237 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8238 * permission.
8239 *
8240 * @throws SecurityException if the caller does not have the required permission
8241 */
8242 private void enforceSendSmsPermission() {
8243 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8244 }
8245
8246 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008247 * Make sure either called from same process as self (phone) or IPC caller has interact across
8248 * users permission.
8249 *
8250 * @throws SecurityException if the caller does not have the required permission
8251 */
8252 private void enforceInteractAcrossUsersPermission(String message) {
8253 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8254 }
8255
8256 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008257 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008258 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008259 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008260 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008261 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008262 final long identity = Binder.clearCallingIdentity();
8263 try {
8264 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008265 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008266 if (componentName == null) {
8267 throw new SecurityException(
8268 "Caller not current active visual voicemail package[null]");
8269 }
8270 String vvmPackage = componentName.getPackageName();
8271 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008272 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008273 }
8274 } finally {
8275 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008276 }
8277 }
8278
8279 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008280 * Return the application ID for the app type.
8281 *
8282 * @param subId the subscription ID that this request applies to.
8283 * @param appType the uicc app type.
8284 * @return Application ID for specificied app type, or null if no uicc.
8285 */
8286 @Override
8287 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008288 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008289 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008290
8291 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008292 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 if (phone == null) {
8294 return null;
8295 }
8296 String aid = null;
8297 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008298 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299 .getApplicationByType(appType).getAid();
8300 } catch (Exception e) {
8301 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8302 }
8303 return aid;
8304 } finally {
8305 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008306 }
Youhan Wange64578a2016-05-02 15:32:42 -07008307 }
8308
Youhan Wang4001d252016-05-11 10:29:41 -07008309 /**
8310 * Return the Electronic Serial Number.
8311 *
8312 * @param subId the subscription ID that this request applies to.
8313 * @return ESN or null if error.
8314 */
8315 @Override
8316 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008317 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008318 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008319
8320 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008321 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008322 if (phone == null) {
8323 return null;
8324 }
8325 String esn = null;
8326 try {
8327 esn = phone.getEsn();
8328 } catch (Exception e) {
8329 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8330 }
8331 return esn;
8332 } finally {
8333 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008334 }
Youhan Wang4001d252016-05-11 10:29:41 -07008335 }
8336
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008337 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008338 * Return the Preferred Roaming List Version.
8339 *
8340 * @param subId the subscription ID that this request applies to.
8341 * @return PRLVersion or null if error.
8342 */
8343 @Override
8344 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008345 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008346 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008347
8348 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008349 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008350 if (phone == null) {
8351 return null;
8352 }
8353 String cdmaPrlVersion = null;
8354 try {
8355 cdmaPrlVersion = phone.getCdmaPrlVersion();
8356 } catch (Exception e) {
8357 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8358 }
8359 return cdmaPrlVersion;
8360 } finally {
8361 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008362 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008363 }
8364
8365 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008366 * Get snapshot of Telephony histograms
8367 * @return List of Telephony histograms
8368 * @hide
8369 */
8370 @Override
8371 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8373 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008374
8375 final long identity = Binder.clearCallingIdentity();
8376 try {
8377 return RIL.getTelephonyRILTimingHistograms();
8378 } finally {
8379 Binder.restoreCallingIdentity(identity);
8380 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008381 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008382
8383 /**
8384 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008385 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8386 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008387 * Require system privileges. In the future we may add this to carrier APIs.
8388 *
Michele Berionne482f8202018-11-27 18:57:59 -08008389 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008390 */
8391 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008392 @TelephonyManager.SetCarrierRestrictionResult
8393 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008394 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008395 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008396
Michele Berionne482f8202018-11-27 18:57:59 -08008397 if (carrierRestrictionRules == null) {
8398 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008399 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008401 final long identity = Binder.clearCallingIdentity();
8402 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008403 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008404 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008405 } finally {
8406 Binder.restoreCallingIdentity(identity);
8407 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008408 }
8409
8410 /**
8411 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008412 * Get the allowed carrier list and the excluded carrier list, including the priority between
8413 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008414 * Require system privileges. In the future we may add this to carrier APIs.
8415 *
Michele Berionne482f8202018-11-27 18:57:59 -08008416 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008417 */
8418 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008419 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008420 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008421 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008422
8423 final long identity = Binder.clearCallingIdentity();
8424 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008425 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8426 if (response instanceof CarrierRestrictionRules) {
8427 return (CarrierRestrictionRules) response;
8428 }
8429 // Response is an Exception of some kind,
8430 // which is signalled to the user as a NULL retval
8431 return null;
8432 } catch (Exception e) {
8433 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8434 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008435 } finally {
8436 Binder.restoreCallingIdentity(identity);
8437 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008438 }
8439
fionaxu59545b42016-05-25 15:53:37 -07008440 /**
fionaxu59545b42016-05-25 15:53:37 -07008441 * Action set from carrier signalling broadcast receivers to enable/disable radio
8442 * @param subId the subscription ID that this action applies to.
8443 * @param enabled control enable or disable radio.
8444 * {@hide}
8445 */
8446 @Override
8447 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8448 enforceModifyPermission();
8449 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008450
8451 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008452 if (phone == null) {
8453 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8454 return;
8455 }
8456 try {
8457 phone.carrierActionSetRadioEnabled(enabled);
8458 } catch (Exception e) {
8459 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008460 } finally {
8461 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008462 }
8463 }
8464
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008465 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008466 * Enable or disable Voice over NR (VoNR)
8467 * @param subId the subscription ID that this action applies to.
8468 * @param enabled enable or disable VoNR.
8469 * @return operation result.
8470 */
8471 @Override
8472 public int setVoNrEnabled(int subId, boolean enabled) {
8473 enforceModifyPermission();
8474 final Phone phone = getPhone(subId);
8475
8476 final long identity = Binder.clearCallingIdentity();
8477 if (phone == null) {
8478 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8479 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8480 }
8481
8482 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8483 try {
8484 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8485 workSource);
8486 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008487
8488 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8489 if (DBG) {
8490 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8491 }
8492 SubscriptionManager.setSubscriptionProperty(
8493 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8494 (enabled ? "1" : "0"));
8495 }
8496
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008497 return result;
8498 } finally {
8499 Binder.restoreCallingIdentity(identity);
8500 }
8501 }
8502
8503 /**
8504 * Is voice over NR enabled
8505 * @return true if VoNR is enabled else false
8506 */
8507 @Override
8508 public boolean isVoNrEnabled(int subId) {
8509 enforceReadPrivilegedPermission("isVoNrEnabled");
8510 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8511 final long identity = Binder.clearCallingIdentity();
8512 try {
8513 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8514 null, subId, workSource);
8515 if (DBG) log("isVoNrEnabled: " + isEnabled);
8516 return isEnabled;
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
8519 }
8520 }
8521
8522 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008523 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8524 * network status based on which carrier apps could apply actions accordingly,
8525 * enable/disable default url handler for example.
8526 *
8527 * @param subId the subscription ID that this action applies to.
8528 * @param report control start/stop reporting the default network status.
8529 * {@hide}
8530 */
8531 @Override
8532 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8533 enforceModifyPermission();
8534 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008535
8536 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008537 if (phone == null) {
8538 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8539 return;
8540 }
8541 try {
8542 phone.carrierActionReportDefaultNetworkStatus(report);
8543 } catch (Exception e) {
8544 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008545 } finally {
8546 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008547 }
8548 }
8549
8550 /**
fionaxud9622282017-07-17 17:51:30 -07008551 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8552 * @param subId the subscription ID that this action applies to.
8553 * {@hide}
8554 */
8555 @Override
8556 public void carrierActionResetAll(int subId) {
8557 enforceModifyPermission();
8558 final Phone phone = getPhone(subId);
8559 if (phone == null) {
8560 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8561 return;
8562 }
8563 try {
8564 phone.carrierActionResetAll();
8565 } catch (Exception e) {
8566 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8567 }
8568 }
8569
8570 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008571 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8572 * bug report is being generated.
8573 */
8574 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008575 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008576 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8577 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008578 writer.println("Permission Denial: can't dump Phone from pid="
8579 + Binder.getCallingPid()
8580 + ", uid=" + Binder.getCallingUid()
8581 + "without permission "
8582 + android.Manifest.permission.DUMP);
8583 return;
8584 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008585 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008586 }
Jack Yueb89b242016-06-22 13:27:47 -07008587
Brad Ebingerdac2f002018-04-03 15:17:52 -07008588 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008589 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8590 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8591 @NonNull String[] args) {
8592 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8593 this, in.getFileDescriptor(), out.getFileDescriptor(),
8594 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008595 }
8596
Jack Yueb89b242016-06-22 13:27:47 -07008597 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008598 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008599 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008600 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008601 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008602 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008603 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008604 */
8605 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008606 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008607 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008608 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8609 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8610 try {
8611 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008612 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008613 } catch (SecurityException se) {
8614 enforceModifyPermission();
8615 }
8616 } else {
8617 enforceModifyPermission();
8618 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008619
8620 final long identity = Binder.clearCallingIdentity();
8621 try {
8622 Phone phone = getPhone(subId);
8623 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008624 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8625 phone.carrierActionSetMeteredApnsEnabled(enabled);
8626 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008627 phone.getDataSettingsManager().setDataEnabled(
8628 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008629 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008630 }
8631 } finally {
8632 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008633 }
8634 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008635
8636 /**
8637 * Get Client request stats
8638 * @return List of Client Request Stats
8639 * @hide
8640 */
8641 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008642 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8643 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008644 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008645 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008646 return null;
8647 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008648 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008650 final long identity = Binder.clearCallingIdentity();
8651 try {
8652 if (phone != null) {
8653 return phone.getClientRequestStats();
8654 }
8655
8656 return null;
8657 } finally {
8658 Binder.restoreCallingIdentity(identity);
8659 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008660 }
8661
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008662 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008663 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008664 if (uid == Process.ROOT_UID && packageName == null) {
8665 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8666 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8667 // exception. ROOT_UID seems not to have a valid package name returned by
8668 // PackageManager, so just fake it here to avoid issues when running telephony shell
8669 // commands that plumb through the RIL as root, like so:
8670 // $ adb root
8671 // $ adb shell cmd phone ...
8672 packageName = "root";
8673 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008674 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008675 }
Jack Yueb4124c2017-02-16 15:32:43 -08008676
8677 /**
Grace Chen70990072017-03-24 17:21:30 -07008678 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008679 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008680 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008681 * @param state State of SIM (power down, power up, pass through)
8682 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8683 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8684 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008685 *
8686 **/
8687 @Override
Grace Chen70990072017-03-24 17:21:30 -07008688 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008689 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008690 Phone phone = PhoneFactory.getPhone(slotIndex);
8691
vagdeviaf9a5b92018-08-15 16:01:53 -07008692 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008694 final long identity = Binder.clearCallingIdentity();
8695 try {
8696 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008697 phone.setSimPowerState(state, null, workSource);
8698 }
8699 } finally {
8700 Binder.restoreCallingIdentity(identity);
8701 }
8702 }
8703
8704 /**
8705 * Set SIM card power state.
8706 *
8707 * @param slotIndex SIM slot id.
8708 * @param state State of SIM (power down, power up, pass through)
8709 * @param callback callback to trigger after success or failure
8710 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8711 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8712 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8713 *
8714 **/
8715 @Override
8716 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8717 IIntegerConsumer callback) {
8718 enforceModifyPermission();
8719 Phone phone = PhoneFactory.getPhone(slotIndex);
8720
8721 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8722
8723 final long identity = Binder.clearCallingIdentity();
8724 try {
8725 if (phone != null) {
8726 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8727 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008728 }
8729 } finally {
8730 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008731 }
8732 }
Shuo Qiandd210312017-04-12 22:11:33 +00008733
Tyler Gunn65d45c22017-06-05 11:22:26 -07008734 private boolean isUssdApiAllowed(int subId) {
8735 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008736 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008737 if (configManager == null) {
8738 return false;
8739 }
8740 PersistableBundle pb = configManager.getConfigForSubId(subId);
8741 if (pb == null) {
8742 return false;
8743 }
8744 return pb.getBoolean(
8745 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8746 }
8747
Shuo Qiandd210312017-04-12 22:11:33 +00008748 /**
8749 * Check if phone is in emergency callback mode
8750 * @return true if phone is in emergency callback mode
8751 * @param subId sub id
8752 */
goneil9c5f4872017-12-05 14:07:56 -08008753 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008754 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008755 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008756 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008757
8758 final long identity = Binder.clearCallingIdentity();
8759 try {
8760 if (phone != null) {
8761 return phone.isInEcm();
8762 } else {
8763 return false;
8764 }
8765 } finally {
8766 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008767 }
8768 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008769
8770 /**
8771 * Get the current signal strength information for the given subscription.
8772 * Because this information is not updated when the device is in a low power state
8773 * it should not be relied-upon to be current.
8774 * @param subId Subscription index
8775 * @return the most recent cached signal strength info from the modem
8776 */
8777 @Override
8778 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008779 final long identity = Binder.clearCallingIdentity();
8780 try {
8781 Phone p = getPhone(subId);
8782 if (p == null) {
8783 return null;
8784 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008786 return p.getSignalStrength();
8787 } finally {
8788 Binder.restoreCallingIdentity(identity);
8789 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008790 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008791
Pengquan Meng77b7f132018-08-22 14:49:57 -07008792 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008793 * Get the current modem radio state for the given slot.
8794 * @param slotIndex slot index.
8795 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008796 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008797 * @return the current radio power state from the modem
8798 */
8799 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008800 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008801 Phone phone = PhoneFactory.getPhone(slotIndex);
8802 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8804 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008805 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8806 }
8807
8808 final long identity = Binder.clearCallingIdentity();
8809 try {
8810 return phone.getRadioPowerState();
8811 } finally {
8812 Binder.restoreCallingIdentity(identity);
8813 }
8814 }
8815 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8816 }
8817
8818 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008819 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8820 *
8821 * <p>Requires one of the following permissions:
8822 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008823 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008824 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8825 * privileges.
8826 *
8827 * @param subId subscription id
8828 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8829 * {@code false}.
8830 */
8831 @Override
8832 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008833 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008834 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008835 try {
8836 mApp.enforceCallingOrSelfPermission(
8837 android.Manifest.permission.ACCESS_NETWORK_STATE,
8838 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008839 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008840 mApp.enforceCallingOrSelfPermission(
8841 permission.READ_BASIC_PHONE_STATE, functionName);
8842 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008843 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008844 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008845 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008846 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008847
Pengquan Menga1bb6272018-09-06 09:59:22 -07008848 boolean isEnabled = false;
8849 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008850 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008851 Phone phone = getPhone(subId);
8852 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008853 } finally {
8854 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008855 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008856 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008857 }
8858
8859
8860 /**
8861 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8862 *
8863 * <p> Requires permission:
8864 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8865 * privileges.
8866 *
8867 * @param subId subscription id
8868 * @param isEnabled {@code true} means enable, {@code false} means disable.
8869 */
8870 @Override
8871 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8873 mApp, subId, "setDataRoamingEnabled");
8874
Pengquan Menga1bb6272018-09-06 09:59:22 -07008875 final long identity = Binder.clearCallingIdentity();
8876 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008877 Phone phone = getPhone(subId);
8878 if (phone != null) {
8879 phone.setDataRoamingEnabled(isEnabled);
8880 }
8881 } finally {
8882 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008883 }
8884 }
8885
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008886 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008887 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008888 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008889 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008890 mApp, subId, "isManualNetworkSelectionAllowed");
8891
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008892 boolean isAllowed = true;
8893 final long identity = Binder.clearCallingIdentity();
8894 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008895 Phone phone = getPhone(subId);
8896 if (phone != null) {
8897 isAllowed = phone.isCspPlmnEnabled();
8898 }
8899 } finally {
8900 Binder.restoreCallingIdentity(identity);
8901 }
8902 return isAllowed;
8903 }
8904
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008905 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8906 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008907 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008908 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008909 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008910 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8911 if (phone == null) {
8912 return false;
8913 }
8914 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8915 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8916 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008917 }
8918
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008919 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008920 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008921 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008922 mApp.getSystemService(AppOpsManager.class)
8923 .checkPackage(Binder.getCallingUid(), callingPackage);
8924
Jordan Liu1e142fc2019-04-22 15:10:43 -07008925 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008926 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008927 try {
8928 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008929 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008930 } catch (SecurityException e) {
8931 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8932 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008933 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008934 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008935 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008936 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008937 }
sandeepjsb6c87872021-09-27 15:34:44 +00008938 // checking compatibility, if calling app's target SDK is T and beyond.
8939 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8940 Binder.getCallingUid())) {
8941 isIccIdAccessRestricted = true;
8942 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008943 final long identity = Binder.clearCallingIdentity();
8944 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008945 UiccController uiccController = UiccController.getInstance();
8946 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008947 if (hasReadPermission) {
8948 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008949 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008950
8951 // Remove private info if the caller doesn't have access
8952 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8953 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008954 //setting the value after compatibility check
8955 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008956 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8957 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008958 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008959 if (card == null) {
8960 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008961 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008962 continue;
8963 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008964 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8965 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008966 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008967 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008968 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008969 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8970 for (UiccPortInfo portInfo : portInfos) {
8971 UiccPort port = uiccController.getUiccPortForSlot(
8972 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8973 if (port == null) {
8974 // assume no access if port is null
8975 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8976 continue;
8977 }
8978 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8979 uiccPortInfos.add(portInfo);
8980 } else {
8981 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8982 }
8983 }
8984 filteredInfos.add(new UiccCardInfo(
8985 cardInfo.isEuicc(),
8986 cardInfo.getCardId(),
8987 null,
8988 cardInfo.getPhysicalSlotIndex(),
8989 cardInfo.isRemovable(),
8990 cardInfo.isMultipleEnabledProfilesSupported(),
8991 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008992 }
8993 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008994 } finally {
8995 Binder.restoreCallingIdentity(identity);
8996 }
8997 }
8998
sandeepjsb6c87872021-09-27 15:34:44 +00008999 /**
9000 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9001 * generally private and require carrier privileges to view.
9002 *
9003 * @hide
9004 */
9005 @NonNull
9006 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9007 List<UiccPortInfo> portinfo = new ArrayList<>();
9008 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9009 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9010 }
9011 return new UiccCardInfo(
9012 cardInfo.isEuicc(),
9013 cardInfo.getCardId(),
9014 null,
9015 cardInfo.getPhysicalSlotIndex(),
9016 cardInfo.isRemovable(),
9017 cardInfo.isMultipleEnabledProfilesSupported(),
9018 portinfo
9019 );
9020 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009021
sandeepjsb6c87872021-09-27 15:34:44 +00009022 /**
9023 * @hide
9024 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9025 * These values are generally private and require carrier privileges to view.
9026 */
9027 @NonNull
9028 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9029 return new UiccPortInfo(
9030 UiccPortInfo.ICCID_REDACTED,
9031 portInfo.getPortIndex(),
9032 portInfo.getLogicalSlotIndex(),
9033 portInfo.isActive()
9034 );
9035 }
9036 @Override
9037 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009038 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009039 mApp.getSystemService(AppOpsManager.class)
9040 .checkPackage(Binder.getCallingUid(), callingPackage);
9041
sandeepjsb6c87872021-09-27 15:34:44 +00009042 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009043
Aman Guptaf3c90b32022-03-17 04:54:16 +00009044 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9045 // we are reading iccId which is PII data.
9046 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009047
9048 // checking compatibility, if calling app's target SDK is T and beyond.
9049 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9050 Binder.getCallingUid())) {
9051 isLogicalSlotAccessRestricted = true;
9052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009053 final long identity = Binder.clearCallingIdentity();
9054 try {
9055 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009056 if (slots == null || slots.length == 0) {
9057 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009058 return null;
9059 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009060 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9061 for (int i = 0; i < slots.length; i++) {
9062 UiccSlot slot = slots[i];
9063 if (slot == null) {
9064 continue;
9065 }
9066
Jordan Liu7be7e652019-05-06 18:55:02 +00009067 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009068 UiccCard card = slot.getUiccCard();
9069 if (card != null) {
9070 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009071 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009072 cardId = slot.getEid();
9073 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009074 // If cardId is null, use iccId of default port as cardId.
9075 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009076 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009077 }
9078
Jordan Liu857451f2019-05-09 16:35:35 -07009079 if (cardId != null) {
9080 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9081 // if cardId is an EID, it's all digits so this is fine
9082 cardId = IccUtils.stripTrailingFs(cardId);
9083 }
9084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009085 int cardState = 0;
9086 switch (slot.getCardState()) {
9087 case CARDSTATE_ABSENT:
9088 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9089 break;
9090 case CARDSTATE_PRESENT:
9091 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9092 break;
9093 case CARDSTATE_ERROR:
9094 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9095 break;
9096 case CARDSTATE_RESTRICTED:
9097 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9098 break;
9099 default:
9100 break;
9101
9102 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009103 List<UiccPortInfo> portInfos = new ArrayList<>();
9104 int[] portIndexes = slot.getPortList();
9105 for (int portIdx : portIndexes) {
9106 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009107 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009108 portInfos.add(new UiccPortInfo(iccId, portIdx,
9109 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009111 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009112 slot.isEuicc(),
9113 cardId,
9114 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009115 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009116 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009117 //setting the value after compatibility check
9118 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009119 }
9120 return infos;
9121 } finally {
9122 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009123 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009124 }
9125
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009126 /* Returns null if doesn't have read permission or carrier privilege access. */
9127 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9128 boolean hasReadPermission) {
9129 String iccId = slot.getIccId(portIndex);
9130 if (hasReadPermission) { // if has read permission
9131 return iccId;
9132 } else {
9133 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9134 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9135 // if no read permission, checking carrier privilege access
9136 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9137 return iccId;
9138 }
9139 }
9140 }
9141 // No read permission or carrier privilege access.
9142 return UiccPortInfo.ICCID_REDACTED;
9143 }
9144
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009145 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009146 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009147 public boolean switchSlots(int[] physicalSlots) {
9148 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009149
9150 final long identity = Binder.clearCallingIdentity();
9151 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009152 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9153 for (int i = 0; i < physicalSlots.length; i++) {
9154 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9155 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9156 physicalSlots[i], i));
9157 }
9158 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009159 } finally {
9160 Binder.restoreCallingIdentity(identity);
9161 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009162 }
Jack Yu4c988042018-02-27 15:30:01 -08009163
9164 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009165 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9166 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9167 enforceModifyPermission();
9168
9169 final long identity = Binder.clearCallingIdentity();
9170 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009171 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009172 } finally {
9173 Binder.restoreCallingIdentity(identity);
9174 }
9175 }
9176
9177 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009178 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009179 final long identity = Binder.clearCallingIdentity();
9180 try {
9181 return UiccController.getInstance().getCardIdForDefaultEuicc();
9182 } finally {
9183 Binder.restoreCallingIdentity(identity);
9184 }
9185 }
9186
Pengquan Meng85728fb2018-03-12 16:31:21 -07009187 /**
goneil47ffb6e2018-04-06 15:40:58 -07009188 * A test API to reload the UICC profile.
9189 *
9190 * <p>Requires that the calling app has permission
9191 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9192 * @hide
9193 */
9194 @Override
9195 public void refreshUiccProfile(int subId) {
9196 enforceModifyPermission();
9197
9198 final long identity = Binder.clearCallingIdentity();
9199 try {
9200 Phone phone = getPhone(subId);
9201 if (phone == null) {
9202 return;
9203 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009204 UiccPort uiccPort = phone.getUiccPort();
9205 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009206 return;
9207 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009208 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009209 if (uiccProfile == null) {
9210 return;
9211 }
9212 uiccProfile.refresh();
9213 } finally {
9214 Binder.restoreCallingIdentity(identity);
9215 }
9216 }
9217
9218 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009219 * Returns false if the mobile data is disabled by default, otherwise return true.
9220 */
9221 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009222 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009223 }
9224
9225 /**
9226 * Returns true if the data roaming is enabled by default, i.e the system property
9227 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9228 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9229 */
9230 private boolean getDefaultDataRoamingEnabled(int subId) {
9231 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009232 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009233 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009234 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9235 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9236 return isDataRoamingEnabled;
9237 }
9238
9239 /**
9240 * Returns the default network type for the given {@code subId}, if the default network type is
9241 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9242 */
9243 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009244 List<Integer> list = TelephonyProperties.default_network();
9245 int phoneId = mSubscriptionController.getPhoneId(subId);
9246 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9247 return list.get(phoneId);
9248 }
9249 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009250 }
fionaxua13278b2018-03-21 00:08:13 -07009251
9252 @Override
9253 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009254 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009255 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009256
9257 final long identity = Binder.clearCallingIdentity();
9258 try {
9259 final Phone phone = getPhone(subId);
9260 if (phone == null) {
9261 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9262 return;
9263 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009264 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9265 if (cpt != null) {
9266 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9267 }
9268 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009269 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9270 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009271 if (carrierPrivilegeRules == null) {
9272 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9273 } else {
9274 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009276 } finally {
9277 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009278 }
fionaxua13278b2018-03-21 00:08:13 -07009279 }
9280
9281 @Override
9282 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009283 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009284
9285 final long identity = Binder.clearCallingIdentity();
9286 try {
9287 final Phone phone = getPhone(subId);
9288 if (phone == null) {
9289 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9290 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9291 }
9292 return phone.getCarrierIdListVersion();
9293 } finally {
9294 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009295 }
fionaxua13278b2018-03-21 00:08:13 -07009296 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009297
9298 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009299 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9300 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009302 mApp, subId, callingPackage, callingFeatureId,
9303 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009304 return -1;
9305 }
9306
9307 final long identity = Binder.clearCallingIdentity();
9308 try {
9309 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9310 } finally {
9311 Binder.restoreCallingIdentity(identity);
9312 }
9313 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009314
9315 @Override
9316 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009317 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009318 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009319 mApp, subId, "getCdmaRoamingMode");
9320
9321 final long identity = Binder.clearCallingIdentity();
9322 try {
9323 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9324 } finally {
9325 Binder.restoreCallingIdentity(identity);
9326 }
9327 }
9328
9329 @Override
9330 public boolean setCdmaRoamingMode(int subId, int mode) {
9331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9332 mApp, subId, "setCdmaRoamingMode");
9333
9334 final long identity = Binder.clearCallingIdentity();
9335 try {
9336 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9337 } finally {
9338 Binder.restoreCallingIdentity(identity);
9339 }
9340 }
9341
9342 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009343 public int getCdmaSubscriptionMode(int subId) {
9344 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009345 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009346 mApp, subId, "getCdmaSubscriptionMode");
9347
9348 final long identity = Binder.clearCallingIdentity();
9349 try {
9350 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9351 } finally {
9352 Binder.restoreCallingIdentity(identity);
9353 }
9354 }
9355
9356 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009357 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9359 mApp, subId, "setCdmaSubscriptionMode");
9360
9361 final long identity = Binder.clearCallingIdentity();
9362 try {
9363 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9364 } finally {
9365 Binder.restoreCallingIdentity(identity);
9366 }
9367 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009368
sqianc5eccab2018-10-19 18:46:41 -07009369 @Override
sqian8c685422019-02-22 15:55:18 -08009370 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009371 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009373 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9374 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009375 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9376 }
9377 final long identity = Binder.clearCallingIdentity();
9378 try {
sqian854d44b2018-12-12 16:48:18 -08009379 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9380 for (Phone phone: PhoneFactory.getPhones()) {
9381 if (phone.getEmergencyNumberTracker() != null
9382 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9383 emergencyNumberListInternal.put(
9384 phone.getSubId(),
9385 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9386 }
sqian11b7a0e2018-12-05 18:48:28 -08009387 }
sqian854d44b2018-12-12 16:48:18 -08009388 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009389 } finally {
9390 Binder.restoreCallingIdentity(identity);
9391 }
sqianc5eccab2018-10-19 18:46:41 -07009392 }
9393
9394 @Override
sqian8c685422019-02-22 15:55:18 -08009395 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009396 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009397 if (!exactMatch) {
9398 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009399 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009400 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009401 }
9402 final long identity = Binder.clearCallingIdentity();
9403 try {
sqian854d44b2018-12-12 16:48:18 -08009404 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009405 //Note: we ignore passed in param exactMatch. We can remove it once
9406 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009407 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009408 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009409 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009410 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009411 }
sqian11b7a0e2018-12-05 18:48:28 -08009412 }
9413 return false;
9414 } finally {
9415 Binder.restoreCallingIdentity(identity);
9416 }
9417 }
9418
sqianf4ca7ed2019-01-15 18:32:07 -08009419 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009420 * Start emergency callback mode for GsmCdmaPhone for testing.
9421 */
9422 @Override
9423 public void startEmergencyCallbackMode() {
9424 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9425 "startEmergencyCallbackMode");
9426 enforceModifyPermission();
9427 final long identity = Binder.clearCallingIdentity();
9428 try {
9429 for (Phone phone : PhoneFactory.getPhones()) {
9430 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9431 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9432 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9433 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9434 gsmCdmaPhone.obtainMessage(
9435 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9436 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9437 }
9438 }
9439 } finally {
9440 Binder.restoreCallingIdentity(identity);
9441 }
9442 }
9443
9444 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009445 * Update emergency number list for test mode.
9446 */
9447 @Override
9448 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9449 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9450 "updateEmergencyNumberListTestMode");
9451
9452 final long identity = Binder.clearCallingIdentity();
9453 try {
9454 for (Phone phone: PhoneFactory.getPhones()) {
9455 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9456 if (tracker != null) {
9457 tracker.executeEmergencyNumberTestModeCommand(action, num);
9458 }
9459 }
9460 } finally {
9461 Binder.restoreCallingIdentity(identity);
9462 }
9463 }
9464
9465 /**
9466 * Get the full emergency number list for test mode.
9467 */
9468 @Override
9469 public List<String> getEmergencyNumberListTestMode() {
9470 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9471 "getEmergencyNumberListTestMode");
9472
9473 final long identity = Binder.clearCallingIdentity();
9474 try {
9475 Set<String> emergencyNumbers = new HashSet<>();
9476 for (Phone phone: PhoneFactory.getPhones()) {
9477 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9478 if (tracker != null) {
9479 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9480 emergencyNumbers.add(num.getNumber());
9481 }
9482 }
9483 }
9484 return new ArrayList<>(emergencyNumbers);
9485 } finally {
9486 Binder.restoreCallingIdentity(identity);
9487 }
9488 }
9489
chen xud6b45bd2018-10-30 22:27:10 -07009490 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009491 public int getEmergencyNumberDbVersion(int subId) {
9492 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9493
9494 final long identity = Binder.clearCallingIdentity();
9495 try {
9496 final Phone phone = getPhone(subId);
9497 if (phone == null) {
9498 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9499 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9500 }
9501 return phone.getEmergencyNumberDbVersion();
9502 } finally {
9503 Binder.restoreCallingIdentity(identity);
9504 }
9505 }
9506
9507 @Override
9508 public void notifyOtaEmergencyNumberDbInstalled() {
9509 enforceModifyPermission();
9510
9511 final long identity = Binder.clearCallingIdentity();
9512 try {
9513 for (Phone phone: PhoneFactory.getPhones()) {
9514 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9515 if (tracker != null) {
9516 tracker.updateOtaEmergencyNumberDatabase();
9517 }
9518 }
9519 } finally {
9520 Binder.restoreCallingIdentity(identity);
9521 }
9522 }
9523
9524 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009525 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009526 enforceActiveEmergencySessionPermission();
9527
9528 final long identity = Binder.clearCallingIdentity();
9529 try {
9530 for (Phone phone: PhoneFactory.getPhones()) {
9531 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9532 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009533 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9534 }
9535 }
9536 } finally {
9537 Binder.restoreCallingIdentity(identity);
9538 }
9539 }
9540
9541 @Override
9542 public void resetOtaEmergencyNumberDbFilePath() {
9543 enforceActiveEmergencySessionPermission();
9544
9545 final long identity = Binder.clearCallingIdentity();
9546 try {
9547 for (Phone phone: PhoneFactory.getPhones()) {
9548 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9549 if (tracker != null) {
9550 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009551 }
9552 }
9553 } finally {
9554 Binder.restoreCallingIdentity(identity);
9555 }
9556 }
9557
9558 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009559 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9560 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9561 Phone phone = getPhone(subId);
9562 if (phone == null) {
9563 return null;
9564 }
9565 final long identity = Binder.clearCallingIdentity();
9566 try {
9567 UiccProfile profile = UiccController.getInstance()
9568 .getUiccProfileForPhone(phone.getPhoneId());
9569 if (profile != null) {
9570 return profile.getCertsFromCarrierPrivilegeAccessRules();
9571 }
9572 } finally {
9573 Binder.restoreCallingIdentity(identity);
9574 }
9575 return null;
9576 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009577
9578 /**
9579 * Enable or disable a modem stack.
9580 */
9581 @Override
9582 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9583 enforceModifyPermission();
9584
9585 final long identity = Binder.clearCallingIdentity();
9586 try {
9587 Phone phone = PhoneFactory.getPhone(slotIndex);
9588 if (phone == null) {
9589 return false;
9590 } else {
9591 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9592 }
9593 } finally {
9594 Binder.restoreCallingIdentity(identity);
9595 }
9596 }
Michelecea4cf22018-12-21 15:00:11 -08009597
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009598 /**
9599 * Whether a modem stack is enabled or not.
9600 */
9601 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009602 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9603 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009604 Phone phone = PhoneFactory.getPhone(slotIndex);
9605 if (phone == null) return false;
9606
9607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009608 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9609 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009610 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9611 }
9612
9613 final long identity = Binder.clearCallingIdentity();
9614 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009615 try {
9616 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9617 } catch (NoSuchElementException ex) {
9618 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9619 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009620 } finally {
9621 Binder.restoreCallingIdentity(identity);
9622 }
9623 }
9624
Michelecea4cf22018-12-21 15:00:11 -08009625 @Override
Michele0ea7d782019-03-19 14:58:42 -07009626 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009627 enforceModifyPermission();
9628
9629 final long identity = Binder.clearCallingIdentity();
9630 try {
9631 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009632 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009633 .commit();
9634 } finally {
9635 Binder.restoreCallingIdentity(identity);
9636 }
9637 }
9638
9639 @Override
Michele0ea7d782019-03-19 14:58:42 -07009640 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009641 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009642 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009643 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9644 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009645 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009646 }
Michelecea4cf22018-12-21 15:00:11 -08009647
9648 final long identity = Binder.clearCallingIdentity();
9649 try {
Michele0ea7d782019-03-19 14:58:42 -07009650 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009651 } finally {
9652 Binder.restoreCallingIdentity(identity);
9653 }
9654 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009655
Michele0ea7d782019-03-19 14:58:42 -07009656 @TelephonyManager.IsMultiSimSupportedResult
9657 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009658 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9659 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9660 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009661 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9662 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009663 }
9664 // Check if the hardware supports multisim functionality. If usage of multisim is not
9665 // supported by the modem, indicate that it is restricted.
9666 PhoneCapability staticCapability =
9667 mPhoneConfigurationManager.getStaticPhoneCapability();
9668 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009669 loge("isMultiSimSupportedInternal: no static configuration available");
9670 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009671 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009672 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009673 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9674 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009675 }
9676 // Check if support of multiple SIMs is restricted by carrier
9677 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009678 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009679 }
9680
Michele0ea7d782019-03-19 14:58:42 -07009681 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009682 }
9683
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009684 /**
9685 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009686 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9687 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9688 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009689 * @param numOfSims number of active sims we want to switch to
9690 */
9691 @Override
9692 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009693 if (numOfSims == 1) {
9694 enforceModifyPermission();
9695 } else {
9696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9697 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9698 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009699 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009700
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009701 try {
Michele30b57b22019-03-01 12:01:14 -08009702 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009703 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009704 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9705 return;
9706 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009707 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9708 } finally {
9709 Binder.restoreCallingIdentity(identity);
9710 }
9711 }
9712
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009713 @Override
9714 public boolean isApplicationOnUicc(int subId, int appType) {
9715 enforceReadPrivilegedPermission("isApplicationOnUicc");
9716 Phone phone = getPhone(subId);
9717 if (phone == null) {
9718 return false;
9719 }
9720 final long identity = Binder.clearCallingIdentity();
9721 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009722 UiccPort uiccPort = phone.getUiccPort();
9723 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009724 return false;
9725 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009726 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009727 if (uiccProfile == null) {
9728 return false;
9729 }
9730 if (TelephonyManager.APPTYPE_SIM <= appType
9731 && appType <= TelephonyManager.APPTYPE_ISIM) {
9732 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9733 }
9734 return false;
9735 } finally {
9736 Binder.restoreCallingIdentity(identity);
9737 }
9738 }
9739
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009740 /**
chen xub4baa772019-04-03 10:23:41 -07009741 * Get whether making changes to modem configurations will trigger reboot.
9742 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009743 */
9744 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009745 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9746 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009747 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009748 mApp, subId, callingPackage, callingFeatureId,
9749 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009750 return false;
9751 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009752 final long identity = Binder.clearCallingIdentity();
9753 try {
9754 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9755 } finally {
9756 Binder.restoreCallingIdentity(identity);
9757 }
9758 }
9759
Nathan Harold29f5f052019-02-15 13:41:57 -08009760 private void updateModemStateMetrics() {
9761 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9762 // TODO: check the state for each modem if the api is ready.
9763 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9764 }
9765
Pengquan Meng3889a572019-01-23 11:16:29 -08009766 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009767 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009768 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009769 // Verify that the callingPackage belongs to the calling UID
9770 mApp.getSystemService(AppOpsManager.class)
9771 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009772 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009773 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009774 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009775 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9776 if (slotInfos != null) {
9777 for (int i = 0; i < slotInfos.length; i++) {
9778 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9779 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9780 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9781 portInfo.getLogicalSlotIndex()));
9782 }
9783 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009784 }
9785 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009786 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009787 } finally {
9788 Binder.restoreCallingIdentity(identity);
9789 }
9790 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009791
9792 /**
9793 * Get the IRadio HAL Version
9794 */
9795 @Override
9796 public int getRadioHalVersion() {
9797 Phone phone = getDefaultPhone();
9798 if (phone == null) return -1;
9799 HalVersion hv = phone.getHalVersion();
9800 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9801 return hv.major * 100 + hv.minor;
9802 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009803
9804 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009805 * Get the current calling package name.
9806 * @return the current calling package name
9807 */
9808 @Override
9809 public String getCurrentPackageName() {
9810 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9811 }
9812
9813 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009814 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9815 * corresponding network requests on a subId.
9816 *
9817 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009818 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009819 * 2) APN is un-metered for this subscription, or
9820 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009821 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009822 *
9823 * @return whether data is allowed for a apn type.
9824 *
9825 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009826 */
9827 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009828 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009829 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9830 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009831
9832 // Now that all security checks passes, perform the operation as ourselves.
9833 final long identity = Binder.clearCallingIdentity();
9834 try {
9835 Phone phone = getPhone(subId);
9836 if (phone == null) return false;
9837
Jack Yu27422a52022-03-21 10:38:05 -07009838 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009839 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009840 isMetered = phone.getDataNetworkController().getDataConfigManager()
9841 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9842 phone.getServiceState().getDataRoaming());
9843 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009844 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009845 } finally {
9846 Binder.restoreCallingIdentity(identity);
9847 }
9848 }
9849
9850 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009851 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009852 enforceReadPrivilegedPermission("isApnMetered");
9853
9854 // Now that all security checks passes, perform the operation as ourselves.
9855 final long identity = Binder.clearCallingIdentity();
9856 try {
9857 Phone phone = getPhone(subId);
9858 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009859 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9860 DataUtils.apnTypeToNetworkCapability(apnType),
9861 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009862 } finally {
9863 Binder.restoreCallingIdentity(identity);
9864 }
9865 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009866
9867 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009868 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9869 int subscriptionId, IBooleanConsumer resultCallback) {
9870 enforceModifyPermission();
9871 long token = Binder.clearCallingIdentity();
9872 try {
9873 Phone phone = getPhone(subscriptionId);
9874 if (phone == null) {
9875 try {
9876 if (resultCallback != null) {
9877 resultCallback.accept(false);
9878 }
9879 } catch (RemoteException e) {
9880 // ignore
9881 }
9882 return;
9883 }
9884 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9885 Pair.create(specifiers, (x) -> {
9886 try {
9887 if (resultCallback != null) {
9888 resultCallback.accept(x);
9889 }
9890 } catch (RemoteException e) {
9891 // ignore
9892 }
9893 });
9894 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9895 } finally {
9896 Binder.restoreCallingIdentity(token);
9897 }
9898 }
9899
9900 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009901 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9902 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009903 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009904 mApp, subId, "getSystemSelectionChannels");
9905 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9906 final long identity = Binder.clearCallingIdentity();
9907 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009908 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9909 if (result instanceof IllegalStateException) {
9910 throw (IllegalStateException) result;
9911 }
9912 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009913 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9914 return specifiers;
9915 } finally {
9916 Binder.restoreCallingIdentity(identity);
9917 }
9918 }
9919
9920 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009921 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009922 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009923 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009924 }
9925
9926 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009927 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9928 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009929 if (callingPackage == null) {
9930 callingPackage = getCurrentPackageName();
9931 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009932 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9933 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009934 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9935 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009936 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9937 }
9938 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9939 Intent intent = new Intent();
9940 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9941 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9942 // Bring up choose default SMS subscription dialog right now
9943 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9944 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9945 mApp.startActivity(intent);
9946 }
chen xud5ca2d52019-05-28 15:20:57 -07009947
9948 @Override
9949 public String getMmsUAProfUrl(int subId) {
9950 //TODO investigate if this API should require proper permission check in R b/133791609
9951 final long identity = Binder.clearCallingIdentity();
9952 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009953 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9954 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9955 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9956 return carrierUAProfUrl;
9957 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009958 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9959 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009960 } finally {
9961 Binder.restoreCallingIdentity(identity);
9962 }
9963 }
9964
9965 @Override
9966 public String getMmsUserAgent(int subId) {
9967 //TODO investigate if this API should require proper permission check in R b/133791609
9968 final long identity = Binder.clearCallingIdentity();
9969 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009970 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9971 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9972 if (!TextUtils.isEmpty(carrierUserAgent)) {
9973 return carrierUserAgent;
9974 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009975 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9976 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009977 } finally {
9978 Binder.restoreCallingIdentity(identity);
9979 }
9980 }
Jack Yub07d4972019-05-28 16:12:25 -07009981
9982 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009983 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9984 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009985
Jack Yub07d4972019-05-28 16:12:25 -07009986 final long identity = Binder.clearCallingIdentity();
9987 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009988 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009989 if (phone == null) return false;
9990
Ling Maf188d502022-09-16 15:22:36 -07009991 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -07009992 } finally {
9993 Binder.restoreCallingIdentity(identity);
9994 }
9995 }
9996
9997 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009998 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009999 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010000 enforceModifyPermission();
10001
changbettyd5c246e2019-12-24 15:40:37 +080010002 final long identity = Binder.clearCallingIdentity();
10003 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010004 Phone phone = getPhone(subscriptionId);
10005 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010006
Ling Maf188d502022-09-16 15:22:36 -070010007 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010008 } finally {
10009 Binder.restoreCallingIdentity(identity);
10010 }
10011 }
10012
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010013 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010014 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010015 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10016 * otherwise.
10017 */
10018 @Override
10019 public void setCepEnabled(boolean isCepEnabled) {
10020 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10021
10022 final long identity = Binder.clearCallingIdentity();
10023 try {
10024 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10025 for (Phone phone : PhoneFactory.getPhones()) {
10026 Phone defaultPhone = phone.getImsPhone();
10027 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10028 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10029 ImsPhoneCallTracker imsPhoneCallTracker =
10030 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10031 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10032 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10033 + imsPhone.getMsisdn());
10034 }
10035 }
10036 } finally {
10037 Binder.restoreCallingIdentity(identity);
10038 }
10039 }
allenwtsu46dcc572020-01-08 18:24:03 +080010040
10041 /**
10042 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10043 *
10044 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10045 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10046 * before being read.
10047 */
10048 @Override
10049 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10050 isCompressed) {
10051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10052 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010053 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10054 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10055 }
10056 if (!isImsAvailableOnDevice()) {
10057 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10058 "IMS not available on device.");
10059 }
10060
10061 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010062 try {
Hui Wang761a6682020-10-31 05:12:53 +000010063 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10064 } finally {
10065 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010066 }
10067 }
zoey chene02881a2019-12-30 16:11:23 +080010068
10069 @Override
10070 public boolean isIccLockEnabled(int subId) {
10071 enforceReadPrivilegedPermission("isIccLockEnabled");
10072
10073 // Now that all security checks passes, perform the operation as ourselves.
10074 final long identity = Binder.clearCallingIdentity();
10075 try {
10076 Phone phone = getPhone(subId);
10077 if (phone != null && phone.getIccCard() != null) {
10078 return phone.getIccCard().getIccLockEnabled();
10079 } else {
10080 return false;
10081 }
10082 } finally {
10083 Binder.restoreCallingIdentity(identity);
10084 }
10085 }
10086
10087 /**
10088 * Set the ICC pin lock enabled or disabled.
10089 *
10090 * @return an integer representing the status of IccLock enabled or disabled in the following
10091 * three cases:
10092 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10093 * successfully.
10094 * - Positive number and zero for remaining password attempts.
10095 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10096 *
10097 */
10098 @Override
10099 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10100 enforceModifyPermission();
10101
10102 Phone phone = getPhone(subId);
10103 if (phone == null) {
10104 return 0;
10105 }
10106 // Now that all security checks passes, perform the operation as ourselves.
10107 final long identity = Binder.clearCallingIdentity();
10108 try {
10109 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10110 new Pair<Boolean, String>(enabled, password), phone, null);
10111 return attemptsRemaining;
10112
10113 } catch (Exception e) {
10114 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10115 } finally {
10116 Binder.restoreCallingIdentity(identity);
10117 }
10118 return 0;
10119 }
10120
10121 /**
10122 * Change the ICC password used in ICC pin lock.
10123 *
10124 * @return an integer representing the status of IccLock changed in the following three cases:
10125 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10126 * - Positive number and zero for remaining password attempts.
10127 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10128 *
10129 */
10130 @Override
10131 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10132 enforceModifyPermission();
10133
10134 Phone phone = getPhone(subId);
10135 if (phone == null) {
10136 return 0;
10137 }
10138 // Now that all security checks passes, perform the operation as ourselves.
10139 final long identity = Binder.clearCallingIdentity();
10140 try {
10141 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10142 new Pair<String, String>(oldPassword, newPassword), phone, null);
10143 return attemptsRemaining;
10144
10145 } catch (Exception e) {
10146 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10147 } finally {
10148 Binder.restoreCallingIdentity(identity);
10149 }
10150 return 0;
10151 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010152
10153 /**
10154 * Request for receiving user activity notification
10155 */
10156 @Override
10157 public void requestUserActivityNotification() {
10158 if (!mNotifyUserActivity.get()
10159 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10160 mNotifyUserActivity.set(true);
10161 }
10162 }
10163
10164 /**
10165 * Called when userActivity is signalled in the power manager.
10166 * This is safe to call from any thread, with any window manager locks held or not.
10167 */
10168 @Override
10169 public void userActivity() {
10170 // ***************************************
10171 // * Inherited from PhoneWindowManager *
10172 // ***************************************
10173 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10174 // WITH ITS LOCKS HELD.
10175 //
10176 // This code must be VERY careful about the locks
10177 // it acquires.
10178 // In fact, the current code acquires way too many,
10179 // and probably has lurking deadlocks.
10180
10181 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10182 throw new SecurityException("Only the OS may call notifyUserActivity()");
10183 }
10184
10185 if (mNotifyUserActivity.getAndSet(false)) {
10186 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10187 USER_ACTIVITY_NOTIFICATION_DELAY);
10188 }
10189 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010190
10191 @Override
10192 public boolean canConnectTo5GInDsdsMode() {
10193 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10194 }
Jack Yud10cdd42020-09-28 20:28:01 -070010195
10196 @Override
10197 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10198 String callingFeatureId) {
10199 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10200 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10201 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10202 }
10203
10204 Phone phone = getPhone(subId);
10205 if (phone == null) {
10206 throw new RuntimeException("phone is not available");
10207 }
10208 // Now that all security checks passes, perform the operation as ourselves.
10209 final long identity = Binder.clearCallingIdentity();
10210 try {
10211 return phone.getEquivalentHomePlmns();
10212 } finally {
10213 Binder.restoreCallingIdentity(identity);
10214 }
10215 }
Daniel Bright59e67312020-11-13 11:49:37 -080010216
10217 @Override
10218 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010219 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10220 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010221 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010222 if (radioInterfaceCapabilities == null) {
10223 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010224 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010225 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010226 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010227
Hui Wang641e81c2020-10-12 12:14:23 -070010228 @Override
10229 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10230 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010231 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10232 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10233 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10234 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10235 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010236 if (DBG) {
10237 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10238 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10239 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10240 }
10241
10242 if (!SubscriptionManager.isValidSubscriptionId(subId)
10243 || appType < TelephonyManager.APPTYPE_UNKNOWN
10244 || appType > TelephonyManager.APPTYPE_ISIM
10245 || nafUrl == null || securityProtocol == null || callback == null) {
10246 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10247 if (callback != null) {
10248 try {
10249 callback.onAuthenticationFailure(
10250 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10251 } catch (RemoteException exception) {
10252 log("Fail to notify onAuthenticationFailure due to " + exception);
10253 }
10254 return;
10255 }
10256 }
10257
10258 final long token = Binder.clearCallingIdentity();
10259 try {
10260 getGbaManager(subId).bootstrapAuthenticationRequest(
10261 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10262 forceBootStrapping, callback));
10263 } finally {
10264 Binder.restoreCallingIdentity(token);
10265 }
10266 }
10267
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010268 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010269 * Attempts to set the radio power state for all phones for thermal reason.
10270 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010271 * requested radio power state will actually be set. See {@link
10272 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10273 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010274 * @param enable {@code true} if trying to turn radio on.
10275 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10276 * false}.
10277 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010278 private boolean setRadioPowerForThermal(boolean enable) {
10279 boolean isPhoneAvailable = false;
10280 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10281 Phone phone = PhoneFactory.getPhone(i);
10282 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010283 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010284 isPhoneAvailable = true;
10285 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010286 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010287
10288 // return true if successfully informed the phone object about the thermal radio power
10289 // request.
10290 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010291 }
10292
10293 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010294 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010295 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10296 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10297 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10298 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10299 throw new IllegalArgumentException("modem does not support data throttling");
10300 }
10301
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010302 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10303 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010304 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010305 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10306 }
10307
Sarah Chinecc78c42022-03-31 21:16:48 -070010308 setDataEnabledForReason(
10309 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010310
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010311 if (isDataThrottlingSupported) {
10312 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010313 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010314 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10315 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10316 } else if (thermalMitigationResult
10317 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010318 log("Modem likely does not support data throttling on secondary carrier. Data " +
10319 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10320 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010321 }
10322 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010323 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010324
10325 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010326 }
10327
Jack Nudelman644b91a2021-03-12 14:09:48 -080010328 private static List<String> getThermalMitigationAllowlist(Context context) {
10329 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10330 for (String pckg : context.getResources()
10331 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10332 sThermalMitigationAllowlistedPackages.add(pckg);
10333 }
10334 }
10335
10336 return sThermalMitigationAllowlistedPackages;
10337 }
10338
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010339 private boolean isAnyPhoneInEmergencyState() {
10340 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10341 if (tm.isInEmergencyCall()) {
10342 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10343 return true;
10344 }
10345 for (Phone phone : PhoneFactory.getPhones()) {
10346 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10347 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10348 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10349 + phone.isInEcm());
10350 return true;
10351 }
10352 }
10353
10354 return false;
10355 }
10356
Jack Nudelman644b91a2021-03-12 14:09:48 -080010357 /**
10358 * Used by shell commands to add an authorized package name for thermal mitigation.
10359 * @param packageName name of package to be allowlisted
10360 * @param context
10361 */
10362 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10363 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10364 sThermalMitigationAllowlistedPackages.add(packageName);
10365 }
10366
10367 /**
10368 * Used by shell commands to remove an authorized package name for thermal mitigation.
10369 * @param packageName name of package to remove from allowlist
10370 * @param context
10371 */
10372 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10373 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10374 sThermalMitigationAllowlistedPackages.remove(packageName);
10375 }
10376
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010377 /**
10378 * Thermal mitigation request to control functionalities at modem.
10379 *
10380 * @param subId the id of the subscription.
10381 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010382 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010383 *
10384 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10385 */
10386 @Override
10387 @ThermalMitigationResult
10388 public int sendThermalMitigationRequest(
10389 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010390 ThermalMitigationRequest thermalMitigationRequest,
10391 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010392 enforceModifyPermission();
10393
Jack Nudelman644b91a2021-03-12 14:09:48 -080010394 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10395 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10396 .contains(callingPackage)) {
10397 throw new SecurityException("Calling package must be configured in the device config. "
10398 + "calling package: " + callingPackage);
10399 }
10400
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010401 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10402 final long identity = Binder.clearCallingIdentity();
10403
10404 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10405 try {
10406 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10407 switch (thermalMitigationAction) {
10408 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10409 thermalMitigationResult =
10410 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010411 thermalMitigationRequest.getDataThrottlingRequest(),
10412 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010413 break;
10414 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10415 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10416 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10417 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10418 }
10419
10420 // Ensure that radio is on. If not able to power on due to phone being
10421 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010422 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010423 thermalMitigationResult =
10424 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10425 break;
10426 }
10427
10428 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010429 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010430 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10431 break;
10432 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10433 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10434 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10435 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10436 }
10437
10438 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10439 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010440 Phone phone = getPhone(subId);
10441 if (phone == null) {
10442 thermalMitigationResult =
10443 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10444 break;
10445 }
10446
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010447 TelephonyConnectionService service =
10448 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010449 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010450 Log.e(LOG_TAG, "An emergency call is pending");
10451 thermalMitigationResult =
10452 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10453 break;
10454 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010455 thermalMitigationResult =
10456 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10457 break;
10458 }
10459 } else {
10460 thermalMitigationResult =
10461 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10462 break;
10463 }
10464
10465 // Turn radio off. If not able to power off due to phone being unavailable,
10466 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010467 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010468 thermalMitigationResult =
10469 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10470 break;
10471 }
10472 thermalMitigationResult =
10473 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10474 break;
10475 default:
10476 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10477 + "not exist. Requested action: " + thermalMitigationAction);
10478 }
10479 } catch (IllegalArgumentException e) {
10480 throw e;
10481 } catch (Exception e) {
10482 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10483 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10484 } finally {
10485 Binder.restoreCallingIdentity(identity);
10486 }
10487
10488 if (DBG) {
10489 log("thermalMitigationRequest returning with thermalMitigationResult: "
10490 + thermalMitigationResult);
10491 }
10492
10493 return thermalMitigationResult;
10494 }
Hui Wang641e81c2020-10-12 12:14:23 -070010495
10496 /**
10497 * Set the GbaService Package Name that Telephony will bind to.
10498 *
10499 * @param subId The sim that the GbaService is associated with.
10500 * @param packageName The name of the package to be replaced with.
10501 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10502 */
10503 @Override
10504 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10505 enforceModifyPermission();
10506
10507 final long identity = Binder.clearCallingIdentity();
10508 try {
10509 return getGbaManager(subId).overrideServicePackage(packageName);
10510 } finally {
10511 Binder.restoreCallingIdentity(identity);
10512 }
10513 }
10514
10515 /**
10516 * Return the package name of the currently bound GbaService.
10517 *
10518 * @param subId The sim that the GbaService is associated with.
10519 * @return the package name of the GbaService configuration, null if GBA is not supported.
10520 */
10521 @Override
10522 public String getBoundGbaService(int subId) {
10523 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10524
10525 final long identity = Binder.clearCallingIdentity();
10526 try {
10527 return getGbaManager(subId).getServicePackage();
10528 } finally {
10529 Binder.restoreCallingIdentity(identity);
10530 }
10531 }
10532
10533 /**
10534 * Set the release time for telephony to unbind GbaService.
10535 *
10536 * @param subId The sim that the GbaService is associated with.
10537 * @param interval The release time to unbind GbaService by millisecond.
10538 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10539 */
10540 @Override
10541 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10542 enforceModifyPermission();
10543
10544 final long identity = Binder.clearCallingIdentity();
10545 try {
10546 return getGbaManager(subId).overrideReleaseTime(interval);
10547 } finally {
10548 Binder.restoreCallingIdentity(identity);
10549 }
10550 }
10551
10552 /**
10553 * Return the release time for telephony to unbind GbaService.
10554 *
10555 * @param subId The sim that the GbaService is associated with.
10556 * @return The release time to unbind GbaService by millisecond.
10557 */
10558 @Override
10559 public int getGbaReleaseTime(int subId) {
10560 enforceReadPrivilegedPermission("getGbaReleaseTime");
10561
10562 final long identity = Binder.clearCallingIdentity();
10563 try {
10564 return getGbaManager(subId).getReleaseTime();
10565 } finally {
10566 Binder.restoreCallingIdentity(identity);
10567 }
10568 }
10569
10570 private GbaManager getGbaManager(int subId) {
10571 GbaManager instance = GbaManager.getInstance(subId);
10572 if (instance == null) {
10573 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10574 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10575 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10576 }
10577 return instance;
10578 }
Hui Wang761a6682020-10-31 05:12:53 +000010579
10580 /**
10581 * indicate whether the device and the carrier can support
10582 * RCS VoLTE single registration.
10583 */
10584 @Override
10585 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010586 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10587 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10588 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10589 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010590
10591 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10592 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10593 }
10594
10595 final long identity = Binder.clearCallingIdentity();
10596 try {
10597 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10598 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010599 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10600 if (isCapable != null) {
10601 return isCapable;
10602 }
Hui Wang761a6682020-10-31 05:12:53 +000010603 }
Hui Wang67af90e2021-06-04 16:57:15 -070010604 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10605 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010606 } finally {
10607 Binder.restoreCallingIdentity(identity);
10608 }
10609 }
10610
10611 /**
10612 * Register RCS provisioning callback.
10613 */
10614 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010615 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010616 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010617 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010618 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010619 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10620 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010621
10622 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10623 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10624 }
10625 if (!isImsAvailableOnDevice()) {
10626 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10627 "IMS not available on device.");
10628 }
10629
10630 final long identity = Binder.clearCallingIdentity();
10631 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010632 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010633 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010634 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10635 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010636 }
Hui Wang761a6682020-10-31 05:12:53 +000010637 } finally {
10638 Binder.restoreCallingIdentity(identity);
10639 }
10640 }
10641
10642 /**
10643 * Unregister RCS provisioning callback.
10644 */
10645 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010646 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010647 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010648 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010649 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010650 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10651 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010652
10653 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10654 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10655 }
10656 if (!isImsAvailableOnDevice()) {
10657 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10658 "IMS not available on device.");
10659 }
10660
10661 final long identity = Binder.clearCallingIdentity();
10662 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010663 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010664 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010665 } finally {
10666 Binder.restoreCallingIdentity(identity);
10667 }
10668 }
10669
10670 /**
10671 * trigger RCS reconfiguration.
10672 */
10673 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010674 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10675 "triggerRcsReconfiguration",
10676 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010677
10678 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10679 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10680 }
10681 if (!isImsAvailableOnDevice()) {
10682 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10683 "IMS not available on device.");
10684 }
10685
10686 final long identity = Binder.clearCallingIdentity();
10687 try {
10688 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10689 } finally {
10690 Binder.restoreCallingIdentity(identity);
10691 }
10692 }
10693
10694 /**
10695 * Provide the client configuration parameters of the RCS application.
10696 */
10697 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010698 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10699 "setRcsClientConfiguration",
10700 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010701
10702 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10703 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10704 }
10705 if (!isImsAvailableOnDevice()) {
10706 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10707 "IMS not available on device.");
10708 }
10709
10710 final long identity = Binder.clearCallingIdentity();
10711
10712 try {
10713 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10714 if (configBinder == null) {
10715 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010716 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10717 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010718 } else {
10719 configBinder.setRcsClientConfiguration(rcc);
10720 }
joonhunshin3e154242021-09-17 06:33:39 +000010721
10722 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10723 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010724 } catch (RemoteException e) {
10725 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010726 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10727 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010728 } finally {
10729 Binder.restoreCallingIdentity(identity);
10730 }
10731 }
10732
10733 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010734 * Enables or disables the test mode for RCS VoLTE single registration.
10735 */
10736 @Override
10737 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10738 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10739 "setRcsSingleRegistrationTestModeEnabled");
10740
10741 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10742 }
10743
10744 /**
10745 * Gets the test mode for RCS VoLTE single registration.
10746 */
10747 @Override
10748 public boolean getRcsSingleRegistrationTestModeEnabled() {
10749 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10750 "getRcsSingleRegistrationTestModeEnabled");
10751
10752 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10753 }
10754
10755 /**
Hui Wang761a6682020-10-31 05:12:53 +000010756 * Overrides the config of RCS VoLTE single registration enabled for the device.
10757 */
10758 @Override
10759 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10760 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10761 "setDeviceSingleRegistrationEnabledOverride");
10762 enforceModifyPermission();
10763
10764 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10765 : Boolean.parseBoolean(enabledStr);
10766 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010767 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010768 }
10769
10770 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010771 * Sends a device to device communication message. Only usable via shell.
10772 * @param message message to send.
10773 * @param value message value.
10774 */
10775 @Override
10776 public void sendDeviceToDeviceMessage(int message, int value) {
10777 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010778 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010779 enforceModifyPermission();
10780
10781 final long identity = Binder.clearCallingIdentity();
10782 try {
10783 TelephonyConnectionService service =
10784 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10785 if (service == null) {
10786 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10787 return;
10788 }
10789 service.sendTestDeviceToDeviceMessage(message, value);
10790 } finally {
10791 Binder.restoreCallingIdentity(identity);
10792 }
10793 }
10794
Tyler Gunnbabbda02021-02-10 11:05:02 -080010795 /**
10796 * Sets the specified device to device transport active.
10797 * @param transport The transport to set active.
10798 */
10799 @Override
10800 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10801 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10802 "setActiveDeviceToDeviceTransport");
10803 enforceModifyPermission();
10804
10805 final long identity = Binder.clearCallingIdentity();
10806 try {
10807 TelephonyConnectionService service =
10808 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10809 if (service == null) {
10810 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10811 return;
10812 }
10813 service.setActiveDeviceToDeviceTransport(transport);
10814 } finally {
10815 Binder.restoreCallingIdentity(identity);
10816 }
10817 }
Tyler Gunn92479152021-01-20 16:30:10 -080010818
Tyler Gunnd4339262021-05-03 14:46:49 -070010819 @Override
10820 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10821 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10822 "setDeviceToDeviceForceEnabled");
10823
10824 final long identity = Binder.clearCallingIdentity();
10825 try {
10826 Arrays.stream(PhoneFactory.getPhones()).forEach(
10827 p -> {
10828 Phone thePhone = p.getImsPhone();
10829 if (thePhone != null && thePhone instanceof ImsPhone) {
10830 ImsPhone imsPhone = (ImsPhone) thePhone;
10831 CallTracker tracker = imsPhone.getCallTracker();
10832 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10833 ImsPhoneCallTracker imsPhoneCallTracker =
10834 (ImsPhoneCallTracker) tracker;
10835 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10836 }
10837 }
10838 }
10839 );
10840 } finally {
10841 Binder.restoreCallingIdentity(identity);
10842 }
10843 }
10844
Tyler Gunn92479152021-01-20 16:30:10 -080010845 /**
Hui Wang761a6682020-10-31 05:12:53 +000010846 * Gets the config of RCS VoLTE single registration enabled for the device.
10847 */
10848 @Override
10849 public boolean getDeviceSingleRegistrationEnabled() {
10850 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10851 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10852 }
10853
10854 /**
10855 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10856 */
10857 @Override
10858 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10859 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10860 "setCarrierSingleRegistrationEnabledOverride");
10861 enforceModifyPermission();
10862
10863 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10864 : Boolean.parseBoolean(enabledStr);
10865 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10866 subId, enabled);
10867 }
10868
10869 /**
10870 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10871 */
10872 @Override
10873 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10874 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10875 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10876 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010877
10878 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010879 * Overrides the ims feature validation result
10880 */
10881 @Override
10882 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10883 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10884 "setImsFeatureValidationOverride");
10885
10886 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10887 : Boolean.parseBoolean(enabledStr);
10888 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10889 subId, enabled);
10890 }
10891
10892 /**
10893 * Gets the ims feature validation override value
10894 */
10895 @Override
10896 public boolean getImsFeatureValidationOverride(int subId) {
10897 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10898 "getImsFeatureValidationOverride");
10899 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10900 }
10901
10902 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010903 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10904 * their mobile plan.
10905 */
10906 @Override
10907 public String getMobileProvisioningUrl() {
10908 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10909 final long identity = Binder.clearCallingIdentity();
10910 try {
10911 return getDefaultPhone().getMobileProvisioningUrl();
10912 } finally {
10913 Binder.restoreCallingIdentity(identity);
10914 }
10915 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010916
James.cf Linbcdf8b32021-01-14 16:44:13 +080010917 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010918 * Get the EAB contact from the EAB database.
10919 */
10920 @Override
10921 public String getContactFromEab(String contact) {
10922 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10923 enforceModifyPermission();
10924 final long identity = Binder.clearCallingIdentity();
10925 try {
10926 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10927 } finally {
10928 Binder.restoreCallingIdentity(identity);
10929 }
10930 }
10931
10932 /**
Calvin Pana1434322021-07-01 19:27:01 +080010933 * Get the EAB capability from the EAB database.
10934 */
10935 @Override
10936 public String getCapabilityFromEab(String contact) {
10937 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10938 enforceModifyPermission();
10939 final long identity = Binder.clearCallingIdentity();
10940 try {
10941 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10942 } finally {
10943 Binder.restoreCallingIdentity(identity);
10944 }
10945 }
10946
10947 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010948 * Remove the EAB contacts from the EAB database.
10949 */
10950 @Override
10951 public int removeContactFromEab(int subId, String contacts) {
10952 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10953 enforceModifyPermission();
10954 final long identity = Binder.clearCallingIdentity();
10955 try {
10956 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10957 } finally {
10958 Binder.restoreCallingIdentity(identity);
10959 }
10960 }
10961
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010962 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010963 public boolean getDeviceUceEnabled() {
10964 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10965 final long identity = Binder.clearCallingIdentity();
10966 try {
10967 return mApp.getDeviceUceEnabled();
10968 } finally {
10969 Binder.restoreCallingIdentity(identity);
10970 }
10971 }
10972
10973 @Override
10974 public void setDeviceUceEnabled(boolean isEnabled) {
10975 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10976 final long identity = Binder.clearCallingIdentity();
10977 try {
10978 mApp.setDeviceUceEnabled(isEnabled);
10979 } finally {
10980 Binder.restoreCallingIdentity(identity);
10981 }
10982 }
10983
Brad Ebinger14d467f2021-02-12 06:18:28 +000010984 /**
10985 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10986 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10987 */
10988 // Used for SHELL command only right now.
10989 @Override
10990 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10991 List<String> featureTags) {
10992 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10993 "addUceRegistrationOverrideShell");
10994 final long identity = Binder.clearCallingIdentity();
10995 try {
10996 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10997 new ArraySet<>(featureTags));
10998 } catch (ImsException e) {
10999 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11000 } finally {
11001 Binder.restoreCallingIdentity(identity);
11002 }
11003 }
11004
11005 /**
11006 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11007 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11008 */
11009 // Used for SHELL command only right now.
11010 @Override
11011 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11012 List<String> featureTags) {
11013 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11014 "removeUceRegistrationOverrideShell");
11015 final long identity = Binder.clearCallingIdentity();
11016 try {
11017 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11018 new ArraySet<>(featureTags));
11019 } catch (ImsException e) {
11020 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11021 } finally {
11022 Binder.restoreCallingIdentity(identity);
11023 }
11024 }
11025
11026 /**
11027 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11028 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11029 */
11030 // Used for SHELL command only right now.
11031 @Override
11032 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11033 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11034 "clearUceRegistrationOverrideShell");
11035 final long identity = Binder.clearCallingIdentity();
11036 try {
11037 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11038 } catch (ImsException e) {
11039 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11040 } finally {
11041 Binder.restoreCallingIdentity(identity);
11042 }
11043 }
11044
11045 /**
11046 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11047 */
11048 // Used for SHELL command only right now.
11049 @Override
11050 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11051 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11052 "getLatestRcsContactUceCapabilityShell");
11053 final long identity = Binder.clearCallingIdentity();
11054 try {
11055 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11056 } catch (ImsException e) {
11057 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11058 } finally {
11059 Binder.restoreCallingIdentity(identity);
11060 }
11061 }
11062
11063 /**
11064 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11065 * device does not have an active PUBLISH.
11066 */
11067 // Used for SHELL command only right now.
11068 @Override
11069 public String getLastUcePidfXmlShell(int subId) {
11070 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11071 final long identity = Binder.clearCallingIdentity();
11072 try {
11073 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11074 } catch (ImsException e) {
11075 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11076 } finally {
11077 Binder.restoreCallingIdentity(identity);
11078 }
11079 }
11080
James.cf Line8713a42021-04-29 16:04:26 +080011081 /**
11082 * Remove UCE requests cannot be sent to the network status.
11083 */
11084 // Used for SHELL command only right now.
11085 @Override
11086 public boolean removeUceRequestDisallowedStatus(int subId) {
11087 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11088 final long identity = Binder.clearCallingIdentity();
11089 try {
11090 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11091 } catch (ImsException e) {
11092 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11093 } finally {
11094 Binder.restoreCallingIdentity(identity);
11095 }
11096 }
11097
James.cf Lin18bb9002021-05-25 01:37:38 +080011098 /**
11099 * Remove UCE requests cannot be sent to the network status.
11100 */
11101 // Used for SHELL command only.
11102 @Override
11103 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11104 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11105 final long identity = Binder.clearCallingIdentity();
11106 try {
11107 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11108 } catch (ImsException e) {
11109 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11110 } finally {
11111 Binder.restoreCallingIdentity(identity);
11112 }
11113 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011114
James.cf Lin4b784aa2021-01-31 03:25:15 +080011115 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011116 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11117 String callingPackage) {
11118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11119 mApp, subId, "setSignalStrengthUpdateRequest");
11120
11121 final int callingUid = Binder.getCallingUid();
11122 // Verify that tha callingPackage belongs to the calling UID
11123 mApp.getSystemService(AppOpsManager.class)
11124 .checkPackage(callingUid, callingPackage);
11125
Rambo Wang3607f502021-02-01 21:51:40 -080011126 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011127
11128 final long identity = Binder.clearCallingIdentity();
11129 try {
11130 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11131 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11132
11133 if (result instanceof IllegalStateException) {
11134 throw (IllegalStateException) result;
11135 }
11136 } finally {
11137 Binder.restoreCallingIdentity(identity);
11138 }
11139 }
11140
11141 @Override
11142 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11143 String callingPackage) {
11144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11145 mApp, subId, "clearSignalStrengthUpdateRequest");
11146
11147 final int callingUid = Binder.getCallingUid();
11148 // Verify that tha callingPackage belongs to the calling UID
11149 mApp.getSystemService(AppOpsManager.class)
11150 .checkPackage(callingUid, callingPackage);
11151
11152 final long identity = Binder.clearCallingIdentity();
11153 try {
11154 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11155 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11156
11157 if (result instanceof IllegalStateException) {
11158 throw (IllegalStateException) result;
11159 }
11160 } finally {
11161 Binder.restoreCallingIdentity(identity);
11162 }
11163 }
11164
Rambo Wang3607f502021-02-01 21:51:40 -080011165 private static void validateSignalStrengthUpdateRequest(Context context,
11166 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011167 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11168 // phone/system process do not have further restriction on request
11169 return;
11170 }
11171
11172 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011173 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011174 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011175 context.enforceCallingOrSelfPermission(
11176 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11177 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011178 }
11179
11180 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11181 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11182 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11183 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11184 || info.isEnabled()) {
11185 throw new IllegalArgumentException(
11186 "Only system can set hide fields in SignalThresholdInfo");
11187 }
11188
11189 // Thresholds length for each RAN need in range. This has been validated in
11190 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11191 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11192 final int[] thresholds = info.getThresholds();
11193 Objects.requireNonNull(thresholds);
11194 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11195 || thresholds.length
11196 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11197 throw new IllegalArgumentException(
11198 "thresholds length is out of range: " + thresholds.length);
11199 }
11200 }
11201 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011202
11203 /**
11204 * Gets the current phone capability.
11205 *
11206 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11207 * @return the PhoneCapability which describes the data connection capability of modem.
11208 * It's used to evaluate possible phone config change, for example from single
11209 * SIM device to multi-SIM device.
11210 */
11211 @Override
11212 public PhoneCapability getPhoneCapability() {
11213 enforceReadPrivilegedPermission("getPhoneCapability");
11214 final long identity = Binder.clearCallingIdentity();
11215 try {
11216 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11217 } finally {
11218 Binder.restoreCallingIdentity(identity);
11219 }
11220 }
Michele Berionne5e411512020-11-13 02:36:59 +000011221
11222 /**
11223 * Prepare TelephonyManager for an unattended reboot. The reboot is
11224 * required to be done shortly after the API is invoked.
11225 */
11226 @Override
11227 @TelephonyManager.PrepareUnattendedRebootResult
11228 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011229 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011230 enforceRebootPermission();
11231
11232 final long identity = Binder.clearCallingIdentity();
11233 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011234 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011235 } finally {
11236 Binder.restoreCallingIdentity(identity);
11237 }
11238 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011239
11240 /**
11241 * Request to get the current slicing configuration including URSP rules and
11242 * NSSAIs (configured, allowed and rejected).
11243 *
11244 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11245 */
11246 @Override
11247 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011248 TelephonyPermissions
11249 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11250 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011251
11252 final long identity = Binder.clearCallingIdentity();
11253 try {
11254 Phone phone = getDefaultPhone();
11255 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11256 } finally {
11257 Binder.restoreCallingIdentity(identity);
11258 }
11259 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011260
11261 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011262 * Check whether the given premium capability is available for purchase from the carrier.
11263 *
11264 * @param capability The premium capability to check.
11265 * @param subId The subId to check the premium capability for.
11266 *
11267 * @return Whether the given premium capability is available to purchase.
11268 */
11269 @Override
11270 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11271 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11272 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11273 log("Premium capability "
11274 + TelephonyManager.convertPremiumCapabilityToString(capability)
11275 + " is not available for purchase due to missing permissions.");
11276 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11277 + "permission READ_BASIC_PHONE_STATE.");
11278 }
11279
11280 Phone phone = getPhone(subId);
11281 final long identity = Binder.clearCallingIdentity();
11282 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011283 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011284 .isPremiumCapabilityAvailableForPurchase(capability);
11285 } finally {
11286 Binder.restoreCallingIdentity(identity);
11287 }
11288 }
11289
11290 /**
11291 * Purchase the given premium capability from the carrier.
11292 *
11293 * @param capability The premium capability to purchase.
11294 * @param callback The result of the purchase request.
11295 * @param subId The subId to purchase the premium capability for.
11296 */
11297 @Override
11298 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11299 log("purchasePremiumCapability: capability="
11300 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11301 + getCurrentPackageName());
11302
11303 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11304 mApp, "purchasePremiumCapability")) {
11305 log("purchasePremiumCapability "
11306 + TelephonyManager.convertPremiumCapabilityToString(capability)
11307 + " failed due to missing permissions.");
11308 throw new SecurityException("purchasePremiumCapability requires permission "
11309 + "READ_BASIC_PHONE_STATE.");
11310 }
11311
11312 Phone phone = getPhone(subId);
Sarah Chin71b3a852022-09-28 15:54:19 -070011313 String appName;
11314 try {
11315 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11316 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11317 } catch (PackageManager.NameNotFoundException e) {
11318 appName = "An application";
11319 }
11320 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11321 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011322 }
11323
11324 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011325 * Register an IMS connection state callback
11326 */
11327 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011328 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11329 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011330 if (feature == ImsFeature.FEATURE_MMTEL) {
11331 // ImsMmTelManager
11332 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11333 TelephonyPermissions
11334 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11335 mApp, subId, "registerImsStateCallback");
11336 } else if (feature == ImsFeature.FEATURE_RCS) {
11337 // ImsRcsManager or SipDelegateManager
11338 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11339 Binder.getCallingUid(), "registerImsStateCallback",
11340 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11341 Manifest.permission.READ_PRECISE_PHONE_STATE,
11342 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11343 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11344 }
11345
11346 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11347 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11348 "IMS not available on device.");
11349 }
11350
11351 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11352 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11353 }
11354
11355 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11356 if (controller == null) {
11357 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11358 "IMS not available on device.");
11359 }
11360
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011361 if (callingPackage == null) {
11362 callingPackage = getCurrentPackageName();
11363 }
11364
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011365 final long token = Binder.clearCallingIdentity();
11366 try {
11367 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011368 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011369 } catch (ImsException e) {
11370 throw new ServiceSpecificException(e.getCode());
11371 } finally {
11372 Binder.restoreCallingIdentity(token);
11373 }
11374 }
11375
11376 /**
11377 * Unregister an IMS connection state callback
11378 */
11379 @Override
11380 public void unregisterImsStateCallback(IImsStateCallback cb) {
11381 final long token = Binder.clearCallingIdentity();
11382 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11383 if (controller == null) {
11384 return;
11385 }
11386 try {
11387 controller.unregisterImsStateCallback(cb);
11388 } finally {
11389 Binder.restoreCallingIdentity(token);
11390 }
11391 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011392
11393 /**
11394 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11395 *
11396 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11397 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11398 * SecurityException.
11399 * If there is current registered network this value will be same as the registered cell
11400 * identity. If the device goes out of service the previous cell identity is cached and
11401 * will be returned. If the cache age of the Cell identity is more than 24 hours
11402 * it will be cleared and null will be returned.
11403 *
11404 */
11405 @Override
11406 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11407 String callingFeatureId) {
11408 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11409 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11410 LocationAccessPolicy.checkLocationPermission(mApp,
11411 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11412 .setCallingPackage(callingPackage)
11413 .setCallingFeatureId(callingFeatureId)
11414 .setCallingPid(Binder.getCallingPid())
11415 .setCallingUid(Binder.getCallingUid())
11416 .setMethod("getLastKnownCellIdentity")
11417 .setLogAsInfo(true)
11418 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11419 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11420 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11421 .build());
11422
11423 boolean hasFinePermission =
11424 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11425 if (!hasFinePermission
11426 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11427 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011428 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011429 }
11430
11431 final long identity = Binder.clearCallingIdentity();
11432 try {
11433 Phone phone = getPhone(subId);
11434 if (phone == null) return null;
11435 ServiceStateTracker sst = phone.getServiceStateTracker();
11436 if (sst == null) return null;
11437 return sst.getLastKnownCellIdentity();
11438 } finally {
11439 Binder.restoreCallingIdentity(identity);
11440 }
11441 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011442
jimsun3b9ccac2021-10-26 15:01:23 +080011443 /**
11444 * Sets the modem service class Name that Telephony will bind to.
11445 *
11446 * @param serviceName The class name of the modem service.
11447 * @return true if the operation is succeed, otherwise false.
11448 */
11449 public boolean setModemService(String serviceName) {
11450 Log.d(LOG_TAG, "setModemService - " + serviceName);
11451 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11453 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11454 "setModemService");
11455 return mPhoneConfigurationManager.setModemService(serviceName);
11456 }
11457
11458 /**
11459 * Return the class name of the currently bounded modem service.
11460 *
11461 * @return the class name of the modem service.
11462 */
11463 public String getModemService() {
11464 String result;
11465 Log.d(LOG_TAG, "getModemService");
11466 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11467 TelephonyPermissions
11468 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11469 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11470 "getModemService");
11471 result = mPhoneConfigurationManager.getModemService();
11472 Log.d(LOG_TAG, "result = " + result);
11473 return result;
11474 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011475
11476 @Override
11477 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11478 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11479 mApp.enforceCallingOrSelfPermission(
11480 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11481 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11482
11483 final long identity = Binder.clearCallingIdentity();
11484 try {
11485 Phone phone = getPhone(subId);
11486 if (phone == null) return;
11487 phone.setVoiceServiceStateOverride(hasService);
11488 } finally {
11489 Binder.restoreCallingIdentity(identity);
11490 }
11491 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011492
11493 /**
11494 * set removable eSIM as default eUICC.
11495 *
11496 * @hide
11497 */
11498 @Override
11499 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11500 enforceModifyPermission();
11501 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11502
11503 final long identity = Binder.clearCallingIdentity();
11504 try {
11505 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11506 } finally {
11507 Binder.restoreCallingIdentity(identity);
11508 }
11509 }
11510
11511 /**
11512 * Returns whether the removable eSIM is default eUICC or not.
11513 *
11514 * @hide
11515 */
11516 @Override
11517 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11518 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11519 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11520
11521 final long identity = Binder.clearCallingIdentity();
11522 try {
11523 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11524 } finally {
11525 Binder.restoreCallingIdentity(identity);
11526 }
11527 }
11528
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011529 /**
11530 * Get the component name of the default app to direct respond-via-message intent for the
11531 * user associated with this subscription, update the cache if there is no respond-via-message
11532 * application currently configured for this user.
11533 * @return component name of the app and class to direct Respond Via Message intent to, or
11534 * {@code null} if the functionality is not supported.
11535 * @hide
11536 */
11537 @Override
11538 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11539 boolean updateIfNeeded) {
11540 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011541
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011542 Context context = getPhone(subId).getContext();
11543 UserHandle userHandle = null;
11544 final long identity = Binder.clearCallingIdentity();
11545 try {
11546 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11547 } finally {
11548 Binder.restoreCallingIdentity(identity);
11549 }
11550 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11551 updateIfNeeded, userHandle);
11552 }
11553}