blob: 976799a213dd73a98e645922cf67629afde5a343 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070034import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000035import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080036import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
tom hsue9360cd2022-09-29 23:49:21 +080053import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.Looper;
55import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080057import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070058import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070059import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080060import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080061import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070062import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070063import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080064import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070066import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070067import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070068import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070069import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080070import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070071import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090072import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080073import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080074import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070075import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080076import android.telephony.AccessNetworkConstants;
77import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070078import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070079import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080080import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080081import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070082import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080083import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070084import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080085import android.telephony.CellIdentityCdma;
86import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070088import android.telephony.CellInfoGsm;
89import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070090import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080091import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070092import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070093import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070094import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080095import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070096import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080097import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070098import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080099import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800100import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700101import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800102import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800104import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800105import android.telephony.SignalStrengthUpdateRequest;
106import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800107import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800109import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700110import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700111import android.telephony.TelephonyManager;
Ryan Savitskicab25c52023-03-14 14:23:49 +0000112import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800113import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800114import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800115import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000116import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000117import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000118import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700119import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700120import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800121import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800122import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700123import android.telephony.gba.GbaAuthRequest;
124import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700125import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800126import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000127import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000128import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700129import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000130import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700131import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800132import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700133import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800134import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700135import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000136import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700137import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800138import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800139import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800141import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700142import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800144import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800145
Andrew Lee312e8172014-10-23 17:01:36 -0700146import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800147import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800148import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800149import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800150import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700151import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700152import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700153import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800154import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800155import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700156import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700157import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800158import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700159import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800160import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800161import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800162import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700163import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000164import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800166import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.telephony.IccCard;
Ryan Savitskicab25c52023-03-14 14:23:49 +0000169import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800170import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700172import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700173import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700175import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800176import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700177import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700178import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700179import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700180import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800181import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800182import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700183import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700184import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700185import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800186import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800187import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800188import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700189import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800190import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700191import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800192import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700193import com.android.internal.telephony.imsphone.ImsPhone;
194import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000195import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800196import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yudf049d72022-12-02 22:48:35 -0800197import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
198import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700199import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700200import com.android.internal.telephony.uicc.IccIoResult;
201import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800202import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700203import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800204import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700205import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000206import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800207import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000208import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800209import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700210import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700211import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800212import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800213import com.android.phone.callcomposer.CallComposerPictureManager;
214import com.android.phone.callcomposer.CallComposerPictureTransfer;
215import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700216import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700217import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800218import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700219import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700220import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800221import com.android.services.telephony.TelecomAccountRegistry;
222import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800223import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800224
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700226import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800227import java.io.IOException;
228import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700229import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700230import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800231import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000232import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800233import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800234import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800235import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800236import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100237import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800238import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700239import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800240import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800241import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800242import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800243import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800244import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245
246/**
247 * Implementation of the ITelephony interface.
248 */
Santos Cordon117fee72014-05-16 17:56:12 -0700249public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250 private static final String LOG_TAG = "PhoneInterfaceManager";
251 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
252 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800253 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254
255 // Message codes used with mMainThreadHandler
256 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700257 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
258 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700259 private static final int CMD_OPEN_CHANNEL = 9;
260 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
261 private static final int CMD_CLOSE_CHANNEL = 11;
262 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800263 private static final int CMD_NV_READ_ITEM = 13;
264 private static final int EVENT_NV_READ_ITEM_DONE = 14;
265 private static final int CMD_NV_WRITE_ITEM = 15;
266 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
267 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
268 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700269 private static final int CMD_RESET_MODEM_CONFIG = 19;
270 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800271 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
272 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800273 private static final int CMD_SEND_ENVELOPE = 25;
274 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000275 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
276 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700277 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
278 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
279 private static final int CMD_EXCHANGE_SIM_IO = 31;
280 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800281 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
282 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700283 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
284 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700285 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
286 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700287 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
288 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
289 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
290 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700291 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
292 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
293 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
294 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700295 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800296 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
297 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000298 private static final int CMD_SWITCH_SLOTS = 50;
299 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700300 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
301 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
302 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
303 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
304 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
305 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
306 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
307 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700308 private static final int CMD_GET_ALL_CELL_INFO = 60;
309 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
310 private static final int CMD_GET_CELL_LOCATION = 62;
311 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700312 private static final int CMD_MODEM_REBOOT = 64;
313 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700314 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
315 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800316 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
317 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700318 private static final int CMD_GET_MODEM_STATUS = 70;
319 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700320 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
321 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700322 private static final int CMD_ERASE_MODEM_CONFIG = 74;
323 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800324 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
325 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
326 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
327 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800328 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
329 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800330 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800331 private static final int CMD_GET_CALL_FORWARDING = 83;
332 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
333 private static final int CMD_SET_CALL_FORWARDING = 85;
334 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
335 private static final int CMD_GET_CALL_WAITING = 87;
336 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
337 private static final int CMD_SET_CALL_WAITING = 89;
338 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700339 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
340 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
341 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
342 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700343 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
344 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800345 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
346 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800347 private static final int CMD_SET_DATA_THROTTLING = 99;
348 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800349 private static final int CMD_SET_SIM_POWER = 101;
350 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800351 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
352 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
353 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
354 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800355 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
356 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000357 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800358 private static final int CMD_GET_SLICING_CONFIG = 110;
359 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800360 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700361 private static final int CMD_ENABLE_VONR = 113;
362 private static final int EVENT_ENABLE_VONR_DONE = 114;
363 private static final int CMD_IS_VONR_ENABLED = 115;
364 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800366 // Parameters of select command.
367 private static final int SELECT_COMMAND = 0xA4;
368 private static final int SELECT_P1 = 0x04;
369 private static final int SELECT_P2 = 0;
370 private static final int SELECT_P3 = 0x10;
371
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 /** The singleton instance. */
373 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800374 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800378 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700379 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800380 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700381 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800382 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800383 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800384 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700385 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800386 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000387 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388
Peter Wangdafb9ac2020-01-15 14:13:38 -0800389 /** User Activity */
390 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800391 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
392
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700393 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
394
Derek Tan97ebb422014-09-05 16:55:38 -0700395 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
396 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800397 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800398 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700399
Michelecea4cf22018-12-21 15:00:11 -0800400 // String to store multi SIM allowed
401 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
402
Derek Tan740e1672017-06-27 14:56:27 -0700403 // The AID of ISD-R.
404 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
405
yinxub1bed742017-04-17 11:45:04 -0700406 private NetworkScanRequestTracker mNetworkScanRequestTracker;
407
David Kelly5e06a7f2018-03-12 14:10:59 +0000408 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
409 private static final int MANUFACTURER_CODE_LENGTH = 8;
410
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800411 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800412 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800413
Derek Tan89e89d42014-07-08 17:00:10 -0700414 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700415 * Experiment flag to enable erase modem config on reset network, default value is false
416 */
417 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
418 "reset_network_erase_modem_config_enabled";
419
Rambo Wang0f050d82021-02-12 11:43:36 -0800420 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800421
sandeepjsb6c87872021-09-27 15:34:44 +0000422 /**
423 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
424 * one ICCID active at the same time.
425 * Apps should use below API signatures if targeting SDK is T and beyond.
426 *
427 * @hide
428 */
429 @ChangeId
430 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
431 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800432
Naina Nallurid63128d2019-09-17 14:10:30 -0700433 /**
Chen Xu540470b2021-12-14 17:15:47 -0800434 * Apps targeting on Android T and beyond will get exception whenever icc close channel
435 * operation fails.
436 */
437 @ChangeId
438 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
439 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
440
441 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 * A request object to use for transmitting data to an ICC.
443 */
444 private static final class IccAPDUArgument {
445 public int channel, cla, command, p1, p2, p3;
446 public String data;
447
448 public IccAPDUArgument(int channel, int cla, int command,
449 int p1, int p2, int p3, String data) {
450 this.channel = channel;
451 this.cla = cla;
452 this.command = command;
453 this.p1 = p1;
454 this.p2 = p2;
455 this.p3 = p3;
456 this.data = data;
457 }
458 }
459
460 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700461 * A request object to use for transmitting data to an ICC.
462 */
463 private static final class ManualNetworkSelectionArgument {
464 public OperatorInfo operatorInfo;
465 public boolean persistSelection;
466
467 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
468 this.operatorInfo = operatorInfo;
469 this.persistSelection = persistSelection;
470 }
471 }
472
473 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
475 * request after sending. The main thread will notify the request when it is complete.
476 */
477 private static final class MainThreadRequest {
478 /** The argument to use for the request */
479 public Object argument;
480 /** The result of the request that is run on the main thread */
481 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800482 // The subscriber id that this request applies to. Defaults to
483 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
484 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485
Nathan Harold92bed182018-10-12 18:16:49 -0700486 // In cases where subId is unavailable, the caller needs to specify the phone.
487 public Phone phone;
488
vagdeviaf9a5b92018-08-15 16:01:53 -0700489 public WorkSource workSource;
490
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700491 public MainThreadRequest(Object argument) {
492 this.argument = argument;
493 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800494
Nathan Harold92bed182018-10-12 18:16:49 -0700495 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
496 this.argument = argument;
497 if (phone != null) {
498 this.phone = phone;
499 }
500 this.workSource = workSource;
501 }
502
vagdeviaf9a5b92018-08-15 16:01:53 -0700503 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800504 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800505 if (subId != null) {
506 this.subId = subId;
507 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700508 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510 }
511
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800512 private static final class IncomingThirdPartyCallArgs {
513 public final ComponentName component;
514 public final String callId;
515 public final String callerDisplayName;
516
517 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
518 String callerDisplayName) {
519 this.component = component;
520 this.callId = callId;
521 this.callerDisplayName = callerDisplayName;
522 }
523 }
524
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 /**
526 * A handler that processes messages on the main thread in the phone process. Since many
527 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
528 * inbound binder threads to the main thread in the phone process. The Binder thread
529 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
530 * on, which will be notified when the operation completes and will contain the result of the
531 * request.
532 *
533 * <p>If a MainThreadRequest object is provided in the msg.obj field,
534 * note that request.result must be set to something non-null for the calling thread to
535 * unblock.
536 */
537 private final class MainThreadHandler extends Handler {
538 @Override
539 public void handleMessage(Message msg) {
540 MainThreadRequest request;
541 Message onCompleted;
542 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000543 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700544 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800545 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546
547 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 case CMD_HANDLE_USSD_REQUEST: {
549 request = (MainThreadRequest) msg.obj;
550 final Phone phone = getPhoneFromRequest(request);
551 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800552 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700553 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700554
Pengquan Menga1bb6272018-09-06 09:59:22 -0700555 if (!isUssdApiAllowed(request.subId)) {
556 // Carrier does not support use of this API, return failure.
557 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
558 UssdResponse response = new UssdResponse(ussdRequest, null);
559 Bundle returnData = new Bundle();
560 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
561 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700562
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 request.result = true;
564 notifyRequester(request);
565 return;
566 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700567
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 try {
569 request.result = phone != null
570 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
571 } catch (CallStateException cse) {
572 request.result = false;
573 }
574 // Wake up the requesting thread
575 notifyRequester(request);
576 break;
pkanwar32d516d2016-10-14 19:37:38 -0700577 }
578
Yorke Lee716f67e2015-06-17 15:39:16 -0700579 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700580 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700581 final Phone phone = getPhoneFromRequest(request);
582 request.result = phone != null ?
583 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
584 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700585 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700586 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700587 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700589
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000593 uiccPort = getUiccPortFromRequest(request);
594 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800596 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800600 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000601 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800602 iccArgument.channel, iccArgument.cla, iccArgument.command,
603 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
604 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700605 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 break;
607
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700608 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 ar = (AsyncResult) msg.obj;
610 request = (MainThreadRequest) ar.userObj;
611 if (ar.exception == null && ar.result != null) {
612 request.result = ar.result;
613 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800614 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 if (ar.result == null) {
616 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800617 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800619 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 } else {
621 loge("iccTransmitApduLogicalChannel: Unknown exception");
622 }
623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 break;
626
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
628 request = (MainThreadRequest) msg.obj;
629 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000630 uiccPort = getUiccPortFromRequest(request);
631 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800633 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 } else {
636 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800637 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000638 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800639 iccArgument.cla, iccArgument.command, iccArgument.p1,
640 iccArgument.p2,
641 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 }
643 break;
644
645 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
646 ar = (AsyncResult) msg.obj;
647 request = (MainThreadRequest) ar.userObj;
648 if (ar.exception == null && ar.result != null) {
649 request.result = ar.result;
650 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800651 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 if (ar.result == null) {
653 loge("iccTransmitApduBasicChannel: Empty response");
654 } else if (ar.exception instanceof CommandException) {
655 loge("iccTransmitApduBasicChannel: CommandException: " +
656 ar.exception);
657 } else {
658 loge("iccTransmitApduBasicChannel: Unknown exception");
659 }
660 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700661 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 break;
663
664 case CMD_EXCHANGE_SIM_IO:
665 request = (MainThreadRequest) msg.obj;
666 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000667 uiccPort = getUiccPortFromRequest(request);
668 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800670 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700671 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 } else {
673 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
674 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000675 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
677 iccArgument.data, onCompleted);
678 }
679 break;
680
681 case EVENT_EXCHANGE_SIM_IO_DONE:
682 ar = (AsyncResult) msg.obj;
683 request = (MainThreadRequest) ar.userObj;
684 if (ar.exception == null && ar.result != null) {
685 request.result = ar.result;
686 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800687 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700689 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700690 break;
691
Derek Tan4d5e5c12014-02-04 11:54:58 -0800692 case CMD_SEND_ENVELOPE:
693 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000694 uiccPort = getUiccPortFromRequest(request);
695 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700696 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800697 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700698 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700699 } else {
700 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800701 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700702 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800703 break;
704
705 case EVENT_SEND_ENVELOPE_DONE:
706 ar = (AsyncResult) msg.obj;
707 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700708 if (ar.exception == null && ar.result != null) {
709 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800710 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800711 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700712 if (ar.result == null) {
713 loge("sendEnvelopeWithStatus: Empty response");
714 } else if (ar.exception instanceof CommandException) {
715 loge("sendEnvelopeWithStatus: CommandException: " +
716 ar.exception);
717 } else {
718 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
719 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800720 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700721 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800722 break;
723
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 case CMD_OPEN_CHANNEL:
725 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000726 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800727 IccLogicalChannelRequest openChannelRequest =
728 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000729 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700730 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800731 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800732 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700733 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700734 } else {
735 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800736 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
737 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700738 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 break;
740
741 case EVENT_OPEN_CHANNEL_DONE:
742 ar = (AsyncResult) msg.obj;
743 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700744 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700745 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700746 int[] result = (int[]) ar.result;
747 int channelId = result[0];
748 byte[] selectResponse = null;
749 if (result.length > 1) {
750 selectResponse = new byte[result.length - 1];
751 for (int i = 1; i < result.length; ++i) {
752 selectResponse[i - 1] = (byte) result[i];
753 }
754 }
755 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800756 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800757
758 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700759 if (uiccPort == null) {
760 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
761 } else {
762 IccLogicalChannelRequest channelRequest =
763 (IccLogicalChannelRequest) request.argument;
764 channelRequest.channel = channelId;
765 uiccPort.onLogicalChannelOpened(channelRequest);
766 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700767 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 if (ar.result == null) {
769 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700771 if (ar.exception != null) {
772 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
773 }
774
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700775 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700776 if (ar.exception instanceof CommandException) {
777 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800778 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700779 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700780 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700781 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700782 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700783 }
784 }
785 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800786 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700788 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700789 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 break;
791
792 case CMD_CLOSE_CHANNEL:
793 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000794 uiccPort = getUiccPortFromRequest(request);
795 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700796 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800797 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800798 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800799 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700800 } else {
801 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000802 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700803 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700804 break;
805
806 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800807 ar = (AsyncResult) msg.obj;
808 request = (MainThreadRequest) ar.userObj;
809 if (ar.exception == null) {
810 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800811 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700812 if (uiccPort == null) {
813 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
814 } else {
815 final int channelId = (Integer) request.argument;
816 uiccPort.onLogicalChannelClosed(channelId);
817 }
Chen Xu540470b2021-12-14 17:15:47 -0800818 } else {
819 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800820 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800821 if (ar.exception instanceof CommandException) {
822 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
823 CommandException.Error error =
824 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800825 if (error == CommandException.Error.INVALID_ARGUMENTS) {
826 // should only throw exceptions from the binder threads.
827 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800828 "iccCloseLogicalChannel: invalid argument ");
829 }
830 } else {
831 loge("iccCloseLogicalChannel: Unknown exception");
832 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800833 request.result = (exception != null) ? exception :
834 new IllegalStateException(
835 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800836 }
837 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800838 break;
839
840 case CMD_NV_READ_ITEM:
841 request = (MainThreadRequest) msg.obj;
842 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800843 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
844 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800845 break;
846
847 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 ar = (AsyncResult) msg.obj;
849 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800850 if (ar.exception == null && ar.result != null) {
851 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700852 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800853 request.result = "";
854 if (ar.result == null) {
855 loge("nvReadItem: Empty response");
856 } else if (ar.exception instanceof CommandException) {
857 loge("nvReadItem: CommandException: " +
858 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700859 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800860 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700861 }
862 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700863 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700864 break;
865
Jake Hambye994d462014-02-03 13:10:13 -0800866 case CMD_NV_WRITE_ITEM:
867 request = (MainThreadRequest) msg.obj;
868 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
869 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800870 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700871 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800872 break;
873
874 case EVENT_NV_WRITE_ITEM_DONE:
875 handleNullReturnEvent(msg, "nvWriteItem");
876 break;
877
878 case CMD_NV_WRITE_CDMA_PRL:
879 request = (MainThreadRequest) msg.obj;
880 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800881 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800882 break;
883
884 case EVENT_NV_WRITE_CDMA_PRL_DONE:
885 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
886 break;
887
chen xu6dac5ab2018-10-26 17:39:23 -0700888 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800889 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700890 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800891 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800892 break;
893
chen xu6dac5ab2018-10-26 17:39:23 -0700894 case EVENT_RESET_MODEM_CONFIG_DONE:
895 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800896 break;
897
Sooraj Sasindran37444802020-08-11 10:40:43 -0700898 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
901 request);
902 Phone phone = getPhoneFromRequest(request);
903 if (phone != null) {
904 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
905 } else {
906 loge("isNRDualConnectivityEnabled: No phone object");
907 request.result = false;
908 notifyRequester(request);
909 }
910 break;
911 }
912
913 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
916 if (ar.exception == null && ar.result != null) {
917 request.result = ar.result;
918 } else {
919 // request.result must be set to something non-null
920 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700921 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700922 request.result = ar.result;
923 } else {
924 request.result = false;
925 }
926 if (ar.result == null) {
927 loge("isNRDualConnectivityEnabled: Empty response");
928 } else if (ar.exception instanceof CommandException) {
929 loge("isNRDualConnectivityEnabled: CommandException: "
930 + ar.exception);
931 } else {
932 loge("isNRDualConnectivityEnabled: Unknown exception");
933 }
934 }
935 notifyRequester(request);
936 break;
937
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700938 case CMD_IS_VONR_ENABLED: {
939 request = (MainThreadRequest) msg.obj;
940 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
941 request);
942 Phone phone = getPhoneFromRequest(request);
943 if (phone != null) {
944 phone.isVoNrEnabled(onCompleted, request.workSource);
945 } else {
946 loge("isVoNrEnabled: No phone object");
947 request.result = false;
948 notifyRequester(request);
949 }
950 break;
951 }
952
953 case EVENT_IS_VONR_ENABLED_DONE:
954 ar = (AsyncResult) msg.obj;
955 request = (MainThreadRequest) ar.userObj;
956 if (ar.exception == null && ar.result != null) {
957 request.result = ar.result;
958 } else {
959 // request.result must be set to something non-null
960 // for the calling thread to unblock
961 if (ar.result != null) {
962 request.result = ar.result;
963 } else {
964 request.result = false;
965 }
966 if (ar.result == null) {
967 loge("isVoNrEnabled: Empty response");
968 } else if (ar.exception instanceof CommandException) {
969 loge("isVoNrEnabled: CommandException: "
970 + ar.exception);
971 } else {
972 loge("isVoNrEnabled: Unknown exception");
973 }
974 }
975 notifyRequester(request);
976 break;
977
Sooraj Sasindran37444802020-08-11 10:40:43 -0700978 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
979 request = (MainThreadRequest) msg.obj;
980 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
981 Phone phone = getPhoneFromRequest(request);
982 if (phone != null) {
983 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
984 request.workSource);
985 } else {
986 loge("enableNrDualConnectivity: No phone object");
987 request.result =
988 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
989 notifyRequester(request);
990 }
991 break;
992 }
993
994 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
997 if (ar.exception == null) {
998 request.result =
999 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1000 } else {
1001 request.result =
1002 TelephonyManager
1003 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1004 if (ar.exception instanceof CommandException) {
1005 CommandException.Error error =
1006 ((CommandException) (ar.exception)).getCommandError();
1007 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1008 request.result =
1009 TelephonyManager
1010 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001011 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1012 request.result =
1013 TelephonyManager
1014 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001015 }
1016 loge("enableNrDualConnectivity" + ": CommandException: "
1017 + ar.exception);
1018 } else {
1019 loge("enableNrDualConnectivity" + ": Unknown exception");
1020 }
1021 }
1022 notifyRequester(request);
1023 break;
1024 }
1025
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001026 case CMD_ENABLE_VONR: {
1027 request = (MainThreadRequest) msg.obj;
1028 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1029 Phone phone = getPhoneFromRequest(request);
1030 if (phone != null) {
1031 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1032 request.workSource);
1033 } else {
1034 loge("setVoNrEnabled: No phone object");
1035 request.result =
1036 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1037 notifyRequester(request);
1038 }
1039 break;
1040 }
1041
1042 case EVENT_ENABLE_VONR_DONE: {
1043 ar = (AsyncResult) msg.obj;
1044 request = (MainThreadRequest) ar.userObj;
1045 if (ar.exception == null) {
1046 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1047 } else {
1048 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1049 if (ar.exception instanceof CommandException) {
1050 CommandException.Error error =
1051 ((CommandException) (ar.exception)).getCommandError();
1052 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1053 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1054 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1055 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1056 } else {
1057 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1058 }
1059 loge("setVoNrEnabled" + ": CommandException: "
1060 + ar.exception);
1061 } else {
1062 loge("setVoNrEnabled" + ": Unknown exception");
1063 }
1064 }
1065 notifyRequester(request);
1066 break;
1067 }
1068
SongFerngWang3ef3e072020-12-21 16:41:52 +08001069 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001070 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001071 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1072 request);
1073 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001074 break;
1075
SongFerngWang3ef3e072020-12-21 16:41:52 +08001076 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001077 ar = (AsyncResult) msg.obj;
1078 request = (MainThreadRequest) ar.userObj;
1079 if (ar.exception == null && ar.result != null) {
1080 request.result = ar.result; // Integer
1081 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301082 // request.result must be set to something non-null
1083 // for the calling thread to unblock
1084 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001087 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001088 loge("getAllowedNetworkTypesBitmask: CommandException: "
1089 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001090 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001091 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001092 }
1093 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001094 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001095 break;
1096
SongFerngWang3ef3e072020-12-21 16:41:52 +08001097 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001098 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001099 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1100 request);
1101 Pair<Integer, Long> reasonWithNetworkTypes =
1102 (Pair<Integer, Long>) request.argument;
1103 getPhoneFromRequest(request).setAllowedNetworkTypes(
1104 reasonWithNetworkTypes.first,
1105 reasonWithNetworkTypes.second,
1106 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001107 break;
1108
SongFerngWang3ef3e072020-12-21 16:41:52 +08001109 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1110 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001111 break;
1112
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001113 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1114 request = (MainThreadRequest)msg.obj;
1115 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001116 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001117 break;
1118
1119 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1120 ar = (AsyncResult)msg.obj;
1121 request = (MainThreadRequest)ar.userObj;
1122 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001123 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001124 break;
1125
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001126 case CMD_SET_VOICEMAIL_NUMBER:
1127 request = (MainThreadRequest) msg.obj;
1128 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1129 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001130 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1131 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001132 break;
1133
1134 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1135 handleNullReturnEvent(msg, "setVoicemailNumber");
1136 break;
1137
Stuart Scott54788802015-03-30 13:18:01 -07001138 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1141 request);
1142 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1143 break;
1144
1145 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1146 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1147 break;
1148
Shishir Agrawal302c8692015-06-19 13:49:39 -07001149 case CMD_PERFORM_NETWORK_SCAN:
1150 request = (MainThreadRequest) msg.obj;
1151 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1152 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1153 break;
1154
Hall Liu27d24262020-09-18 19:04:59 -07001155 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001156 request = (MainThreadRequest) msg.obj;
1157 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001158 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1159 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1160 request.argument;
1161 int callForwardingReason = args.first;
1162 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001163 break;
Hall Liu27d24262020-09-18 19:04:59 -07001164 }
1165 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001166 ar = (AsyncResult) msg.obj;
1167 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001168 TelephonyManager.CallForwardingInfoCallback callback =
1169 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1170 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001171 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001172 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001173 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1174 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1175 // Service Class is a bit mask per 3gpp 27.007. Search for
1176 // any service for voice call.
1177 if ((callForwardInfo.serviceClass
1178 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001179 callForwardingInfo = new CallForwardingInfo(
1180 callForwardInfo.status
1181 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001182 callForwardInfo.reason,
1183 callForwardInfo.number,
1184 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001185 break;
1186 }
1187 }
1188 // Didn't find a call forward info for voice call.
1189 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001190 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1191 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001192 }
Hall Liu27d24262020-09-18 19:04:59 -07001193 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001194 } else {
1195 if (ar.result == null) {
1196 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1197 }
1198 if (ar.exception != null) {
1199 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1200 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001201 int errorCode = TelephonyManager
1202 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001203 if (ar.exception instanceof CommandException) {
1204 CommandException.Error error =
1205 ((CommandException) (ar.exception)).getCommandError();
1206 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001207 errorCode = TelephonyManager
1208 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001209 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001210 errorCode = TelephonyManager
1211 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001212 }
1213 }
Hall Liu27d24262020-09-18 19:04:59 -07001214 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001215 }
Shuo Qian4a594052020-01-23 11:59:30 -08001216 break;
Hall Liu27d24262020-09-18 19:04:59 -07001217 }
Shuo Qian4a594052020-01-23 11:59:30 -08001218
Hall Liu27d24262020-09-18 19:04:59 -07001219 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001220 request = (MainThreadRequest) msg.obj;
1221 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001222 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001223 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001224 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1225 request.argument).first;
1226 request.phone.setCallForwardingOption(
1227 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001228 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001229 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001230 callForwardingInfoToSet.getReason(),
1231 callForwardingInfoToSet.getNumber(),
1232 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1233 break;
Hall Liu27d24262020-09-18 19:04:59 -07001234 }
Shuo Qian4a594052020-01-23 11:59:30 -08001235
Hall Liu27d24262020-09-18 19:04:59 -07001236 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001237 ar = (AsyncResult) msg.obj;
1238 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001239 Consumer<Integer> callback =
1240 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1241 request.argument).second;
1242 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001243 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001244 int errorCode = TelephonyManager.CallForwardingInfoCallback
1245 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001246 if (ar.exception instanceof CommandException) {
1247 CommandException.Error error =
1248 ((CommandException) (ar.exception)).getCommandError();
1249 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001250 errorCode = TelephonyManager.CallForwardingInfoCallback
1251 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001252 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001253 errorCode = TelephonyManager.CallForwardingInfoCallback
1254 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001255 }
1256 }
1257 callback.accept(errorCode);
1258 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001259 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001260 }
Shuo Qian4a594052020-01-23 11:59:30 -08001261 break;
Hall Liu27d24262020-09-18 19:04:59 -07001262 }
Shuo Qian4a594052020-01-23 11:59:30 -08001263
Hall Liu27d24262020-09-18 19:04:59 -07001264 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001265 request = (MainThreadRequest) msg.obj;
1266 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1267 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1268 break;
Hall Liu27d24262020-09-18 19:04:59 -07001269 }
Shuo Qian4a594052020-01-23 11:59:30 -08001270
Hall Liu27d24262020-09-18 19:04:59 -07001271 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001272 ar = (AsyncResult) msg.obj;
1273 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001274 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001275 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001276 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001277 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001278 // Service Class is a bit mask per 3gpp 27.007.
1279 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001280 if (callForwardResults.length > 1
1281 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001282 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001283 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001284 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1285 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001286 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001287 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001288 }
1289 } else {
1290 if (ar.result == null) {
1291 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1292 }
1293 if (ar.exception != null) {
1294 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1295 }
1296 if (ar.exception instanceof CommandException) {
1297 CommandException.Error error =
1298 ((CommandException) (ar.exception)).getCommandError();
1299 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001300 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001301 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001302 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1303 callWaitingStatus =
1304 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001305 }
1306 }
1307 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001308 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001309 break;
Hall Liu27d24262020-09-18 19:04:59 -07001310 }
Shuo Qian4a594052020-01-23 11:59:30 -08001311
Hall Liu27d24262020-09-18 19:04:59 -07001312 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001313 request = (MainThreadRequest) msg.obj;
1314 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001315 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1316 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001317 break;
Hall Liu27d24262020-09-18 19:04:59 -07001318 }
Shuo Qian4a594052020-01-23 11:59:30 -08001319
Hall Liu27d24262020-09-18 19:04:59 -07001320 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001321 ar = (AsyncResult) msg.obj;
1322 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001323 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1324 Consumer<Integer> callback =
1325 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1326 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001327 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001328 if (ar.exception instanceof CommandException) {
1329 CommandException.Error error =
1330 ((CommandException) (ar.exception)).getCommandError();
1331 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1332 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001333 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1334 callback.accept(
1335 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001336 } else {
1337 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1338 }
1339 } else {
1340 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1341 }
1342 } else {
1343 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1344 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001345 }
Shuo Qian4a594052020-01-23 11:59:30 -08001346 break;
Hall Liu27d24262020-09-18 19:04:59 -07001347 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001348 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1349 ar = (AsyncResult) msg.obj;
1350 request = (MainThreadRequest) ar.userObj;
1351 CellNetworkScanResult cellScanResult;
1352 if (ar.exception == null && ar.result != null) {
1353 cellScanResult = new CellNetworkScanResult(
1354 CellNetworkScanResult.STATUS_SUCCESS,
1355 (List<OperatorInfo>) ar.result);
1356 } else {
1357 if (ar.result == null) {
1358 loge("getCellNetworkScanResults: Empty response");
1359 }
1360 if (ar.exception != null) {
1361 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1362 }
1363 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1364 if (ar.exception instanceof CommandException) {
1365 CommandException.Error error =
1366 ((CommandException) (ar.exception)).getCommandError();
1367 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1368 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1369 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1370 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1371 }
1372 }
1373 cellScanResult = new CellNetworkScanResult(errorCode, null);
1374 }
1375 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001376 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001377 break;
1378
1379 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1380 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001381 ManualNetworkSelectionArgument selArg =
1382 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001383 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1384 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001385 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1386 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001387 break;
1388
1389 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001390 ar = (AsyncResult) msg.obj;
1391 request = (MainThreadRequest) ar.userObj;
1392 if (ar.exception == null) {
1393 request.result = true;
1394 } else {
1395 request.result = false;
1396 loge("setNetworkSelectionModeManual " + ar.exception);
1397 }
1398 notifyRequester(request);
1399 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001400 break;
1401
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001402 case CMD_GET_MODEM_ACTIVITY_INFO:
1403 request = (MainThreadRequest) msg.obj;
1404 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001405 if (defaultPhone != null) {
1406 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001407 } else {
1408 ResultReceiver result = (ResultReceiver) request.argument;
1409 Bundle bundle = new Bundle();
1410 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001411 new ModemActivityInfo(0, 0, 0,
1412 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001413 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001414 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001415 break;
1416
Hall Liud0f208c2020-10-14 16:54:44 -07001417 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001418 ar = (AsyncResult) msg.obj;
1419 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001420 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001421 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001422 if (mLastModemActivityInfo == null) {
1423 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1424 mLastModemActivitySpecificInfo[0] =
1425 new ActivityStatsTechSpecificInfo(
1426 0,
1427 0,
1428 new int[ModemActivityInfo.getNumTxPowerLevels()],
1429 0);
1430 mLastModemActivityInfo =
1431 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1432 }
1433
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001434 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001435 // Update the last modem activity info and the result of the request.
1436 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1437 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001438 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001439 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001440 mLastModemActivityInfo =
1441 new ModemActivityInfo(
1442 mLastModemActivityInfo.getTimestampMillis(),
1443 mLastModemActivityInfo.getSleepTimeMillis(),
1444 mLastModemActivityInfo.getIdleTimeMillis(),
1445 mLastModemActivitySpecificInfo);
1446
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 } else {
1448 if (ar.result == null) {
1449 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001450 error = TelephonyManager.ModemActivityInfoException
1451 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001452 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001453 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001454 error = TelephonyManager.ModemActivityInfoException
1455 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001456 } else {
1457 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001458 error = TelephonyManager.ModemActivityInfoException
1459 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001460 }
1461 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001462 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001463 if (mLastModemActivityInfo != null) {
1464 bundle.putParcelable(
1465 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1466 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001467 } else {
1468 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1469 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001470 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001471 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001472 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001473 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001474
Meng Wang1a7c35a2016-05-05 20:56:15 -07001475 case CMD_SET_ALLOWED_CARRIERS:
1476 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001477 CarrierRestrictionRules argument =
1478 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001479 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001480 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001481 break;
1482
1483 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1484 ar = (AsyncResult) msg.obj;
1485 request = (MainThreadRequest) ar.userObj;
1486 if (ar.exception == null && ar.result != null) {
1487 request.result = ar.result;
1488 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001489 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1490 if (ar.exception instanceof CommandException) {
1491 loge("setAllowedCarriers: CommandException: " + ar.exception);
1492 CommandException.Error error =
1493 ((CommandException) (ar.exception)).getCommandError();
1494 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1495 request.result =
1496 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1497 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001498 } else {
1499 loge("setAllowedCarriers: Unknown exception");
1500 }
1501 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001502 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001503 break;
1504
1505 case CMD_GET_ALLOWED_CARRIERS:
1506 request = (MainThreadRequest) msg.obj;
1507 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001508 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001509 break;
1510
1511 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1512 ar = (AsyncResult) msg.obj;
1513 request = (MainThreadRequest) ar.userObj;
1514 if (ar.exception == null && ar.result != null) {
1515 request.result = ar.result;
1516 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001517 request.result = new IllegalStateException(
1518 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001519 if (ar.result == null) {
1520 loge("getAllowedCarriers: Empty response");
1521 } else if (ar.exception instanceof CommandException) {
1522 loge("getAllowedCarriers: CommandException: " +
1523 ar.exception);
1524 } else {
1525 loge("getAllowedCarriers: Unknown exception");
1526 }
1527 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001528 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001529 break;
1530
Nathan Haroldb3014052017-01-25 15:57:32 -08001531 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1532 ar = (AsyncResult) msg.obj;
1533 request = (MainThreadRequest) ar.userObj;
1534 if (ar.exception == null && ar.result != null) {
1535 request.result = ar.result;
1536 } else {
1537 request.result = new IllegalArgumentException(
1538 "Failed to retrieve Forbidden Plmns");
1539 if (ar.result == null) {
1540 loge("getForbiddenPlmns: Empty response");
1541 } else {
1542 loge("getForbiddenPlmns: Unknown exception");
1543 }
1544 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001545 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001546 break;
1547
1548 case CMD_GET_FORBIDDEN_PLMNS:
1549 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001550 uiccPort = getUiccPortFromRequest(request);
1551 if (uiccPort == null) {
1552 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001553 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001554 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001555 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001556 break;
1557 }
1558 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001559 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001560 if (uiccApp == null) {
1561 loge("getForbiddenPlmns() no app with specified type -- "
1562 + appType);
1563 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001564 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001565 break;
1566 } else {
1567 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1568 + " specified type -- " + appType);
1569 }
1570 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1571 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1572 onCompleted);
1573 break;
1574
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001575 case CMD_SWITCH_SLOTS:
1576 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001577 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001578 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001579 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001580 break;
1581
1582 case EVENT_SWITCH_SLOTS_DONE:
1583 ar = (AsyncResult) msg.obj;
1584 request = (MainThreadRequest) ar.userObj;
1585 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001586 notifyRequester(request);
1587 break;
1588 case CMD_GET_NETWORK_SELECTION_MODE:
1589 request = (MainThreadRequest) msg.obj;
1590 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1591 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1592 break;
1593
1594 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1595 ar = (AsyncResult) msg.obj;
1596 request = (MainThreadRequest) ar.userObj;
1597 if (ar.exception != null) {
1598 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1599 } else {
1600 int mode = ((int[]) ar.result)[0];
1601 if (mode == 0) {
1602 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1603 } else {
1604 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1605 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001606 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001607 notifyRequester(request);
1608 break;
1609 case CMD_GET_CDMA_ROAMING_MODE:
1610 request = (MainThreadRequest) msg.obj;
1611 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1612 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1613 break;
1614 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1615 ar = (AsyncResult) msg.obj;
1616 request = (MainThreadRequest) ar.userObj;
1617 if (ar.exception != null) {
1618 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1619 } else {
1620 request.result = ((int[]) ar.result)[0];
1621 }
1622 notifyRequester(request);
1623 break;
1624 case CMD_SET_CDMA_ROAMING_MODE:
1625 request = (MainThreadRequest) msg.obj;
1626 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1627 int mode = (int) request.argument;
1628 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1629 break;
1630 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1631 ar = (AsyncResult) msg.obj;
1632 request = (MainThreadRequest) ar.userObj;
1633 request.result = ar.exception == null;
1634 notifyRequester(request);
1635 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001636 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1637 request = (MainThreadRequest) msg.obj;
1638 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1639 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1640 break;
1641 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1642 ar = (AsyncResult) msg.obj;
1643 request = (MainThreadRequest) ar.userObj;
1644 if (ar.exception != null) {
1645 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1646 } else {
1647 request.result = ((int[]) ar.result)[0];
1648 }
1649 notifyRequester(request);
1650 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001651 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1652 request = (MainThreadRequest) msg.obj;
1653 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1654 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001655 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1656 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001657 break;
1658 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1659 ar = (AsyncResult) msg.obj;
1660 request = (MainThreadRequest) ar.userObj;
1661 request.result = ar.exception == null;
1662 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001663 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001664 case CMD_GET_ALL_CELL_INFO:
1665 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001666 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001667 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001668 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001669 case EVENT_GET_ALL_CELL_INFO_DONE:
1670 ar = (AsyncResult) msg.obj;
1671 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001672 // If a timeout occurs, the response will be null
1673 request.result = (ar.exception == null && ar.result != null)
1674 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001675 synchronized (request) {
1676 request.notifyAll();
1677 }
1678 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001679 case CMD_REQUEST_CELL_INFO_UPDATE:
1680 request = (MainThreadRequest) msg.obj;
1681 request.phone.requestCellInfoUpdate(request.workSource,
1682 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1683 break;
1684 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1685 ar = (AsyncResult) msg.obj;
1686 request = (MainThreadRequest) ar.userObj;
1687 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1688 try {
1689 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001690 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001691 cb.onError(
1692 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1693 ar.exception.getClass().getName(),
1694 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001695 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001696 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001697 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001698 } else {
1699 // use the result as returned
1700 cb.onCellInfo((List<CellInfo>) ar.result);
1701 }
1702 } catch (RemoteException re) {
1703 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1704 }
1705 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001706 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001707 request = (MainThreadRequest) msg.obj;
1708 WorkSource ws = (WorkSource) request.argument;
1709 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001710 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001711 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001712 }
1713 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001714 ar = (AsyncResult) msg.obj;
1715 request = (MainThreadRequest) ar.userObj;
1716 if (ar.exception == null) {
1717 request.result = ar.result;
1718 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001719 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001720 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001721 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001722 }
1723
1724 synchronized (request) {
1725 request.notifyAll();
1726 }
1727 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001728 }
chen xu6dac5ab2018-10-26 17:39:23 -07001729 case CMD_MODEM_REBOOT:
1730 request = (MainThreadRequest) msg.obj;
1731 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001732 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001733 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001734 case EVENT_CMD_MODEM_REBOOT_DONE:
1735 handleNullReturnEvent(msg, "rebootModem");
1736 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001737 case CMD_REQUEST_ENABLE_MODEM:
1738 request = (MainThreadRequest) msg.obj;
1739 boolean enable = (boolean) request.argument;
1740 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001741 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001742 PhoneConfigurationManager.getInstance()
1743 .enablePhone(request.phone, enable, onCompleted);
1744 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001745 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001746 ar = (AsyncResult) msg.obj;
1747 request = (MainThreadRequest) ar.userObj;
1748 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001749 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001750 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001751 if ((boolean) request.result) {
1752 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1753 updateModemStateMetrics();
1754 } else {
1755 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1756 + ar.exception);
1757 }
1758 notifyRequester(request);
1759 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001760 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001761 case CMD_GET_MODEM_STATUS:
1762 request = (MainThreadRequest) msg.obj;
1763 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1764 PhoneConfigurationManager.getInstance()
1765 .getPhoneStatusFromModem(request.phone, onCompleted);
1766 break;
1767 case EVENT_GET_MODEM_STATUS_DONE:
1768 ar = (AsyncResult) msg.obj;
1769 request = (MainThreadRequest) ar.userObj;
1770 int id = request.phone.getPhoneId();
1771 if (ar.exception == null && ar.result != null) {
1772 request.result = ar.result;
1773 //update the cache as modem status has changed
1774 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1775 (boolean) request.result);
1776 } else {
1777 // Return true if modem status cannot be retrieved. For most cases,
1778 // modem status is on. And for older version modems, GET_MODEM_STATUS
1779 // and disable modem are not supported. Modem is always on.
1780 // TODO: this should be fixed in R to support a third
1781 // status UNKNOWN b/131631629
1782 request.result = true;
1783 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1784 + ar.exception);
1785 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001786 notifyRequester(request);
1787 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001788 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1789 request = (MainThreadRequest) msg.obj;
1790 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1791 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1792 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1793 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1794 break;
1795 }
1796 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1797 ar = (AsyncResult) msg.obj;
1798 request = (MainThreadRequest) ar.userObj;
1799 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1800 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1801 args.second.accept(ar.exception == null);
1802 notifyRequester(request);
1803 break;
1804 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001805 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1806 request = (MainThreadRequest) msg.obj;
1807 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1808 Phone phone = getPhoneFromRequest(request);
1809 if (phone != null) {
1810 phone.getSystemSelectionChannels(onCompleted);
1811 } else {
1812 loge("getSystemSelectionChannels: No phone object");
1813 request.result = new ArrayList<RadioAccessSpecifier>();
1814 notifyRequester(request);
1815 }
1816 break;
1817 }
1818 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1819 ar = (AsyncResult) msg.obj;
1820 request = (MainThreadRequest) ar.userObj;
1821 if (ar.exception == null && ar.result != null) {
1822 request.result = ar.result;
1823 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001824 request.result = new IllegalStateException(
1825 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001826 if (ar.result == null) {
1827 loge("getSystemSelectionChannels: Empty response");
1828 } else {
1829 loge("getSystemSelectionChannels: Unknown exception");
1830 }
1831 }
1832 notifyRequester(request);
1833 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001834 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1835 ar = (AsyncResult) msg.obj;
1836 request = (MainThreadRequest) ar.userObj;
1837 if (ar.exception == null && ar.result != null) {
1838 request.result = ar.result;
1839 } else {
1840 request.result = -1;
1841 loge("Failed to set Forbidden Plmns");
1842 if (ar.result == null) {
1843 loge("setForbidenPlmns: Empty response");
1844 } else if (ar.exception != null) {
1845 loge("setForbiddenPlmns: Exception: " + ar.exception);
1846 request.result = -1;
1847 } else {
1848 loge("setForbiddenPlmns: Unknown exception");
1849 }
1850 }
1851 notifyRequester(request);
1852 break;
1853 case CMD_SET_FORBIDDEN_PLMNS:
1854 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001855 uiccPort = getUiccPortFromRequest(request);
1856 if (uiccPort == null) {
1857 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001858 request.result = -1;
1859 notifyRequester(request);
1860 break;
1861 }
1862 Pair<Integer, List<String>> setFplmnsArgs =
1863 (Pair<Integer, List<String>>) request.argument;
1864 appType = setFplmnsArgs.first;
1865 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001866 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001867 if (uiccApp == null) {
1868 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1869 request.result = -1;
1870 loge("Failed to get UICC App");
1871 notifyRequester(request);
1872 } else {
1873 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1874 ((SIMRecords) uiccApp.getIccRecords())
1875 .setForbiddenPlmns(onCompleted, fplmns);
1876 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001877 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001878 case CMD_ERASE_MODEM_CONFIG:
1879 request = (MainThreadRequest) msg.obj;
1880 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1881 defaultPhone.eraseModemConfig(onCompleted);
1882 break;
1883 case EVENT_ERASE_MODEM_CONFIG_DONE:
1884 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001885 break;
zoey chene02881a2019-12-30 16:11:23 +08001886
Kai Shif70f46f2021-03-03 13:59:46 -08001887 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1888 request = (MainThreadRequest) msg.obj;
1889 request.result = defaultPhone.eraseDataInSharedPreferences();
1890 notifyRequester(request);
1891 break;
1892
zoey chene02881a2019-12-30 16:11:23 +08001893 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1894 request = (MainThreadRequest) msg.obj;
1895 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1896 Pair<String, String> changed = (Pair<String, String>) request.argument;
1897 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1898 changed.first, changed.second, onCompleted);
1899 break;
1900 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1901 ar = (AsyncResult) msg.obj;
1902 request = (MainThreadRequest) ar.userObj;
1903 if (ar.exception == null) {
1904 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001905 // If the operation is successful, update the PIN storage
1906 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1907 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001908 UiccController.getInstance().getPinStorage()
1909 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001910 } else {
1911 request.result = msg.arg1;
1912 }
1913 notifyRequester(request);
1914 break;
1915
Michele Berionne5e411512020-11-13 02:36:59 +00001916 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001917 request = (MainThreadRequest) msg.obj;
1918 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1919 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1920 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1921 enabled.first, enabled.second, onCompleted);
1922 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001923 }
zoey chene02881a2019-12-30 16:11:23 +08001924 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1925 ar = (AsyncResult) msg.obj;
1926 request = (MainThreadRequest) ar.userObj;
1927 if (ar.exception == null) {
1928 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001929 // If the operation is successful, update the PIN storage
1930 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1931 int phoneId = getPhoneFromRequest(request).getPhoneId();
1932 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001933 UiccController.getInstance().getPinStorage()
1934 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001935 } else {
1936 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1937 }
zoey chene02881a2019-12-30 16:11:23 +08001938 } else {
1939 request.result = msg.arg1;
1940 }
Michele Berionne5e411512020-11-13 02:36:59 +00001941
1942
zoey chene02881a2019-12-30 16:11:23 +08001943 notifyRequester(request);
1944 break;
1945
Peter Wangdafb9ac2020-01-15 14:13:38 -08001946 case MSG_NOTIFY_USER_ACTIVITY:
1947 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001948 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001949 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1950 getDefaultPhone().getContext().sendBroadcastAsUser(
1951 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1952 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001953
1954 case CMD_SET_DATA_THROTTLING: {
1955 request = (MainThreadRequest) msg.obj;
1956 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1957 DataThrottlingRequest dataThrottlingRequest =
1958 (DataThrottlingRequest) request.argument;
1959 Phone phone = getPhoneFromRequest(request);
1960 if (phone != null) {
1961 phone.setDataThrottling(onCompleted,
1962 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1963 dataThrottlingRequest.getCompletionDurationMillis());
1964 } else {
1965 loge("setDataThrottling: No phone object");
1966 request.result =
1967 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1968 notifyRequester(request);
1969 }
1970
1971 break;
1972 }
1973 case EVENT_SET_DATA_THROTTLING_DONE:
1974 ar = (AsyncResult) msg.obj;
1975 request = (MainThreadRequest) ar.userObj;
1976
1977 if (ar.exception == null) {
1978 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1979 } else if (ar.exception instanceof CommandException) {
1980 loge("setDataThrottling: CommandException: " + ar.exception);
1981 CommandException.Error error =
1982 ((CommandException) (ar.exception)).getCommandError();
1983
1984 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1985 request.result = TelephonyManager
1986 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1987 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1988 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001989 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1990 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001991 } else {
1992 request.result =
1993 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1994 }
1995 } else {
1996 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1997 }
1998 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1999 notifyRequester(request);
2000 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002001
2002 case CMD_SET_SIM_POWER: {
2003 request = (MainThreadRequest) msg.obj;
2004 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2005 request = (MainThreadRequest) msg.obj;
2006 int stateToSet =
2007 ((Pair<Integer, IIntegerConsumer>)
2008 request.argument).first;
2009 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2010 break;
2011 }
2012 case EVENT_SET_SIM_POWER_DONE: {
2013 ar = (AsyncResult) msg.obj;
2014 request = (MainThreadRequest) ar.userObj;
2015 IIntegerConsumer callback =
2016 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2017 if (ar.exception != null) {
2018 loge("setSimPower exception: " + ar.exception);
2019 int errorCode = TelephonyManager.CallForwardingInfoCallback
2020 .RESULT_ERROR_UNKNOWN;
2021 if (ar.exception instanceof CommandException) {
2022 CommandException.Error error =
2023 ((CommandException) (ar.exception)).getCommandError();
2024 if (error == CommandException.Error.SIM_ERR) {
2025 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2026 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2027 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2028 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2029 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2030 } else {
2031 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2032 }
2033 }
2034 try {
2035 callback.accept(errorCode);
2036 } catch (RemoteException e) {
2037 // Ignore if the remote process is no longer available to call back.
2038 Log.w(LOG_TAG, "setSimPower: callback not available.");
2039 }
2040 } else {
2041 try {
2042 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2043 } catch (RemoteException e) {
2044 // Ignore if the remote process is no longer available to call back.
2045 Log.w(LOG_TAG, "setSimPower: callback not available.");
2046 }
2047 }
2048 break;
2049 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002050 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2051 request = (MainThreadRequest) msg.obj;
2052
2053 final Phone phone = getPhoneFromRequest(request);
2054 if (phone == null || phone.getServiceStateTracker() == null) {
2055 request.result = new IllegalStateException("Phone or SST is null");
2056 notifyRequester(request);
2057 break;
2058 }
2059
2060 Pair<Integer, SignalStrengthUpdateRequest> pair =
2061 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2062 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2063 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002064 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002065 request.subId, pair.first /*callingUid*/,
2066 pair.second /*request*/, onCompleted);
2067 break;
2068 }
2069 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2070 ar = (AsyncResult) msg.obj;
2071 request = (MainThreadRequest) ar.userObj;
2072 // request.result will be the exception of ar if present, true otherwise.
2073 // Be cautious not to leave result null which will wait() forever
2074 request.result = ar.exception != null ? ar.exception : true;
2075 notifyRequester(request);
2076 break;
2077 }
2078 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2079 request = (MainThreadRequest) msg.obj;
2080
2081 Phone phone = getPhoneFromRequest(request);
2082 if (phone == null || phone.getServiceStateTracker() == null) {
2083 request.result = new IllegalStateException("Phone or SST is null");
2084 notifyRequester(request);
2085 break;
2086 }
2087
2088 Pair<Integer, SignalStrengthUpdateRequest> pair =
2089 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2090 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2091 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002092 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002093 request.subId, pair.first /*callingUid*/,
2094 pair.second /*request*/, onCompleted);
2095 break;
2096 }
2097 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2098 ar = (AsyncResult) msg.obj;
2099 request = (MainThreadRequest) ar.userObj;
2100 request.result = ar.exception != null ? ar.exception : true;
2101 notifyRequester(request);
2102 break;
2103 }
Jordan Liu109698e2020-11-24 14:50:34 -08002104
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002105 case CMD_GET_SLICING_CONFIG: {
2106 request = (MainThreadRequest) msg.obj;
2107 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2108 request.phone.getSlicingConfig(onCompleted);
2109 break;
2110 }
2111 case EVENT_GET_SLICING_CONFIG_DONE: {
2112 ar = (AsyncResult) msg.obj;
2113 request = (MainThreadRequest) ar.userObj;
2114 ResultReceiver result = (ResultReceiver) request.argument;
2115
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002116 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002117 Bundle bundle = new Bundle();
2118 int resultCode = 0;
2119 if (ar.exception != null) {
2120 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2121 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002122 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002123 } else if (ar.result == null) {
2124 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002125 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002126 } else {
2127 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002128 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2129 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002130 }
2131
2132 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002133 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002134 }
2135 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2136 result.send(resultCode, bundle);
2137 notifyRequester(request);
2138 break;
2139 }
2140
Michele Berionne5e411512020-11-13 02:36:59 +00002141 case CMD_PREPARE_UNATTENDED_REBOOT:
2142 request = (MainThreadRequest) msg.obj;
2143 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002144 UiccController.getInstance().getPinStorage()
2145 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002146 notifyRequester(request);
2147 break;
2148
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 default:
2150 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2151 break;
2152 }
2153 }
Jake Hambye994d462014-02-03 13:10:13 -08002154
Pengquan Menga1bb6272018-09-06 09:59:22 -07002155 private void notifyRequester(MainThreadRequest request) {
2156 synchronized (request) {
2157 request.notifyAll();
2158 }
2159 }
2160
Jake Hambye994d462014-02-03 13:10:13 -08002161 private void handleNullReturnEvent(Message msg, String command) {
2162 AsyncResult ar = (AsyncResult) msg.obj;
2163 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2164 if (ar.exception == null) {
2165 request.result = true;
2166 } else {
2167 request.result = false;
2168 if (ar.exception instanceof CommandException) {
2169 loge(command + ": CommandException: " + ar.exception);
2170 } else {
2171 loge(command + ": Unknown exception");
2172 }
2173 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002174 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176 }
2177
2178 /**
2179 * Posts the specified command to be executed on the main thread,
2180 * waits for the request to complete, and returns the result.
2181 * @see #sendRequestAsync
2182 */
2183 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002184 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2185 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002186 }
2187
2188 /**
2189 * Posts the specified command to be executed on the main thread,
2190 * waits for the request to complete, and returns the result.
2191 * @see #sendRequestAsync
2192 */
2193 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2194 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002195 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002196 }
2197
2198 /**
2199 * Posts the specified command to be executed on the main thread,
2200 * waits for the request to complete, and returns the result.
2201 * @see #sendRequestAsync
2202 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002203 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002204 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2205 }
2206
2207 /**
2208 * Posts the specified command to be executed on the main thread,
2209 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2210 * if not timeout or null otherwise.
2211 * @see #sendRequestAsync
2212 */
2213 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2214 long timeoutInMs) {
2215 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002216 }
2217
2218 /**
2219 * Posts the specified command to be executed on the main thread,
2220 * waits for the request to complete, and returns the result.
2221 * @see #sendRequestAsync
2222 */
Nathan Harold92bed182018-10-12 18:16:49 -07002223 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002224 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002225 }
2226
2227 /**
2228 * Posts the specified command to be executed on the main thread,
2229 * waits for the request to complete, and returns the result.
2230 * @see #sendRequestAsync
2231 */
2232 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002233 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2234 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002235 }
2236
2237 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002238 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2239 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2240 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002241 * @see #sendRequestAsync
2242 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002243 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2244 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2246 throw new RuntimeException("This method will deadlock if called from the main thread.");
2247 }
2248
Nathan Harold92bed182018-10-12 18:16:49 -07002249 MainThreadRequest request = null;
2250 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2251 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2252 } else if (phone != null) {
2253 request = new MainThreadRequest(argument, phone, workSource);
2254 } else {
2255 request = new MainThreadRequest(argument, subId, workSource);
2256 }
2257
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 Message msg = mMainThreadHandler.obtainMessage(command, request);
2259 msg.sendToTarget();
2260
Rambo Wang0f050d82021-02-12 11:43:36 -08002261
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002263 if (timeoutInMs >= 0) {
2264 // Wait for at least timeoutInMs before returning null request result
2265 long now = SystemClock.elapsedRealtime();
2266 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002267 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002268 try {
2269 request.wait(deadline - now);
2270 } catch (InterruptedException e) {
2271 // Do nothing, go back and check if request is completed or timeout
2272 } finally {
2273 now = SystemClock.elapsedRealtime();
2274 }
2275 }
2276 } else {
2277 // Wait for the request to complete
2278 while (request.result == null) {
2279 try {
2280 request.wait();
2281 } catch (InterruptedException e) {
2282 // Do nothing, go back and wait until the request is complete
2283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 }
2285 }
2286 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002287 if (request.result == null) {
2288 Log.wtf(LOG_TAG,
2289 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 return request.result;
2292 }
2293
2294 /**
2295 * Asynchronous ("fire and forget") version of sendRequest():
2296 * Posts the specified command to be executed on the main thread, and
2297 * returns immediately.
2298 * @see #sendRequest
2299 */
2300 private void sendRequestAsync(int command) {
2301 mMainThreadHandler.sendEmptyMessage(command);
2302 }
2303
2304 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002305 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002306 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002307 */
2308 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002309 sendRequestAsync(command, argument, null, null);
2310 }
2311
2312 /**
2313 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2314 * @see {@link #sendRequest(int,Object)}
2315 */
2316 private void sendRequestAsync(
2317 int command, Object argument, Phone phone, WorkSource workSource) {
2318 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002319 Message msg = mMainThreadHandler.obtainMessage(command, request);
2320 msg.sendToTarget();
2321 }
2322
2323 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 * Initialize the singleton PhoneInterfaceManager instance.
2325 * This is only done once, at startup, from PhoneApp.onCreate().
2326 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002327 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002328 synchronized (PhoneInterfaceManager.class) {
2329 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002330 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 } else {
2332 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2333 }
2334 return sInstance;
2335 }
2336 }
2337
2338 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002339 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002342 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002343 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002345 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002347 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002348 mTelephonySharedPreferences =
2349 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002350 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002351 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002352 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002353 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002354 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukiermand6cae882022-12-29 12:02:31 -05002355 mTelephony2gUpdater = new Telephony2gUpdater(mApp);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002356 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 publish();
2358 }
2359
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002360 private Phone getDefaultPhone() {
2361 Phone thePhone = getPhone(getDefaultSubscription());
2362 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2363 }
2364
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365 private void publish() {
2366 if (DBG) log("publish: " + this);
2367
Peter Wangc035ce42020-01-08 21:00:22 -08002368 TelephonyFrameworkInitializer
2369 .getTelephonyServiceManager()
2370 .getTelephonyServiceRegisterer()
2371 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 }
2373
Stuart Scott584921c2015-01-15 17:10:34 -08002374 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002375 if (request.phone != null) {
2376 return request.phone;
2377 } else {
2378 return getPhoneFromSubId(request.subId);
2379 }
2380 }
2381
2382 private Phone getPhoneFromSubId(int subId) {
2383 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2384 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002385 }
2386
Rambo Wange53e07d2022-05-10 13:01:13 -07002387 @Nullable
2388 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002389 Phone phone = getPhoneFromRequest(request);
2390 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002391 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002392 }
2393
Wink Saville36469e72014-06-11 15:17:00 -07002394 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002395 private Phone getPhone(int subId) {
Jack Yudf049d72022-12-02 22:48:35 -08002396 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002398
Kai Shif70f46f2021-03-03 13:59:46 -08002399 private void sendEraseModemConfig(@NonNull Phone phone) {
2400 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2401 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2402 }
2403
2404 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2405 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2406 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002407 }
2408
Peter Wang44b186e2020-01-13 23:33:09 -08002409 private boolean isImsAvailableOnDevice() {
2410 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2411 if (pm == null) {
2412 // For some reason package manger is not available.. This will fail internally anyway,
2413 // so do not throw error and allow.
2414 return true;
2415 }
2416 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2417 }
2418
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002420 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002421 }
2422
Wink Savilleb564aae2014-10-23 10:18:09 -07002423 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 if (DBG) log("dial: " + number);
2425 // No permission check needed here: This is just a wrapper around the
2426 // ACTION_DIAL intent, which is available to any app since it puts up
2427 // the UI before it does anything.
2428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002429 final long identity = Binder.clearCallingIdentity();
2430 try {
2431 String url = createTelUrl(number);
2432 if (url == null) {
2433 return;
2434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002436 // PENDING: should we just silently fail if phone is offhook or ringing?
2437 PhoneConstants.State state = mCM.getState(subId);
2438 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2439 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2440 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2441 mApp.startActivity(intent);
2442 }
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 }
2446 }
2447
2448 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002449 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002450 }
2451
Wink Savilleb564aae2014-10-23 10:18:09 -07002452 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 if (DBG) log("call: " + number);
2454
2455 // This is just a wrapper around the ACTION_CALL intent, but we still
2456 // need to do a permission check since we're calling startActivity()
2457 // from the context of the phone app.
2458 enforceCallPermission();
2459
Jordan Liu1617b712019-07-10 15:06:26 -07002460 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 != AppOpsManager.MODE_ALLOWED) {
2462 return;
2463 }
2464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 String url = createTelUrl(number);
2468 if (url == null) {
2469 return;
2470 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472 boolean isValid = false;
2473 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2474 if (slist != null) {
2475 for (SubscriptionInfo subInfoRecord : slist) {
2476 if (subInfoRecord.getSubscriptionId() == subId) {
2477 isValid = true;
2478 break;
2479 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002480 }
Wink Saville08874612014-08-31 19:19:58 -07002481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482 if (!isValid) {
2483 return;
2484 }
Wink Saville08874612014-08-31 19:19:58 -07002485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2487 intent.putExtra(SUBSCRIPTION_KEY, subId);
2488 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2489 mApp.startActivity(intent);
2490 } finally {
2491 Binder.restoreCallingIdentity(identity);
2492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 }
2494
Wink Savilleb564aae2014-10-23 10:18:09 -07002495 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002496 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002497 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2498 }
2499
Wink Savilleb564aae2014-10-23 10:18:09 -07002500 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002501 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002502 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2503 }
2504
Wink Savilleb564aae2014-10-23 10:18:09 -07002505 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507
2508 final long identity = Binder.clearCallingIdentity();
2509 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002510 Phone phone = getPhone(subId);
2511 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 checkSimPin.start();
2513 return checkSimPin.unlockSim(null, pin);
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
2516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
Wink Savilleb564aae2014-10-23 10:18:09 -07002519 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002521
2522 final long identity = Binder.clearCallingIdentity();
2523 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002524 Phone phone = getPhone(subId);
2525 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002526 checkSimPuk.start();
2527 return checkSimPuk.unlockSim(puk, pin);
2528 } finally {
2529 Binder.restoreCallingIdentity(identity);
2530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 }
2532
2533 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002534 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002535 * a synchronous one.
2536 */
2537 private static class UnlockSim extends Thread {
2538
2539 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002540 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541
2542 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002543 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2544 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002545
2546 // For replies from SimCard interface
2547 private Handler mHandler;
2548
2549 // For async handler to identify request type
2550 private static final int SUPPLY_PIN_COMPLETE = 100;
2551
Michele Berionne5e411512020-11-13 02:36:59 +00002552 UnlockSim(int phoneId, IccCard simCard) {
2553 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 mSimCard = simCard;
2555 }
2556
2557 @Override
2558 public void run() {
2559 Looper.prepare();
2560 synchronized (UnlockSim.this) {
2561 mHandler = new Handler() {
2562 @Override
2563 public void handleMessage(Message msg) {
2564 AsyncResult ar = (AsyncResult) msg.obj;
2565 switch (msg.what) {
2566 case SUPPLY_PIN_COMPLETE:
2567 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2568 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002569 mRetryCount = msg.arg1;
2570 if (ar.exception != null) {
2571 if (ar.exception instanceof CommandException &&
2572 ((CommandException)(ar.exception)).getCommandError()
2573 == CommandException.Error.PASSWORD_INCORRECT) {
2574 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002575 } //When UiccCardApp dispose,handle message and return exception
2576 else if (ar.exception instanceof CommandException &&
2577 ((CommandException) (ar.exception)).getCommandError()
2578 == CommandException.Error.ABORTED) {
2579 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002580 } else {
2581 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2582 }
2583 } else {
2584 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 mDone = true;
2587 UnlockSim.this.notifyAll();
2588 }
2589 break;
2590 }
2591 }
2592 };
2593 UnlockSim.this.notifyAll();
2594 }
2595 Looper.loop();
2596 }
2597
2598 /*
2599 * Use PIN or PUK to unlock SIM card
2600 *
2601 * If PUK is null, unlock SIM card with PIN
2602 *
2603 * If PUK is not null, unlock SIM card with PUK and set PIN code
2604 */
Wink Saville9de0f752013-10-22 19:04:03 -07002605 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606
2607 while (mHandler == null) {
2608 try {
2609 wait();
2610 } catch (InterruptedException e) {
2611 Thread.currentThread().interrupt();
2612 }
2613 }
2614 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2615
2616 if (puk == null) {
2617 mSimCard.supplyPin(pin, callback);
2618 } else {
2619 mSimCard.supplyPuk(puk, pin, callback);
2620 }
2621
2622 while (!mDone) {
2623 try {
2624 Log.d(LOG_TAG, "wait for done");
2625 wait();
2626 } catch (InterruptedException e) {
2627 // Restore the interrupted status
2628 Thread.currentThread().interrupt();
2629 }
2630 }
2631 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002632 int[] resultArray = new int[2];
2633 resultArray[0] = mResult;
2634 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002635
2636 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002637 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002638 }
2639
Wink Saville9de0f752013-10-22 19:04:03 -07002640 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002641 }
2642 }
2643
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002644 /**
2645 * This method has been removed due to privacy and stability concerns.
2646 */
2647 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002649 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2650 return;
Wink Saville36469e72014-06-11 15:17:00 -07002651 }
2652
Nathan Harold1f889d82020-06-04 17:05:26 -07002653 @Override
2654 public void updateServiceLocationWithPackageName(String callingPackage) {
2655 mApp.getSystemService(AppOpsManager.class)
2656 .checkPackage(Binder.getCallingUid(), callingPackage);
2657
Nathan Haroldf096d982020-11-18 17:18:06 -08002658 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002659 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2660 // Callers targeting S have no business invoking this method.
2661 return;
2662 }
2663
2664 LocationAccessPolicy.LocationPermissionResult locationResult =
2665 LocationAccessPolicy.checkLocationPermission(mApp,
2666 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2667 .setCallingPackage(callingPackage)
2668 .setCallingFeatureId(null)
2669 .setCallingPid(Binder.getCallingPid())
2670 .setCallingUid(Binder.getCallingUid())
2671 .setMethod("updateServiceLocation")
2672 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2673 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2674 .build());
2675 // Apps that lack location permission have no business calling this method;
2676 // however, because no permission was declared in the public API, denials must
2677 // all be "soft".
2678 switch (locationResult) {
2679 case DENIED_HARD: /* fall through */
2680 case DENIED_SOFT:
2681 return;
2682 }
2683
2684 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685 final long identity = Binder.clearCallingIdentity();
2686 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002687 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002689 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690 }
2691 } finally {
2692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 }
2695
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002696 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002697 @Override
2698 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002699 return isRadioOnWithFeature(callingPackage, null);
2700 }
2701
2702
2703 @Override
2704 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2705 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2706 callingFeatureId);
2707 }
2708
2709 @Deprecated
2710 @Override
2711 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2712 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002713 }
2714
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002715 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002716 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2717 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002719 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002720 return false;
2721 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722
2723 final long identity = Binder.clearCallingIdentity();
2724 try {
2725 return isRadioOnForSubscriber(subId);
2726 } finally {
2727 Binder.restoreCallingIdentity(identity);
2728 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002729 }
2730
2731 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002732 final long identity = Binder.clearCallingIdentity();
2733 try {
2734 final Phone phone = getPhone(subId);
2735 if (phone != null) {
2736 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2737 } else {
2738 return false;
2739 }
2740 } finally {
2741 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002742 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 }
2744
2745 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002746 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002747 }
Wink Saville36469e72014-06-11 15:17:00 -07002748
Wink Savilleb564aae2014-10-23 10:18:09 -07002749 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002750 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002751
2752 final long identity = Binder.clearCallingIdentity();
2753 try {
2754 final Phone phone = getPhone(subId);
2755 if (phone != null) {
2756 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2757 }
2758 } finally {
2759 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002760 }
Wink Saville36469e72014-06-11 15:17:00 -07002761 }
2762
2763 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002764 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002765 }
2766
Wink Savilleb564aae2014-10-23 10:18:09 -07002767 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002768 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769
2770 final long identity = Binder.clearCallingIdentity();
2771 try {
2772 final Phone phone = getPhone(subId);
2773 if (phone == null) {
2774 return false;
2775 }
2776 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2777 toggleRadioOnOffForSubscriber(subId);
2778 }
2779 return true;
2780 } finally {
2781 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002782 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 }
Wink Saville36469e72014-06-11 15:17:00 -07002784
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002785 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002786 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002787 /*
2788 * If any of the Radios are available, it will need to be
2789 * shutdown. So return true if any Radio is available.
2790 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 final long identity = Binder.clearCallingIdentity();
2792 try {
2793 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2794 Phone phone = PhoneFactory.getPhone(i);
2795 if (phone != null && phone.isRadioAvailable()) return true;
2796 }
2797 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2798 return false;
2799 } finally {
2800 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002801 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002802 }
2803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002805 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 enforceModifyPermission();
2807
2808 final long identity = Binder.clearCallingIdentity();
2809 try {
2810 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2811 logv("Shutting down Phone " + i);
2812 shutdownRadioUsingPhoneId(i);
2813 }
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002816 }
2817 }
2818
2819 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002820 Phone phone = PhoneFactory.getPhone(phoneId);
2821 if (phone != null && phone.isRadioAvailable()) {
2822 phone.shutdownRadio();
2823 }
2824 }
2825
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002826 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002827 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828
2829 final long identity = Binder.clearCallingIdentity();
2830 try {
2831 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2832 if (defaultPhone != null) {
2833 defaultPhone.setRadioPower(turnOn);
2834 return true;
2835 } else {
2836 loge("There's no default phone.");
2837 return false;
2838 }
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002841 }
Wink Saville36469e72014-06-11 15:17:00 -07002842 }
2843
Wink Savilleb564aae2014-10-23 10:18:09 -07002844 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002845 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846
2847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 final Phone phone = getPhone(subId);
2850 if (phone != null) {
2851 phone.setRadioPower(turnOn);
2852 return true;
2853 } else {
2854 return false;
2855 }
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 }
2860
Wink Saville36469e72014-06-11 15:17:00 -07002861 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002862 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002863 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002864 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865
2866 final long identity = Binder.clearCallingIdentity();
2867 try {
Jack Yudf049d72022-12-02 22:48:35 -08002868 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869 final Phone phone = getPhone(subId);
2870 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002871 phone.getDataSettingsManager().setDataEnabled(
2872 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002873 return true;
2874 } else {
2875 return false;
2876 }
2877 } finally {
2878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 }
2881
Wink Saville36469e72014-06-11 15:17:00 -07002882 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002883 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002884 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002885 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002886
2887 final long identity = Binder.clearCallingIdentity();
2888 try {
Jack Yudf049d72022-12-02 22:48:35 -08002889 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 final Phone phone = getPhone(subId);
2891 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002892 phone.getDataSettingsManager().setDataEnabled(
2893 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894 return true;
2895 } else {
2896 return false;
2897 }
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901 }
2902
Sanket Padawe356d7632015-06-22 14:03:32 -07002903 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002904 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 final Phone phone = getPhone(subId);
2908 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07002909 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 } else {
2911 return false;
2912 }
2913 } finally {
2914 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002916 }
2917
2918 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002919 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002920 }
2921
pkanwarae03a6b2016-11-06 20:37:09 -08002922 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923 enforceCallPermission();
2924
2925 final long identity = Binder.clearCallingIdentity();
2926 try {
2927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2928 return;
2929 }
2930 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2931 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2932 } finally {
2933 Binder.restoreCallingIdentity(identity);
2934 }
pkanwar32d516d2016-10-14 19:37:38 -07002935 };
2936
Wink Savilleb564aae2014-10-23 10:18:09 -07002937 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002938 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939
2940 final long identity = Binder.clearCallingIdentity();
2941 try {
2942 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2943 return false;
2944 }
2945 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2946 } finally {
2947 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002949 }
2950
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002951 /**
2952 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2953 * tag on getCallState Binder call.
2954 */
2955 @Deprecated
2956 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002957 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002958 if (CompatChanges.isChangeEnabled(
2959 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2960 Binder.getCallingUid())) {
2961 // Do not allow this API to be called on API version 31+, it should only be
2962 // called on old apps using this Binder call directly.
2963 throw new SecurityException("This method can only be used for applications "
2964 + "targeting API version 30 or less.");
2965 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002966 final long identity = Binder.clearCallingIdentity();
2967 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002968 Phone phone = getPhone(getDefaultSubscription());
2969 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2970 PhoneConstantConversions.convertCallState(phone.getState());
2971 } finally {
2972 Binder.restoreCallingIdentity(identity);
2973 }
2974 }
2975
2976 @Override
2977 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2978 if (CompatChanges.isChangeEnabled(
2979 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2980 Binder.getCallingUid())) {
2981 // Check READ_PHONE_STATE for API version 31+
2982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2983 featureId, "getCallStateForSubscription")) {
2984 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2985 + "targeting API level 31+.");
2986 }
2987 }
2988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2992 PhoneConstantConversions.convertCallState(phone.getState());
2993 } finally {
2994 Binder.restoreCallingIdentity(identity);
2995 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002996 }
2997
Sanket Padawe356d7632015-06-22 14:03:32 -07002998 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002999 public int getDataState() {
Jack Yudf049d72022-12-02 22:48:35 -08003000 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003001 }
3002
3003 @Override
3004 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005 final long identity = Binder.clearCallingIdentity();
3006 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003007 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07003009 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003010 } else {
3011 return PhoneConstantConversions.convertDataState(
3012 PhoneConstants.DataState.DISCONNECTED);
3013 }
3014 } finally {
3015 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003017 }
3018
Sanket Padawe356d7632015-06-22 14:03:32 -07003019 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003020 public @DataActivityType int getDataActivity() {
Jack Yudf049d72022-12-02 22:48:35 -08003021 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003022 }
3023
3024 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003025 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 final long identity = Binder.clearCallingIdentity();
3027 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003028 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003030 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003031 } else {
3032 return TelephonyManager.DATA_ACTIVITY_NONE;
3033 }
3034 } finally {
3035 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003036 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003037 }
3038
3039 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003040 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003041 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003042 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003043
3044 LocationAccessPolicy.LocationPermissionResult locationResult =
3045 LocationAccessPolicy.checkLocationPermission(mApp,
3046 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3047 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003048 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003049 .setCallingPid(Binder.getCallingPid())
3050 .setCallingUid(Binder.getCallingUid())
3051 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003052 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003053 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3054 .build());
3055 switch (locationResult) {
3056 case DENIED_HARD:
3057 throw new SecurityException("Not allowed to access cell location");
3058 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003059 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3060 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061 }
3062
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003063 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064 final long identity = Binder.clearCallingIdentity();
3065 try {
3066 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yudf049d72022-12-02 22:48:35 -08003067 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003068 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
Svetoslav64fad262015-04-14 14:35:21 -07003072 }
3073
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003075 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003076 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3077 // registered cell info, so return a NULL country instead.
3078 final long identity = Binder.clearCallingIdentity();
3079 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003080 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3081 // Get default phone in this case.
3082 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3083 }
Jack Yudf049d72022-12-02 22:48:35 -08003084 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003085 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003086 if (phone == null) return "";
3087 ServiceStateTracker sst = phone.getServiceStateTracker();
3088 if (sst == null) return "";
3089 LocaleTracker lt = sst.getLocaleTracker();
3090 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003091 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003095 }
3096
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003097 /**
3098 * This method was removed due to potential issues caused by performing partial
3099 * updates of service state, and lack of a credible use case.
3100 *
3101 * This has the ability to break the telephony implementation by disabling notification of
3102 * changes in device connectivity. DO NOT USE THIS!
3103 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003104 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003105 public void enableLocationUpdates() {
3106 mApp.enforceCallingOrSelfPermission(
3107 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 }
3109
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003110 /**
3111 * This method was removed due to potential issues caused by performing partial
3112 * updates of service state, and lack of a credible use case.
3113 *
3114 * This has the ability to break the telephony implementation by disabling notification of
3115 * changes in device connectivity. DO NOT USE THIS!
3116 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 @Override
3118 public void disableLocationUpdates() {
3119 mApp.enforceCallingOrSelfPermission(
3120 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003121 }
3122
3123 @Override
3124 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003125 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3126 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003127 try {
3128 mApp.getSystemService(AppOpsManager.class)
3129 .checkPackage(Binder.getCallingUid(), callingPackage);
3130 } catch (SecurityException e) {
3131 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3132 throw e;
3133 }
3134
Nathan Haroldf096d982020-11-18 17:18:06 -08003135 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003136 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3137 throw new SecurityException(
3138 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3139 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003140
Jordan Liu1617b712019-07-10 15:06:26 -07003141 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003142 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3143 return null;
3144 }
Svetoslav64fad262015-04-14 14:35:21 -07003145
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003146 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003147
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003148 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003149 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003150
Nathan Haroldf180aac2018-06-01 18:43:55 -07003151 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3152 for (CellInfo ci : info) {
3153 if (ci instanceof CellInfoGsm) {
3154 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3155 } else if (ci instanceof CellInfoWcdma) {
3156 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003159 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003160 }
3161
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003162 private List<CellInfo> getCachedCellInfo() {
3163 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3164 for (Phone phone : PhoneFactory.getPhones()) {
3165 List<CellInfo> info = phone.getAllCellInfo();
3166 if (info != null) cellInfos.addAll(info);
3167 }
3168 return cellInfos;
3169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170
3171 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003172 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003173 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003174 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003175
3176 LocationAccessPolicy.LocationPermissionResult locationResult =
3177 LocationAccessPolicy.checkLocationPermission(mApp,
3178 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3179 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003180 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003181 .setCallingPid(Binder.getCallingPid())
3182 .setCallingUid(Binder.getCallingUid())
3183 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003184 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003185 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3186 .build());
3187 switch (locationResult) {
3188 case DENIED_HARD:
3189 throw new SecurityException("Not allowed to access cell info");
3190 case DENIED_SOFT:
3191 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003192 }
3193
Nathan Haroldf096d982020-11-18 17:18:06 -08003194 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003195 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3196 return getCachedCellInfo();
3197 }
3198
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003199 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003200 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201 final long identity = Binder.clearCallingIdentity();
3202 try {
3203 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3204 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003205 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003206 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 if (info != null) cellInfos.addAll(info);
3208 }
3209 return cellInfos;
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 }
3213 }
3214
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003215 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003216 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3217 String callingFeatureId) {
3218 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3219 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003220 }
3221
3222 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003223 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3224 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003225 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003226 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003227 }
3228
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003229 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3230 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003231 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003232 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003233
3234 LocationAccessPolicy.LocationPermissionResult locationResult =
3235 LocationAccessPolicy.checkLocationPermission(mApp,
3236 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3237 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003238 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003239 .setCallingPid(Binder.getCallingPid())
3240 .setCallingUid(Binder.getCallingUid())
3241 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003242 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3243 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003244 .build());
3245 switch (locationResult) {
3246 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003247 if (TelephonyPermissions
3248 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003249 // Safetynet logging for b/154934934
3250 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3251 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003252 throw new SecurityException("Not allowed to access cell info");
3253 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003254 if (TelephonyPermissions
3255 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003256 // Safetynet logging for b/154934934
3257 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3258 }
Nathan Harold5320c422019-05-09 10:26:08 -07003259 try {
3260 cb.onCellInfo(new ArrayList<CellInfo>());
3261 } catch (RemoteException re) {
3262 // Drop without consequences
3263 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003264 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003265 }
3266
Nathan Harolda939a962019-05-09 10:13:47 -07003267
3268 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003269 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3270
3271 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3272 }
3273
3274 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003276 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003277 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278
3279 final long identity = Binder.clearCallingIdentity();
3280 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003281 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282 } finally {
3283 Binder.restoreCallingIdentity(identity);
3284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003285 }
3286
Shishir Agrawala9f32182016-04-12 12:00:16 -07003287 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003288 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003289 Phone phone = PhoneFactory.getPhone(slotIndex);
3290 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003291 return null;
3292 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003293 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003294 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003295 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003296 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003297 return null;
3298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003299
3300 final long identity = Binder.clearCallingIdentity();
3301 try {
3302 return phone.getImei();
3303 } finally {
3304 Binder.restoreCallingIdentity(identity);
3305 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003306 }
3307
3308 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003309 public String getTypeAllocationCodeForSlot(int slotIndex) {
3310 Phone phone = PhoneFactory.getPhone(slotIndex);
3311 String tac = null;
3312 if (phone != null) {
3313 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003314 try {
3315 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3316 } catch (IndexOutOfBoundsException e) {
3317 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3318 return null;
3319 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003320 }
3321 return tac;
3322 }
3323
3324 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003325 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003326 try {
3327 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3328 } catch (SecurityException se) {
3329 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3330 throw new SecurityException("Package " + callingPackage + " does not belong to "
3331 + Binder.getCallingUid());
3332 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003333 Phone phone = PhoneFactory.getPhone(slotIndex);
3334 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003335 return null;
3336 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003337
Jeff Davidson913390f2018-02-23 17:11:49 -08003338 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003339 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003340 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003341 return null;
3342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343
3344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 return phone.getMeid();
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
Jack Yu2af8d712017-03-15 17:14:14 -07003350 }
3351
3352 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003353 public String getManufacturerCodeForSlot(int slotIndex) {
3354 Phone phone = PhoneFactory.getPhone(slotIndex);
3355 String manufacturerCode = null;
3356 if (phone != null) {
3357 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003358 try {
3359 manufacturerCode =
3360 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3361 } catch (IndexOutOfBoundsException e) {
3362 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3363 return null;
3364 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003365 }
3366 return manufacturerCode;
3367 }
3368
3369 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003370 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3371 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003372 Phone phone = PhoneFactory.getPhone(slotIndex);
3373 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003374 return null;
3375 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003376 int subId = phone.getSubId();
3377 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003378 mApp, subId, callingPackage, callingFeatureId,
3379 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003380 return null;
3381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382
3383 final long identity = Binder.clearCallingIdentity();
3384 try {
3385 return phone.getDeviceSvn();
3386 } finally {
3387 Binder.restoreCallingIdentity(identity);
3388 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003389 }
3390
fionaxu43304da2017-11-27 22:51:16 -08003391 @Override
3392 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393 final long identity = Binder.clearCallingIdentity();
3394 try {
3395 final Phone phone = getPhone(subId);
3396 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
fionaxu43304da2017-11-27 22:51:16 -08003400 }
3401
3402 @Override
3403 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404 final long identity = Binder.clearCallingIdentity();
3405 try {
3406 final Phone phone = getPhone(subId);
3407 return phone == null ? null : phone.getCarrierName();
3408 } finally {
3409 Binder.restoreCallingIdentity(identity);
3410 }
fionaxu43304da2017-11-27 22:51:16 -08003411 }
3412
calvinpanffe225e2018-11-01 19:43:06 +08003413 @Override
chen xu0026ca62019-03-06 15:28:50 -08003414 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 final Phone phone = getPhone(subId);
3418 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003419 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003420 } finally {
3421 Binder.restoreCallingIdentity(identity);
3422 }
3423 }
3424
3425 @Override
chen xu0026ca62019-03-06 15:28:50 -08003426 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003430 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003431 } finally {
3432 Binder.restoreCallingIdentity(identity);
3433 }
3434 }
3435
chen xu651eec72018-11-11 19:03:44 -08003436 @Override
chen xu864e11c2018-12-06 22:10:03 -08003437 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3438 if (!isSubscriptionMccMnc) {
3439 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3440 }
chen xu651eec72018-11-11 19:03:44 -08003441 final Phone phone = PhoneFactory.getPhone(slotIndex);
3442 if (phone == null) {
3443 return TelephonyManager.UNKNOWN_CARRIER_ID;
3444 }
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
3451 }
3452
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003453 //
3454 // Internal helper methods.
3455 //
3456
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003457 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003458 * Make sure the caller is the calling package itself
3459 *
3460 * @throws SecurityException if the caller is not the calling package
3461 */
3462 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3463 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003464 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3465 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003466 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003467 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003468 } catch (PackageManager.NameNotFoundException e) {
3469 // packageUid is -1
3470 }
3471 if (packageUid != callingUid) {
3472 throw new SecurityException(message + ": Package " + callingPackage
3473 + " does not belong to " + callingUid);
3474 }
3475 }
3476
3477 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003478 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3479 *
3480 * @throws SecurityException if the caller does not have the required permission
3481 */
3482 private void enforceModifyPermission() {
3483 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3484 }
3485
Shuo Qian3b6ee772019-11-13 17:43:31 -08003486 private void enforceActiveEmergencySessionPermission() {
3487 mApp.enforceCallingOrSelfPermission(
3488 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3489 }
3490
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003491 /**
3492 * Make sure the caller has the CALL_PHONE permission.
3493 *
3494 * @throws SecurityException if the caller does not have the required permission
3495 */
3496 private void enforceCallPermission() {
3497 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3498 }
3499
paulhu5a773602019-08-23 19:17:33 +08003500 private void enforceSettingsPermission() {
3501 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003502 }
3503
Michele Berionne5e411512020-11-13 02:36:59 +00003504 private void enforceRebootPermission() {
3505 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3506 }
3507
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508 private String createTelUrl(String number) {
3509 if (TextUtils.isEmpty(number)) {
3510 return null;
3511 }
3512
Jake Hambye994d462014-02-03 13:10:13 -08003513 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003514 }
3515
Ihab Awadf9e92732013-12-05 18:02:52 -08003516 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003517 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3518 }
3519
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003520 private static void logv(String msg) {
3521 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3522 }
3523
Ihab Awadf9e92732013-12-05 18:02:52 -08003524 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003525 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3526 }
3527
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003528 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003529 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003530 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003531 }
3532
Sanket Padawe356d7632015-06-22 14:03:32 -07003533 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003534 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 final Phone phone = PhoneFactory.getPhone(slotIndex);
3538 if (phone == null) {
3539 return PhoneConstants.PHONE_TYPE_NONE;
3540 } else {
3541 return phone.getPhoneType();
3542 }
3543 } finally {
3544 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003546 }
3547
3548 /**
3549 * Returns the CDMA ERI icon index to display
3550 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003551 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003552 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3553 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3554 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003555 }
3556
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003558 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3559 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003561 mApp, subId, callingPackage, callingFeatureId,
3562 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003563 return -1;
3564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565
3566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 final Phone phone = getPhone(subId);
3569 if (phone != null) {
3570 return phone.getCdmaEriIconIndex();
3571 } else {
3572 return -1;
3573 }
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003577 }
3578
3579 /**
3580 * Returns the CDMA ERI icon mode,
3581 * 0 - ON
3582 * 1 - FLASHING
3583 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003584 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003585 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3586 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3587 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003588 }
3589
Sanket Padawe356d7632015-06-22 14:03:32 -07003590 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003591 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3592 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003593 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003594 mApp, subId, callingPackage, callingFeatureId,
3595 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003596 return -1;
3597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598
3599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 final Phone phone = getPhone(subId);
3602 if (phone != null) {
3603 return phone.getCdmaEriIconMode();
3604 } else {
3605 return -1;
3606 }
3607 } finally {
3608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003610 }
3611
3612 /**
3613 * Returns the CDMA ERI text,
3614 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003615 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003616 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3617 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3618 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003619 }
3620
Sanket Padawe356d7632015-06-22 14:03:32 -07003621 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003622 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3623 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003624 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003625 mApp, subId, callingPackage, callingFeatureId,
3626 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003627 return null;
3628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629
3630 final long identity = Binder.clearCallingIdentity();
3631 try {
3632 final Phone phone = getPhone(subId);
3633 if (phone != null) {
3634 return phone.getCdmaEriText();
3635 } else {
3636 return null;
3637 }
3638 } finally {
3639 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003641 }
3642
3643 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003644 * Returns the CDMA MDN.
3645 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003646 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003647 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3649 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650
3651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003654 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655 return phone.getLine1Number();
3656 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003657 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003658 return null;
3659 }
3660 } finally {
3661 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003662 }
3663 }
3664
3665 /**
3666 * Returns the CDMA MIN.
3667 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003668 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003669 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3671 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672
3673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 final Phone phone = getPhone(subId);
3676 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3677 return phone.getCdmaMin();
3678 } else {
3679 return null;
3680 }
3681 } finally {
3682 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003683 }
3684 }
3685
Hall Liud892bec2018-11-30 14:51:45 -08003686 @Override
3687 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3688 INumberVerificationCallback callback, String callingPackage) {
3689 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3690 != PERMISSION_GRANTED) {
3691 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3692 }
3693 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3694
3695 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3696 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003697 throw new SecurityException("Calling package must be configured in the device config: "
3698 + "calling package: " + callingPackage
3699 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003700 }
3701
3702 if (range == null) {
3703 throw new NullPointerException("Range must be non-null");
3704 }
3705
3706 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003707 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003708
3709 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3710 }
3711
Junda Liuca05d5d2014-08-14 22:36:34 -07003712 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003713 * Returns true if CDMA provisioning needs to run.
3714 */
3715 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716 final long identity = Binder.clearCallingIdentity();
3717 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003718 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719 } finally {
3720 Binder.restoreCallingIdentity(identity);
3721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003722 }
3723
3724 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003725 * Sets the voice mail number of a given subId.
3726 */
3727 @Override
3728 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003729 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3730 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003731
3732 final long identity = Binder.clearCallingIdentity();
3733 try {
3734 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3735 new Pair<String, String>(alphaTag, number), new Integer(subId));
3736 return success;
3737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003740 }
3741
Ta-wei Yen87c49842016-05-13 21:19:52 -07003742 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003743 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3744 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003745 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3746 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003747 if (!TextUtils.equals(callingPackage, systemDialer)) {
3748 throw new SecurityException("caller must be system dialer");
3749 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750
3751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3754 if (phoneAccountHandle == null) {
3755 return null;
3756 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003757 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003758 } finally {
3759 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003760 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003761 }
3762
3763 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003764 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3765 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003766 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003768 mApp, subId, callingPackage, callingFeatureId,
3769 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003770 return null;
3771 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003773 final long identity = Binder.clearCallingIdentity();
3774 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003775 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003776 } finally {
3777 Binder.restoreCallingIdentity(identity);
3778 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003779 }
3780
3781 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003782 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3783 VisualVoicemailSmsFilterSettings settings) {
3784 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785
3786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003789 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790 } finally {
3791 Binder.restoreCallingIdentity(identity);
3792 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003793 }
3794
3795 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003796 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3797 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798
3799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003802 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003803 } finally {
3804 Binder.restoreCallingIdentity(identity);
3805 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003806 }
3807
3808 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003809 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3810 String callingPackage, int subId) {
3811 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812
3813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003816 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817 } finally {
3818 Binder.restoreCallingIdentity(identity);
3819 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003820 }
3821
3822 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003823 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003824 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825
3826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003829 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830 } finally {
3831 Binder.restoreCallingIdentity(identity);
3832 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003833 }
3834
3835 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003836 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3837 String callingAttributionTag, int subId, String number, int port, String text,
3838 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003839 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003840 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003841 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003842 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003843 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3844 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003845 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003846
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003847 /**
fionaxu0152e512016-11-14 13:36:14 -08003848 * Sets the voice activation state of a given subId.
3849 */
3850 @Override
3851 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3853 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003854
3855 final long identity = Binder.clearCallingIdentity();
3856 try {
3857 final Phone phone = getPhone(subId);
3858 if (phone != null) {
3859 phone.setVoiceActivationState(activationState);
3860 } else {
3861 loge("setVoiceActivationState fails with invalid subId: " + subId);
3862 }
3863 } finally {
3864 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003865 }
3866 }
3867
3868 /**
3869 * Sets the data activation state of a given subId.
3870 */
3871 @Override
3872 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3874 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003875
3876 final long identity = Binder.clearCallingIdentity();
3877 try {
3878 final Phone phone = getPhone(subId);
3879 if (phone != null) {
3880 phone.setDataActivationState(activationState);
3881 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003882 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003883 }
3884 } finally {
3885 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003886 }
3887 }
3888
3889 /**
3890 * Returns the voice activation state of a given subId.
3891 */
3892 @Override
3893 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895
fionaxu0152e512016-11-14 13:36:14 -08003896 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 if (phone != null) {
3900 return phone.getVoiceActivationState();
3901 } else {
3902 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3903 }
3904 } finally {
3905 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003906 }
3907 }
3908
3909 /**
3910 * Returns the data activation state of a given subId.
3911 */
3912 @Override
3913 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003914 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003915
fionaxu0152e512016-11-14 13:36:14 -08003916 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917 final long identity = Binder.clearCallingIdentity();
3918 try {
3919 if (phone != null) {
3920 return phone.getDataActivationState();
3921 } else {
3922 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3923 }
3924 } finally {
3925 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003926 }
3927 }
3928
3929 /**
Wink Saville36469e72014-06-11 15:17:00 -07003930 * Returns the unread count of voicemails for a subId
3931 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003932 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003933 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3934 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003936 mApp, subId, callingPackage, callingFeatureId,
3937 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003938 return 0;
3939 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 final Phone phone = getPhone(subId);
3943 if (phone != null) {
3944 return phone.getVoiceMessageCount();
3945 } else {
3946 return 0;
3947 }
3948 } finally {
3949 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003951 }
3952
3953 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003954 * returns true, if the device is in a state where both voice and data
3955 * are supported simultaneously. This can change based on location or network condition.
3956 */
3957 @Override
3958 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003959 final long identity = Binder.clearCallingIdentity();
3960 try {
3961 final Phone phone = getPhone(subId);
3962 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3963 } finally {
3964 Binder.restoreCallingIdentity(identity);
3965 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003966 }
3967
3968 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003969 * Send the dialer code if called from the current default dialer or the caller has
3970 * carrier privilege.
3971 * @param inputCode The dialer code to send
3972 */
3973 @Override
3974 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003975 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003976 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003977 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3978 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003979 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003980 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003981 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003983
3984 final long identity = Binder.clearCallingIdentity();
3985 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003986 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987 } finally {
3988 Binder.restoreCallingIdentity(identity);
3989 }
fionaxu235cc5e2017-03-06 22:25:57 -08003990 }
3991
Pengquan Menga1bb6272018-09-06 09:59:22 -07003992 @Override
3993 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003994 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003995 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003996 mApp, subId, "getNetworkSelectionMode");
3997 final long identity = Binder.clearCallingIdentity();
3998 try {
3999 if (!isActiveSubscription(subId)) {
4000 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4001 }
4002 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4003 } finally {
4004 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004005 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004006 }
4007
Brad Ebinger35c841c2018-10-01 10:40:55 -07004008 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004009 public boolean isInEmergencySmsMode() {
4010 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4011 final long identity = Binder.clearCallingIdentity();
4012 try {
4013 for (Phone phone : PhoneFactory.getPhones()) {
4014 if (phone.isInEmergencySmsMode()) {
4015 return true;
4016 }
4017 }
4018 } finally {
4019 Binder.restoreCallingIdentity(identity);
4020 }
4021 return false;
4022 }
4023
shilu366312e2019-12-17 09:28:10 -08004024 /**
4025 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4026 * @param subId The subscription to use to check the configuration.
4027 * @param c The callback that will be used to send the result.
4028 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004029 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004030 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4031 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004032 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004033 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004034
4035 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4036 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4037 "IMS not available on device.");
4038 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 final long token = Binder.clearCallingIdentity();
4040 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004041 int slotId = getSlotIndexOrException(subId);
4042 verifyImsMmTelConfiguredOrThrow(slotId);
4043 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004044 } catch (ImsException e) {
4045 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004046 } finally {
4047 Binder.restoreCallingIdentity(token);
4048 }
4049 }
4050
shilu366312e2019-12-17 09:28:10 -08004051 /**
4052 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4053 * @param subId The subscription to use to check the configuration.
4054 * @param c The callback that will be used to send the result.
4055 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004056 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004057 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004058 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004059 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004060 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4061 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4062 }
Meng Wangafbc5852019-09-19 17:37:13 -07004063 final long token = Binder.clearCallingIdentity();
4064 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004065 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4066 .removeRegistrationCallbackForSubscription(c, subId);
4067 } catch (ImsException e) {
4068 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4069 + "is inactive, ignoring unregister.");
4070 // If the subscription is no longer active, just return, since the callback
4071 // will already have been removed internally.
4072 } finally {
4073 Binder.restoreCallingIdentity(token);
4074 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 }
4076
Brad Ebingera34a6c22019-10-22 17:36:18 -07004077 /**
4078 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4079 */
4080 @Override
4081 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4082 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4083 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4084 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4085 "IMS not available on device.");
4086 }
4087 final long token = Binder.clearCallingIdentity();
4088 try {
4089 Phone phone = getPhone(subId);
4090 if (phone == null) {
4091 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4092 + subId + "'");
4093 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4094 }
4095 phone.getImsRegistrationState(regState -> {
4096 try {
4097 consumer.accept((regState == null)
4098 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4099 } catch (RemoteException e) {
4100 // Ignore if the remote process is no longer available to call back.
4101 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4102 }
4103 });
4104 } finally {
4105 Binder.restoreCallingIdentity(token);
4106 }
4107 }
4108
4109 /**
4110 * Get the transport type for the IMS service registration state.
4111 */
4112 @Override
4113 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004114 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004115 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004116 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4117 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4118 "IMS not available on device.");
4119 }
4120 final long token = Binder.clearCallingIdentity();
4121 try {
4122 Phone phone = getPhone(subId);
4123 if (phone == null) {
4124 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4125 + subId + "'");
4126 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4127 }
4128 phone.getImsRegistrationTech(regTech -> {
4129 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4130 int regTechConverted = (regTech == null)
4131 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4132 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4133 regTechConverted);
4134 try {
4135 consumer.accept(regTechConverted);
4136 } catch (RemoteException e) {
4137 // Ignore if the remote process is no longer available to call back.
4138 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4139 }
4140 });
4141 } finally {
4142 Binder.restoreCallingIdentity(token);
4143 }
4144 }
4145
shilu366312e2019-12-17 09:28:10 -08004146 /**
4147 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4148 * @param subId The subscription to use to check the configuration.
4149 * @param c The callback that will be used to send the result.
4150 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004152 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4153 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004154 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004155 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004156 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4157 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4158 "IMS not available on device.");
4159 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 final long token = Binder.clearCallingIdentity();
4161 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004162 int slotId = getSlotIndexOrException(subId);
4163 verifyImsMmTelConfiguredOrThrow(slotId);
4164 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004165 } catch (ImsException e) {
4166 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004167 } finally {
4168 Binder.restoreCallingIdentity(token);
4169 }
4170 }
4171
shilu366312e2019-12-17 09:28:10 -08004172 /**
4173 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4174 * @param subId The subscription to use to check the configuration.
4175 * @param c The callback that will be used to send the result.
4176 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004178 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004179 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004180 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004181 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4182 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4183 }
Meng Wangafbc5852019-09-19 17:37:13 -07004184
4185 final long token = Binder.clearCallingIdentity();
4186 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004187 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004188 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004189 } catch (ImsException e) {
4190 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4191 + "is inactive, ignoring unregister.");
4192 // If the subscription is no longer active, just return, since the callback
4193 // will already have been removed internally.
4194 } finally {
4195 Binder.restoreCallingIdentity(token);
4196 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 }
4198
4199 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004200 public boolean isCapable(int subId, int capability, int regTech) {
4201 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004202 final long token = Binder.clearCallingIdentity();
4203 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004204 int slotId = getSlotIndexOrException(subId);
4205 verifyImsMmTelConfiguredOrThrow(slotId);
4206 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4207 } catch (com.android.ims.ImsException e) {
4208 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4209 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004210 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004211 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4212 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 } finally {
4214 Binder.restoreCallingIdentity(token);
4215 }
4216 }
4217
4218 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004219 public boolean isAvailable(int subId, int capability, int regTech) {
4220 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 final long token = Binder.clearCallingIdentity();
4222 try {
4223 Phone phone = getPhone(subId);
4224 if (phone == null) return false;
4225 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004226 } catch (com.android.ims.ImsException e) {
4227 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4228 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004229 } finally {
4230 Binder.restoreCallingIdentity(token);
4231 }
4232 }
4233
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004234 /**
4235 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4236 * subscription.
4237 * @param subId The subscription to use to check the configuration.
4238 * @param callback The callback that will be used to send the result.
4239 * @param capability The MmTelFeature capability that will be used to send the result.
4240 * @param transportType The transport type of the MmTelFeature capability.
4241 */
4242 @Override
4243 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4244 int transportType) {
4245 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004246 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4247 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4248 "IMS not available on device.");
4249 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004250 final long token = Binder.clearCallingIdentity();
4251 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004252 int slotId = getSlotIndex(subId);
4253 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4254 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4255 + subId + "'");
4256 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4257 }
4258 verifyImsMmTelConfiguredOrThrow(slotId);
4259 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4260 transportType, aBoolean -> {
4261 try {
4262 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4263 } catch (RemoteException e) {
4264 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4265 + "running. Ignore");
4266 }
4267 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004268 } catch (ImsException e) {
4269 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004270 } finally {
4271 Binder.restoreCallingIdentity(token);
4272 }
4273 }
4274
shilu366312e2019-12-17 09:28:10 -08004275 /**
4276 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4277 * @param subId The subscription to use to check the configuration.
4278 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004279 @Override
4280 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004281 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004282 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004283
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 final long token = Binder.clearCallingIdentity();
4285 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004286 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004287 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004288 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004289 } catch (ImsException e) {
4290 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 } finally {
4292 Binder.restoreCallingIdentity(token);
4293 }
4294 }
4295
4296 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004297 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004299 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004300 final long identity = Binder.clearCallingIdentity();
4301 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004302 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004303 // This setting doesn't require an active ImsService connection, so do not verify. The
4304 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004305 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004306 } catch (ImsException e) {
4307 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004308 } finally {
4309 Binder.restoreCallingIdentity(identity);
4310 }
4311 }
4312
shilu366312e2019-12-17 09:28:10 -08004313 /**
4314 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4315 * @param subId The subscription to use to check the configuration.
4316 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004317 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004318 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004319 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004320 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004321 final long identity = Binder.clearCallingIdentity();
4322 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004323 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004324 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004325 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004326 } catch (ImsException e) {
4327 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 } finally {
4329 Binder.restoreCallingIdentity(identity);
4330 }
4331 }
4332
4333 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004334 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004336 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004337 final long identity = Binder.clearCallingIdentity();
4338 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004339 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004340 // This setting doesn't require an active ImsService connection, so do not verify. The
4341 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004342 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004343 } catch (ImsException e) {
4344 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004345 } finally {
4346 Binder.restoreCallingIdentity(identity);
4347 }
4348 }
4349
shilu366312e2019-12-17 09:28:10 -08004350 /**
4351 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4352 * @param subId The subscription to use to check the configuration.
4353 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 @Override
4355 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004356 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004357 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004358 final long identity = Binder.clearCallingIdentity();
4359 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004360 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004361 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004362 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004363 } catch (ImsException e) {
4364 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 } finally {
4366 Binder.restoreCallingIdentity(identity);
4367 }
4368 }
4369
4370 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004371 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004373 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 final long identity = Binder.clearCallingIdentity();
4375 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004376 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004377 // This setting doesn't require an active ImsService connection, so do not verify. The
4378 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004379 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004380 } catch (ImsException e) {
4381 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
4385 }
4386
shilu366312e2019-12-17 09:28:10 -08004387 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004388 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4389 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4390 * @param subId The subscription to use to check the configuration.
4391 */
4392 @Override
4393 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004394 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004395 mApp, subId, "isCrossSimCallingEnabledByUser");
4396 final long identity = Binder.clearCallingIdentity();
4397 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004398 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004399 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004400 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004401 } catch (ImsException e) {
4402 throw new ServiceSpecificException(e.getCode());
4403 } finally {
4404 Binder.restoreCallingIdentity(identity);
4405 }
4406 }
4407
4408 /**
4409 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4410 * Requires MODIFY_PHONE_STATE permission.
4411 * @param subId The subscription to use to check the configuration.
4412 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4413 * false otherwise
4414 */
4415 @Override
4416 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4418 "setCrossSimCallingEnabled");
4419 final long identity = Binder.clearCallingIdentity();
4420 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004421 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004422 // This setting doesn't require an active ImsService connection, so do not verify. The
4423 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004424 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004425 } catch (ImsException e) {
4426 throw new ServiceSpecificException(e.getCode());
4427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
4430 }
4431
4432 /**
shilu366312e2019-12-17 09:28:10 -08004433 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4434 * @param subId The subscription to use to check the configuration.
4435 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004436 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004437
Brad Ebinger35c841c2018-10-01 10:40:55 -07004438 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004439 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004440 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004441 final long identity = Binder.clearCallingIdentity();
4442 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004443 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004444 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004445 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004446 } catch (ImsException e) {
4447 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
4451 }
4452
4453 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004454 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004456 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004457 final long identity = Binder.clearCallingIdentity();
4458 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004459 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004460 // This setting doesn't require an active ImsService connection, so do not verify. The
4461 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004462 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004463 } catch (ImsException e) {
4464 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004465 } finally {
4466 Binder.restoreCallingIdentity(identity);
4467 }
4468 }
4469
4470 @Override
4471 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4473 "setVoWiFiNonPersistent");
4474 final long identity = Binder.clearCallingIdentity();
4475 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004476 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004477 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004478 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004479 } catch (ImsException e) {
4480 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
4484 }
4485
shilu366312e2019-12-17 09:28:10 -08004486 /**
4487 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4488 * @param subId The subscription to use to check the configuration.
4489 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004490 @Override
4491 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004492 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004493 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004494 final long identity = Binder.clearCallingIdentity();
4495 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004496 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004497 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004498 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004499 } catch (ImsException e) {
4500 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
4504 }
4505
4506 @Override
4507 public void setVoWiFiModeSetting(int subId, int mode) {
4508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4509 "setVoWiFiModeSetting");
4510 final long identity = Binder.clearCallingIdentity();
4511 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004512 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004513 // This setting doesn't require an active ImsService connection, so do not verify. The
4514 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004515 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004516 } catch (ImsException e) {
4517 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
4521 }
4522
4523 @Override
4524 public int getVoWiFiRoamingModeSetting(int subId) {
4525 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4526 final long identity = Binder.clearCallingIdentity();
4527 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004528 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004529 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004530 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004531 } catch (ImsException e) {
4532 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004533 } finally {
4534 Binder.restoreCallingIdentity(identity);
4535 }
4536 }
4537
4538 @Override
4539 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4541 "setVoWiFiRoamingModeSetting");
4542 final long identity = Binder.clearCallingIdentity();
4543 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004544 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004545 // This setting doesn't require an active ImsService connection, so do not verify. The
4546 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004547 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004548 } catch (ImsException e) {
4549 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
4553 }
4554
4555 @Override
4556 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4558 "setRttCapabilityEnabled");
4559 final long identity = Binder.clearCallingIdentity();
4560 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004561 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004562 // This setting doesn't require an active ImsService connection, so do not verify. The
4563 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004564 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004565 } catch (ImsException e) {
4566 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004567 } finally {
4568 Binder.restoreCallingIdentity(identity);
4569 }
4570 }
4571
shilu366312e2019-12-17 09:28:10 -08004572 /**
4573 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4574 * @param subId The subscription to use to check the configuration.
4575 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004576 @Override
4577 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004578 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004579 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004580 final long identity = Binder.clearCallingIdentity();
4581 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004582 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004583 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004584 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004585 } catch (ImsException e) {
4586 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004587 } finally {
4588 Binder.restoreCallingIdentity(identity);
4589 }
4590 }
4591
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004592 @Override
4593 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4594 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004595
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004596 final long identity = Binder.clearCallingIdentity();
4597 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004598 if (!isImsAvailableOnDevice()) {
4599 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4600 "IMS not available on device.");
4601 }
4602 int slotId = getSlotIndexOrException(subId);
4603 verifyImsMmTelConfiguredOrThrow(slotId);
4604 ImsManager.getInstance(mApp, slotId)
4605 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004606 } catch (ImsException e) {
4607 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004608 } finally {
4609 Binder.restoreCallingIdentity(identity);
4610 }
4611 }
4612
4613 @Override
4614 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4615 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004616
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004617 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004618 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4619 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4620 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004621 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004622 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004623 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004624 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004625 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4626 + "is inactive, ignoring unregister.");
4627 // If the subscription is no longer active, just return, since the callback will already
4628 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004629 } finally {
4630 Binder.restoreCallingIdentity(identity);
4631 }
4632 }
4633
joonhunshincffb7fc2021-11-28 07:32:01 +00004634 @Override
4635 public void registerFeatureProvisioningChangedCallback(int subId,
4636 IFeatureProvisioningCallback callback) {
4637 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4638 mApp, subId, "registerFeatureProvisioningChangedCallback");
4639
4640 final long identity = Binder.clearCallingIdentity();
4641 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4642 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4643 }
4644
joonhunshin91bc1952022-04-29 08:47:15 +00004645 try {
4646 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4647 if (controller == null) {
4648 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4649 "Device does not support IMS");
4650 }
4651 controller.addFeatureProvisioningChangedCallback(subId, callback);
4652 } finally {
4653 Binder.restoreCallingIdentity(identity);
4654 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004655 }
4656
4657 @Override
4658 public void unregisterFeatureProvisioningChangedCallback(int subId,
4659 IFeatureProvisioningCallback callback) {
4660 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4661 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4662
4663 final long identity = Binder.clearCallingIdentity();
4664 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4665 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4666 }
4667
joonhunshin91bc1952022-04-29 08:47:15 +00004668 try {
4669 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4670 if (controller == null) {
4671 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4672 return;
4673 }
4674 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4675 } finally {
4676 Binder.restoreCallingIdentity(identity);
4677 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004678 }
allenwtsu99c623b2020-01-03 18:24:23 +08004679
4680 private void checkModifyPhoneStatePermission(int subId, String message) {
4681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4682 message);
4683 }
4684
allenwtsu99c623b2020-01-03 18:24:23 +08004685 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004686 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004687 boolean isProvisioned) {
4688 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4689
4690 final long identity = Binder.clearCallingIdentity();
4691 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004692 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4693 if (controller == null) {
4694 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4695 return;
4696 }
4697 controller.setRcsProvisioningStatusForCapability(
4698 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004699 } finally {
4700 Binder.restoreCallingIdentity(identity);
4701 }
allenwtsu99c623b2020-01-03 18:24:23 +08004702 }
4703
4704
4705 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004706 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4707 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4708 mApp, subId, "getRcsProvisioningStatusForCapability");
4709
allenwtsu99c623b2020-01-03 18:24:23 +08004710 final long identity = Binder.clearCallingIdentity();
4711 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004712 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4713 if (controller == null) {
4714 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4715
4716 // device does not support IMS, this method will return true always.
4717 return true;
4718 }
4719 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004720 } finally {
4721 Binder.restoreCallingIdentity(identity);
4722 }
4723 }
4724
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004725 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004726 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4727 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004728 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004729
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004730 final long identity = Binder.clearCallingIdentity();
4731 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004732 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4733 if (controller == null) {
4734 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4735 return;
4736 }
4737 controller.setImsProvisioningStatusForCapability(
4738 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004739 } finally {
4740 Binder.restoreCallingIdentity(identity);
4741 }
4742 }
4743
4744 @Override
4745 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004746 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4747 mApp, subId, "getProvisioningStatusForCapability");
4748
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004749 final long identity = Binder.clearCallingIdentity();
4750 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004751 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4752 if (controller == null) {
4753 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004754
joonhunshin91bc1952022-04-29 08:47:15 +00004755 // device does not support IMS, this method will return true always.
4756 return true;
4757 }
4758 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004759 } finally {
4760 Binder.restoreCallingIdentity(identity);
4761 }
4762 }
4763
4764 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004765 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4766 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4767 mApp, subId, "isProvisioningRequiredForCapability");
4768
4769 final long identity = Binder.clearCallingIdentity();
4770 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004771 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4772 if (controller == null) {
4773 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4774
4775 // device does not support IMS, this method will return false
4776 return false;
4777 }
4778 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004779 } finally {
4780 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004781 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004782 }
4783
4784 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004785 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4786 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4787 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004788
joonhunshincffb7fc2021-11-28 07:32:01 +00004789 final long identity = Binder.clearCallingIdentity();
4790 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004791 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4792 if (controller == null) {
4793 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4794
4795 // device does not support IMS, this method will return false
4796 return false;
4797 }
4798 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004799 } finally {
4800 Binder.restoreCallingIdentity(identity);
4801 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004802 }
4803
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004804 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004805 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004806 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4807 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4808 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004809 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4810 mApp, subId, "getImsProvisioningInt");
4811
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004812 final long identity = Binder.clearCallingIdentity();
4813 try {
4814 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004815 int slotId = getSlotIndex(subId);
4816 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4817 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4818 + subId + "' for key:" + key);
4819 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4820 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004821
joonhunshin91bc1952022-04-29 08:47:15 +00004822 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4823 if (controller == null) {
4824 loge("getImsProvisioningInt: Device does not support IMS");
4825
4826 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4827 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4828 }
4829 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004830 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4831 return retVal;
4832 }
4833
calvinpanb5a34062021-02-08 19:59:36 +08004834 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004835 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004836 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4837 + subId + "' for key:" + key);
4838 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004839 } finally {
4840 Binder.restoreCallingIdentity(identity);
4841 }
4842 }
4843
4844 @Override
4845 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004846 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4847 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4848 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004849 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4850 mApp, subId, "getImsProvisioningString");
4851
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004852 final long identity = Binder.clearCallingIdentity();
4853 try {
4854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004855 int slotId = getSlotIndex(subId);
4856 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4857 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4858 + subId + "' for key:" + key);
4859 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4860 }
calvinpanb5a34062021-02-08 19:59:36 +08004861 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004862 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004863 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4864 + subId + "' for key:" + key);
4865 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004866 } finally {
4867 Binder.restoreCallingIdentity(identity);
4868 }
4869 }
4870
4871 @Override
4872 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4874 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4875 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4877 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004878
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004879 final long identity = Binder.clearCallingIdentity();
4880 try {
4881 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004882 int slotId = getSlotIndex(subId);
4883 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4884 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4885 + subId + "' for key:" + key);
4886 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4887 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004888
joonhunshin91bc1952022-04-29 08:47:15 +00004889 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4890 if (controller == null) {
4891 loge("setImsProvisioningInt: Device does not support IMS");
4892
4893 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
4894 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4895 }
4896 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00004897 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4898 return retVal;
4899 }
4900
calvinpanb5a34062021-02-08 19:59:36 +08004901 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4902 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004903 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004904 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004905 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004906 } finally {
4907 Binder.restoreCallingIdentity(identity);
4908 }
4909 }
4910
4911 @Override
4912 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004913 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4914 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4915 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4917 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004918 final long identity = Binder.clearCallingIdentity();
4919 try {
4920 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004921 int slotId = getSlotIndex(subId);
4922 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4923 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4924 + subId + "' for key:" + key);
4925 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4926 }
calvinpanb5a34062021-02-08 19:59:36 +08004927 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4928 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004929 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004930 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004931 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
4935 }
4936
Brad Ebinger919631e2021-06-02 17:46:35 -07004937 /**
4938 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4939 * for the given slot ID or no ImsResolver instance has been created.
4940 * @param slotId The slot ID that the IMS service is created for.
4941 * @throws ImsException If there is no ImsService configured for this slot.
4942 */
4943 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4944 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4945 ImsFeature.FEATURE_MMTEL)) {
4946 throw new ImsException("This subscription does not support MMTEL over IMS",
4947 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4948 }
4949 }
4950
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004951 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004952 int slotId = SubscriptionManager.getSlotIndex(subId);
4953 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004954 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4955 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004956 }
4957 return slotId;
4958 }
4959
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004960 private int getSlotIndex(int subId) {
4961 int slotId = SubscriptionManager.getSlotIndex(subId);
4962 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4963 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4964 }
4965 return slotId;
4966 }
4967
Wink Saville36469e72014-06-11 15:17:00 -07004968 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004969 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004970 */
4971 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004972 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4973 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004974 try {
4975 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4976 } catch (SecurityException se) {
4977 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4978 throw new SecurityException("Package " + callingPackage + " does not belong to "
4979 + Binder.getCallingUid());
4980 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004981 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004982 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004983 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004984 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004985 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004986 mApp, subId, callingPackage, callingFeatureId,
4987 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004988 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4989 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 final long identity = Binder.clearCallingIdentity();
4992 try {
4993 final Phone phone = getPhone(subId);
4994 if (phone != null) {
4995 return phone.getServiceState().getDataNetworkType();
4996 } else {
4997 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4998 }
4999 } finally {
5000 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005002 }
5003
5004 /**
5005 * Returns the data network type
5006 */
5007 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005008 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yudf049d72022-12-02 22:48:35 -08005009 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005010 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005011 }
5012
5013 /**
5014 * Returns the data network type for a subId
5015 */
5016 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005017 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5018 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005019 String functionName = "getDataNetworkTypeForSubscriber";
5020 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5021 mApp, functionName)) {
5022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5023 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5024 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5025 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005026 }
5027
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 final long identity = Binder.clearCallingIdentity();
5029 try {
5030 final Phone phone = getPhone(subId);
5031 if (phone != null) {
5032 return phone.getServiceState().getDataNetworkType();
5033 } else {
5034 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5035 }
5036 } finally {
5037 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005038 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005039 }
5040
5041 /**
Wink Saville36469e72014-06-11 15:17:00 -07005042 * Returns the Voice network type for a subId
5043 */
5044 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005045 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5046 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005047 String functionName = "getVoiceNetworkTypeForSubscriber";
5048 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5049 mApp, functionName)) {
5050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5051 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5052 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5053 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005054 }
5055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005056 final long identity = Binder.clearCallingIdentity();
5057 try {
5058 final Phone phone = getPhone(subId);
5059 if (phone != null) {
5060 return phone.getServiceState().getVoiceNetworkType();
5061 } else {
5062 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5063 }
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005067 }
5068
5069 /**
5070 * @return true if a ICC card is present
5071 */
5072 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005073 // FIXME Make changes to pass defaultSimId of type int
Jack Yudf049d72022-12-02 22:48:35 -08005074 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005075 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005076 }
5077
5078 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005079 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005080 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005081 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005082 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083 final long identity = Binder.clearCallingIdentity();
5084 try {
5085 final Phone phone = PhoneFactory.getPhone(slotIndex);
5086 if (phone != null) {
5087 return phone.getIccCard().hasIccCard();
5088 } else {
5089 return false;
5090 }
5091 } finally {
5092 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005094 }
5095
5096 /**
5097 * Return if the current radio is LTE on CDMA. This
5098 * is a tri-state return value as for a period of time
5099 * the mode may be unknown.
5100 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005101 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005102 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005103 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005104 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005105 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005106 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5107 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5108 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005109 }
5110
Sanket Padawe356d7632015-06-22 14:03:32 -07005111 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005112 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5113 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005114 try {
5115 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5116 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005117 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5118 }
5119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005120 final long identity = Binder.clearCallingIdentity();
5121 try {
5122 final Phone phone = getPhone(subId);
5123 if (phone == null) {
5124 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5125 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005126 return TelephonyProperties.lte_on_cdma_device()
5127 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128 }
5129 } finally {
5130 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005131 }
Wink Saville36469e72014-06-11 15:17:00 -07005132 }
5133
Wink Saville36469e72014-06-11 15:17:00 -07005134 /**
5135 * {@hide}
5136 * Returns Default subId, 0 in the case of single standby.
5137 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005138 private int getDefaultSubscription() {
Jack Yudf049d72022-12-02 22:48:35 -08005139 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005140 }
5141
Shishir Agrawala9f32182016-04-12 12:00:16 -07005142 private int getSlotForDefaultSubscription() {
Jack Yudf049d72022-12-02 22:48:35 -08005143 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005144 }
5145
Wink Savilleb564aae2014-10-23 10:18:09 -07005146 private int getPreferredVoiceSubscription() {
Jack Yudf049d72022-12-02 22:48:35 -08005147 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005148 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005149
Pengquan Menge92a50d2018-09-21 15:54:48 -07005150 private boolean isActiveSubscription(int subId) {
Jack Yudf049d72022-12-02 22:48:35 -08005151 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5152 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5153 mApp.getOpPackageName(), mApp.getFeatureId());
5154 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005155 return mSubscriptionController.isActiveSubId(subId);
5156 }
5157
Ihab Awadf2177b72013-11-25 13:33:23 -08005158 /**
5159 * @see android.telephony.TelephonyManager.WifiCallingChoices
5160 */
5161 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 final long identity = Binder.clearCallingIdentity();
5163 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005164 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005165 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5166 getWhenToMakeWifiCallsDefaultPreference());
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
5169 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005170 }
5171
5172 /**
5173 * @see android.telephony.TelephonyManager.WifiCallingChoices
5174 */
5175 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005176 final long identity = Binder.clearCallingIdentity();
5177 try {
5178 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005179 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5181 } finally {
5182 Binder.restoreCallingIdentity(identity);
5183 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005184 }
5185
Sailesh Nepald1e68152013-12-12 19:08:02 -08005186 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005187 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005188 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005189 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005190
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005191 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5192 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5193 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005194 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005195 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5196 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005197 }
5198 return PhoneFactory.getPhone(phoneId);
5199 }
5200
Shishir Agrawal566b7612013-10-28 14:41:00 -07005201 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005202 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005203 @NonNull IccLogicalChannelRequest request) {
5204 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5205 /*message=*/ "iccOpenLogicalChannel");
5206
5207 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5208 // Verify that the callingPackage in the request belongs to the calling UID
5209 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5210
5211 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005212 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005213
Rambo Wanga1782702021-11-10 20:15:19 -08005214 private Phone getPhoneFromValidIccLogicalChannelRequest(
5215 @NonNull IccLogicalChannelRequest request, String message) {
5216 Phone phone;
5217 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5219 mApp, request.subId, message);
5220 phone = getPhoneFromSubId(request.subId);
5221 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5222 enforceModifyPermission();
5223 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5224 } else {
5225 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005226 }
Rambo Wanga1782702021-11-10 20:15:19 -08005227 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005228 }
5229
5230 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005231 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 final long identity = Binder.clearCallingIdentity();
5233 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005234 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005236 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5237 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005238 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5239 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005240 loge("The calling package is not allowed to access ISD-R.");
5241 throw new SecurityException(
5242 "The calling package is not allowed to access ISD-R.");
5243 }
Derek Tan740e1672017-06-27 14:56:27 -07005244 }
Derek Tan740e1672017-06-27 14:56:27 -07005245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005247 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5248 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005249 return response;
5250 } finally {
5251 Binder.restoreCallingIdentity(identity);
5252 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005253 }
5254
5255 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005256 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5257 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5258 /*message=*/"iccCloseLogicalChannel");
5259
5260 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5261
5262 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005263 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005264
Rambo Wanga1782702021-11-10 20:15:19 -08005265 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5266 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005267 // before this feature is enabled, this API should only return false if
5268 // the operation fails instead of throwing runtime exception for
5269 // backward-compatibility.
5270 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5271 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005272 final long identity = Binder.clearCallingIdentity();
5273 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005274 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005275 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 }
Chen Xue9d737e2022-01-01 23:41:31 -08005277 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005278 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005279 Boolean success = false;
5280 if (result instanceof RuntimeException) {
5281 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005282 if (shouldThrowExceptionOnFailure) {
5283 throw (RuntimeException) result;
5284 } else {
5285 return false;
5286 }
Chen Xue9d737e2022-01-01 23:41:31 -08005287 } else if (result instanceof Boolean) {
5288 success = (Boolean) result;
5289 } else {
5290 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5291 }
Rambo Wanga1782702021-11-10 20:15:19 -08005292 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 return success;
5294 } finally {
5295 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005296 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005297 }
5298
5299 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005300 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005301 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5303 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005304 if (DBG) {
5305 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5306 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5307 + p3 + " data=" + data);
5308 }
5309 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5310 command, p1, p2, p3, data);
5311 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005312
Jordan Liu4c733742019-02-28 12:03:40 -08005313 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005314 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5315 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005316 enforceModifyPermission();
5317 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005318 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5319 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5320 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005321 }
5322 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005323 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5324 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005325 }
5326
5327 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5328 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329 final long identity = Binder.clearCallingIdentity();
5330 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005331 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 return "";
5333 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005336 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5337 null /* workSource */);
5338 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340 // Append the returned status code to the end of the response payload.
5341 String s = Integer.toHexString(
5342 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5343 if (response.payload != null) {
5344 s = IccUtils.bytesToHexString(response.payload) + s;
5345 }
5346 return s;
5347 } finally {
5348 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005349 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005350 }
Jake Hambye994d462014-02-03 13:10:13 -08005351
Evan Charltonc66da362014-05-16 14:06:40 -07005352 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005353 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5354 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5356 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005358 if (DBG) {
5359 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5360 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5361 }
5362 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5363 cla, command, p1, p2, p3, data);
5364 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005365
Jordan Liu4c733742019-02-28 12:03:40 -08005366 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005367 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5368 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005369 enforceModifyPermission();
5370 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5371 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005372 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5373 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5374 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005375 }
5376
5377 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005378 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5379 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005380 }
5381
5382 // open APDU basic channel assuming the caller has sufficient permissions
5383 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5384 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005385 final long identity = Binder.clearCallingIdentity();
5386 try {
5387 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5388 && TextUtils.equals(ISDR_AID, data)) {
5389 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005390 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5391 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005392 if (bestComponent == null
5393 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5394 loge("The calling package is not allowed to select ISD-R.");
5395 throw new SecurityException(
5396 "The calling package is not allowed to select ISD-R.");
5397 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005398 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005401 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5402 null /* workSource */);
5403 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005404
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 // Append the returned status code to the end of the response payload.
5406 String s = Integer.toHexString(
5407 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5408 if (response.payload != null) {
5409 s = IccUtils.bytesToHexString(response.payload) + s;
5410 }
5411 return s;
5412 } finally {
5413 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005414 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005415 }
5416
5417 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005418 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005419 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5421 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005423 final long identity = Binder.clearCallingIdentity();
5424 try {
5425 if (DBG) {
5426 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5427 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5428 }
5429
5430 IccIoResult response =
5431 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5432 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5433 subId);
5434
5435 if (DBG) {
5436 log("Exchange SIM_IO [R]" + response);
5437 }
5438
5439 byte[] result = null;
5440 int length = 2;
5441 if (response.payload != null) {
5442 length = 2 + response.payload.length;
5443 result = new byte[length];
5444 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5445 } else {
5446 result = new byte[length];
5447 }
5448
5449 result[length - 1] = (byte) response.sw2;
5450 result[length - 2] = (byte) response.sw1;
5451 return result;
5452 } finally {
5453 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005454 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005455 }
5456
Nathan Haroldb3014052017-01-25 15:57:32 -08005457 /**
5458 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5459 * on a particular subscription
5460 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005461 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5462 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005464 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005465 return null;
5466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005467
5468 final long identity = Binder.clearCallingIdentity();
5469 try {
5470 if (appType != TelephonyManager.APPTYPE_USIM
5471 && appType != TelephonyManager.APPTYPE_SIM) {
5472 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5473 return null;
5474 }
5475 Object response = sendRequest(
5476 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5477 if (response instanceof String[]) {
5478 return (String[]) response;
5479 }
yincheng zhao2737e882019-09-06 17:06:54 -07005480 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005482 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 } finally {
5484 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005485 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005486 }
5487
yincheng zhao2737e882019-09-06 17:06:54 -07005488 /**
5489 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5490 * subscription.
5491 *
5492 * @param subId the id of the subscription.
5493 * @param appType the uicc app type, must be USIM or SIM.
5494 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5495 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005496 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005497 * @return number of fplmns that is successfully written to the SIM.
5498 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005499 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5500 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5502 mApp, subId, "setForbiddenPlmns");
5503
yincheng zhao2737e882019-09-06 17:06:54 -07005504 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5505 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5506 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5507 }
5508 if (fplmns == null) {
5509 throw new IllegalArgumentException("Fplmn List provided is null");
5510 }
5511 for (String fplmn : fplmns) {
5512 if (!CellIdentity.isValidPlmn(fplmn)) {
5513 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5514 }
5515 }
5516 final long identity = Binder.clearCallingIdentity();
5517 try {
5518 Object response = sendRequest(
5519 CMD_SET_FORBIDDEN_PLMNS,
5520 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5521 subId);
5522 return (int) response;
5523 } finally {
5524 Binder.restoreCallingIdentity(identity);
5525 }
5526 }
5527
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005528 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005529 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5531 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533 final long identity = Binder.clearCallingIdentity();
5534 try {
5535 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5536 if (response.payload == null) {
5537 return "";
5538 }
Evan Charltonc66da362014-05-16 14:06:40 -07005539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005540 // Append the returned status code to the end of the response payload.
5541 String s = Integer.toHexString(
5542 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5543 s = IccUtils.bytesToHexString(response.payload) + s;
5544 return s;
5545 } finally {
5546 Binder.restoreCallingIdentity(identity);
5547 }
Evan Charltonc66da362014-05-16 14:06:40 -07005548 }
5549
Jake Hambye994d462014-02-03 13:10:13 -08005550 /**
5551 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5552 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5553 *
5554 * @param itemID the ID of the item to read
5555 * @return the NV item as a String, or null on error.
5556 */
5557 @Override
5558 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005559 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5561 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562
5563 final long identity = Binder.clearCallingIdentity();
5564 try {
5565 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005566 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5568 return value;
5569 } finally {
5570 Binder.restoreCallingIdentity(identity);
5571 }
Jake Hambye994d462014-02-03 13:10:13 -08005572 }
5573
5574 /**
5575 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5576 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5577 *
5578 * @param itemID the ID of the item to read
5579 * @param itemValue the value to write, as a String
5580 * @return true on success; false on any failure
5581 */
5582 @Override
5583 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005584 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5586 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587
5588 final long identity = Binder.clearCallingIdentity();
5589 try {
5590 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5591 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005592 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5594 return success;
5595 } finally {
5596 Binder.restoreCallingIdentity(identity);
5597 }
Jake Hambye994d462014-02-03 13:10:13 -08005598 }
5599
5600 /**
5601 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5602 * Used for device configuration by some CDMA operators.
5603 *
5604 * @param preferredRoamingList byte array containing the new PRL
5605 * @return true on success; false on any failure
5606 */
5607 @Override
5608 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5610 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611
5612 final long identity = Binder.clearCallingIdentity();
5613 try {
5614 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5615 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5616 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5617 return success;
5618 } finally {
5619 Binder.restoreCallingIdentity(identity);
5620 }
Jake Hambye994d462014-02-03 13:10:13 -08005621 }
5622
5623 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005624 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005625 * Used for device configuration by some CDMA operators.
5626 *
chen xu6dac5ab2018-10-26 17:39:23 -07005627 * @param slotIndex - device slot.
5628 *
Jake Hambye994d462014-02-03 13:10:13 -08005629 * @return true on success; false on any failure
5630 */
5631 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005632 public boolean resetModemConfig(int slotIndex) {
5633 Phone phone = PhoneFactory.getPhone(slotIndex);
5634 if (phone != null) {
5635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5636 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637
chen xu6dac5ab2018-10-26 17:39:23 -07005638 final long identity = Binder.clearCallingIdentity();
5639 try {
5640 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5641 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5642 return success;
5643 } finally {
5644 Binder.restoreCallingIdentity(identity);
5645 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646 }
chen xu6dac5ab2018-10-26 17:39:23 -07005647 return false;
5648 }
5649
5650 /**
5651 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5652 *
5653 * @param slotIndex - device slot.
5654 *
5655 * @return true on success; false on any failure
5656 */
5657 @Override
5658 public boolean rebootModem(int slotIndex) {
5659 Phone phone = PhoneFactory.getPhone(slotIndex);
5660 if (phone != null) {
5661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5662 mApp, phone.getSubId(), "rebootModem");
5663
5664 final long identity = Binder.clearCallingIdentity();
5665 try {
5666 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5667 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5668 return success;
5669 } finally {
5670 Binder.restoreCallingIdentity(identity);
5671 }
5672 }
5673 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005674 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005675
Brad Ebinger51f743a2017-01-23 13:50:20 -08005676 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005677 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5678 * {@link #disableIms(int)}.
5679 * @param slotIndex device slot.
5680 */
5681 public void resetIms(int slotIndex) {
5682 enforceModifyPermission();
5683
5684 final long identity = Binder.clearCallingIdentity();
5685 try {
5686 if (mImsResolver == null) {
5687 // may happen if the does not support IMS.
5688 return;
5689 }
5690 mImsResolver.disableIms(slotIndex);
5691 mImsResolver.enableIms(slotIndex);
5692 } finally {
5693 Binder.restoreCallingIdentity(identity);
5694 }
5695 }
5696
5697 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005698 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5699 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005700 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005701 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005702 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703
5704 final long identity = Binder.clearCallingIdentity();
5705 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005706 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005707 // may happen if the device does not support IMS.
5708 return;
5709 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005710 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711 } finally {
5712 Binder.restoreCallingIdentity(identity);
5713 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005714 }
5715
5716 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005717 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5718 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005719 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005720 public void disableIms(int slotId) {
5721 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722
5723 final long identity = Binder.clearCallingIdentity();
5724 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005725 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005726 // may happen if the device does not support IMS.
5727 return;
5728 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005729 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 } finally {
5731 Binder.restoreCallingIdentity(identity);
5732 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005733 }
5734
5735 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005736 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5737 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005738 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005739 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005740 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005741 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742
5743 final long identity = Binder.clearCallingIdentity();
5744 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005745 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005746 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5747 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005748 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005749 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750 } finally {
5751 Binder.restoreCallingIdentity(identity);
5752 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005753 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005754 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005755 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5756 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005757 @Override
5758 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005759 enforceModifyPermission();
5760
5761 final long identity = Binder.clearCallingIdentity();
5762 try {
5763 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005764 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005765 } finally {
5766 Binder.restoreCallingIdentity(identity);
5767 }
5768 }
5769
5770 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005771 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005772 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005773 */
5774 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5775 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776
5777 final long identity = Binder.clearCallingIdentity();
5778 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005779 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005780 // may happen if the device does not support IMS.
5781 return null;
5782 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005783 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005784 } finally {
5785 Binder.restoreCallingIdentity(identity);
5786 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005787 }
5788
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005789 /**
5790 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005791 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005792 */
5793 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5794 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795
5796 final long identity = Binder.clearCallingIdentity();
5797 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005798 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005799 // may happen if the device does not support IMS.
5800 return null;
5801 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005802 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803 } finally {
5804 Binder.restoreCallingIdentity(identity);
5805 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005806 }
5807
Brad Ebinger884c07b2018-02-15 16:17:40 -08005808 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005809 * Sets the ImsService Package Name that Telephony will bind to.
5810 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005811 * @param slotIndex the slot ID that the ImsService should bind for.
5812 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005813 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005814 * @param featureTypes An integer array of feature types associated with a packageName.
5815 * @param packageName The name of the package that the current configuration will be replaced
5816 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005817 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005818 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005819 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5820 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005821 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yude40a3f2022-11-19 22:29:12 -08005823 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 final long identity = Binder.clearCallingIdentity();
5826 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005827 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005828 // may happen if the device does not support IMS.
5829 return false;
5830 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005831 Map<Integer, String> featureConfig = new HashMap<>();
5832 for (int featureType : featureTypes) {
5833 featureConfig.put(featureType, packageName);
5834 }
5835 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5836 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005837 } finally {
5838 Binder.restoreCallingIdentity(identity);
5839 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005840 }
5841
5842 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005843 * Clears any carrier ImsService overrides for the slot index specified that were previously
5844 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5845 *
5846 * This should only be used for testing.
5847 *
5848 * @param slotIndex the slot ID that the ImsService should bind for.
5849 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5850 */
5851 @Override
5852 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08005853 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5854 "clearCarrierImsServiceOverride");
5855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yude40a3f2022-11-19 22:29:12 -08005856 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08005857
5858 final long identity = Binder.clearCallingIdentity();
5859 try {
5860 if (mImsResolver == null) {
5861 // may happen if the device does not support IMS.
5862 return false;
5863 }
5864 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5865 } finally {
5866 Binder.restoreCallingIdentity(identity);
5867 }
5868 }
5869
5870 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005871 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005872 *
5873 * @param slotId The slot that the ImsService is associated with.
5874 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5875 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005876 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005877 * @return the package name of the ImsService configuration.
5878 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005879 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5880 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005881 TelephonyPermissions
Jack Yude40a3f2022-11-19 22:29:12 -08005882 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
5883 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005884
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005885 final long identity = Binder.clearCallingIdentity();
5886 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005887 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005888 // may happen if the device does not support IMS.
5889 return "";
5890 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005891 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005892 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5893 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 } finally {
5895 Binder.restoreCallingIdentity(identity);
5896 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005897 }
5898
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005899 /**
5900 * Get the MmTelFeature state associated with the requested subscription id.
5901 * @param subId The subscription that the MmTelFeature is associated with.
5902 * @param callback A callback with an integer containing the
5903 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5904 */
5905 @Override
5906 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5907 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005908 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5909 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5910 "IMS not available on device.");
5911 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005912 final long token = Binder.clearCallingIdentity();
5913 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005914 int slotId = getSlotIndex(subId);
5915 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5916 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5917 + subId + "'");
5918 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5919 }
5920 verifyImsMmTelConfiguredOrThrow(slotId);
5921 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5922 try {
5923 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5924 } catch (RemoteException e) {
5925 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5926 + "Ignore");
5927 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005928 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005929 } catch (ImsException e) {
5930 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005931 } finally {
5932 Binder.restoreCallingIdentity(token);
5933 }
5934 }
5935
Daniel Brightbb5840b2021-01-12 15:48:18 -08005936 /**
5937 * Sets the ims registration state on all valid {@link Phone}s.
5938 */
5939 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005940 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941
5942 final long identity = Binder.clearCallingIdentity();
5943 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005944 // NOTE: Before S, this method only set the default phone.
5945 for (final Phone phone : PhoneFactory.getPhones()) {
5946 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5947 phone.setImsRegistrationState(registered);
5948 }
5949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950 } finally {
5951 Binder.restoreCallingIdentity(identity);
5952 }
Wink Saville36469e72014-06-11 15:17:00 -07005953 }
5954
5955 /**
Stuart Scott54788802015-03-30 13:18:01 -07005956 * Set the network selection mode to automatic.
5957 *
5958 */
5959 @Override
5960 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5962 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963
5964 final long identity = Binder.clearCallingIdentity();
5965 try {
shilufc958392020-01-20 11:36:01 -08005966 if (!isActiveSubscription(subId)) {
5967 return;
5968 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005970 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5971 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972 } finally {
5973 Binder.restoreCallingIdentity(identity);
5974 }
Stuart Scott54788802015-03-30 13:18:01 -07005975 }
5976
Jack Yud10cdd42020-09-28 20:28:01 -07005977 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005978 * Ask the radio to connect to the input network and change selection mode to manual.
5979 *
5980 * @param subId the id of the subscription.
5981 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5982 * the operator to attach to.
5983 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5984 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5985 * normal network selection next time.
5986 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005987 */
5988 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005989 public boolean setNetworkSelectionModeManual(
5990 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5992 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005993
Jack Yudf049d72022-12-02 22:48:35 -08005994 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07005995 if (!isActiveSubscription(subId)) {
5996 return false;
5997 }
5998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006000 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006002 if (DBG) {
6003 log("setNetworkSelectionModeManual: subId: " + subId
6004 + " operator: " + operatorInfo);
6005 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6007 } finally {
6008 Binder.restoreCallingIdentity(identity);
6009 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006010 }
shilu84f6e8b2019-12-19 13:58:01 -08006011 /**
6012 * Get the manual network selection
6013 *
6014 * @param subId the id of the subscription.
6015 *
6016 * @return the previously saved user selected PLMN
6017 */
6018 @Override
6019 public String getManualNetworkSelectionPlmn(int subId) {
6020 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006021 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006022 mApp, subId, "getManualNetworkSelectionPlmn");
6023
6024 final long identity = Binder.clearCallingIdentity();
6025 try {
6026 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006027 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006028 }
6029
6030 final Phone phone = getPhone(subId);
6031 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006032 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006033 }
6034 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6035 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6036 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6037 } finally {
6038 Binder.restoreCallingIdentity(identity);
6039 }
6040 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006041
6042 /**
6043 * Scans for available networks.
6044 */
6045 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006046 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6047 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6049 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006050 LocationAccessPolicy.LocationPermissionResult locationResult =
6051 LocationAccessPolicy.checkLocationPermission(mApp,
6052 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6053 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006054 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006055 .setCallingPid(Binder.getCallingPid())
6056 .setCallingUid(Binder.getCallingUid())
6057 .setMethod("getCellNetworkScanResults")
6058 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006059 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6060 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006061 .build());
6062 switch (locationResult) {
6063 case DENIED_HARD:
6064 throw new SecurityException("Not allowed to access scan results -- location");
6065 case DENIED_SOFT:
6066 return null;
6067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068
Pengquan Menga1bb6272018-09-06 09:59:22 -07006069 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 try {
6071 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006072 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006074 } finally {
6075 Binder.restoreCallingIdentity(identity);
6076 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006077 }
6078
6079 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006080 * Get the call forwarding info, given the call forwarding reason.
6081 */
6082 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006083 public void getCallForwarding(int subId, int callForwardingReason,
6084 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006085 enforceReadPrivilegedPermission("getCallForwarding");
6086 long identity = Binder.clearCallingIdentity();
6087 try {
6088 if (DBG) {
6089 log("getCallForwarding: subId " + subId
6090 + " callForwardingReason" + callForwardingReason);
6091 }
Hall Liu27d24262020-09-18 19:04:59 -07006092
6093 Phone phone = getPhone(subId);
6094 if (phone == null) {
6095 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006096 callback.onError(
6097 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006098 } catch (RemoteException e) {
6099 // ignore
6100 }
6101 return;
6102 }
6103
6104 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6105 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6106 @Override
6107 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6108 try {
6109 callback.onCallForwardingInfoAvailable(info);
6110 } catch (RemoteException e) {
6111 // ignore
6112 }
6113 }
6114
6115 @Override
6116 public void onError(int error) {
6117 try {
6118 callback.onError(error);
6119 } catch (RemoteException e) {
6120 // ignore
6121 }
6122 }
6123 });
6124 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006125 } finally {
6126 Binder.restoreCallingIdentity(identity);
6127 }
6128 }
6129
6130 /**
6131 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6132 * reason, the number to forward, and the timeout before the forwarding is attempted.
6133 */
6134 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006135 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6136 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006137 enforceModifyPermission();
6138 long identity = Binder.clearCallingIdentity();
6139 try {
6140 if (DBG) {
6141 log("setCallForwarding: subId " + subId
6142 + " callForwardingInfo" + callForwardingInfo);
6143 }
Hall Liu27d24262020-09-18 19:04:59 -07006144
6145 Phone phone = getPhone(subId);
6146 if (phone == null) {
6147 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006148 callback.accept(
6149 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006150 } catch (RemoteException e) {
6151 // ignore
6152 }
6153 return;
6154 }
6155
6156 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6157 FunctionalUtils.ignoreRemoteException(callback::accept));
6158
6159 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006160 } finally {
6161 Binder.restoreCallingIdentity(identity);
6162 }
6163 }
6164
6165 /**
Hall Liu27d24262020-09-18 19:04:59 -07006166 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006167 */
6168 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006169 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006170 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006171 long identity = Binder.clearCallingIdentity();
6172 try {
Hall Liu27d24262020-09-18 19:04:59 -07006173 Phone phone = getPhone(subId);
6174 if (phone == null) {
6175 try {
6176 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6177 } catch (RemoteException e) {
6178 // ignore
6179 }
6180 return;
6181 }
SongFerngWang0e767992021-03-31 22:08:45 +08006182 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6183 PersistableBundle c = configManager.getConfigForSubId(subId);
6184 boolean requireUssd = c.getBoolean(
6185 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006186
Shuo Qian4a594052020-01-23 11:59:30 -08006187 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006188 if (requireUssd) {
6189 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6190 getSubscriptionCarrierId(subId));
6191 String newUssdCommand = "";
6192 try {
6193 newUssdCommand = carrierXmlParser.getFeature(
6194 CarrierXmlParser.FEATURE_CALL_WAITING)
6195 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6196 } catch (NullPointerException e) {
6197 loge("Failed to generate USSD number" + e);
6198 }
6199 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6200 mMainThreadHandler, callback, carrierXmlParser,
6201 CarrierXmlParser.SsEntry.SSAction.QUERY);
6202 final String ussdCommand = newUssdCommand;
6203 Executors.newSingleThreadExecutor().execute(() -> {
6204 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6205 });
6206 } else {
6207 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6208 callback::accept);
6209 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6210 }
Shuo Qian4a594052020-01-23 11:59:30 -08006211 } finally {
6212 Binder.restoreCallingIdentity(identity);
6213 }
6214 }
6215
6216 /**
Hall Liu27d24262020-09-18 19:04:59 -07006217 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006218 */
6219 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006220 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006221 enforceModifyPermission();
6222 long identity = Binder.clearCallingIdentity();
6223 try {
Hall Liu27d24262020-09-18 19:04:59 -07006224 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6225
6226 Phone phone = getPhone(subId);
6227 if (phone == null) {
6228 try {
6229 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6230 } catch (RemoteException e) {
6231 // ignore
6232 }
6233 return;
6234 }
6235
SongFerngWang0e767992021-03-31 22:08:45 +08006236 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6237 PersistableBundle c = configManager.getConfigForSubId(subId);
6238 boolean requireUssd = c.getBoolean(
6239 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006240
SongFerngWang0e767992021-03-31 22:08:45 +08006241 if (DBG) log("getCallWaitingStatus: subId " + subId);
6242 if (requireUssd) {
6243 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6244 getSubscriptionCarrierId(subId));
6245 CarrierXmlParser.SsEntry.SSAction ssAction =
6246 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6247 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6248 String newUssdCommand = "";
6249 try {
6250 newUssdCommand = carrierXmlParser.getFeature(
6251 CarrierXmlParser.FEATURE_CALL_WAITING)
6252 .makeCommand(ssAction, null);
6253 } catch (NullPointerException e) {
6254 loge("Failed to generate USSD number" + e);
6255 }
6256 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6257 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6258 final String ussdCommand = newUssdCommand;
6259 Executors.newSingleThreadExecutor().execute(() -> {
6260 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6261 });
6262 } else {
6263 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6264 FunctionalUtils.ignoreRemoteException(callback::accept));
6265
6266 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6267 }
Shuo Qian4a594052020-01-23 11:59:30 -08006268 } finally {
6269 Binder.restoreCallingIdentity(identity);
6270 }
6271 }
6272
6273 /**
yinxub1bed742017-04-17 11:45:04 -07006274 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006275 *
yinxub1bed742017-04-17 11:45:04 -07006276 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006277 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6278 * location related information which will be sent if the caller already possess
6279 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006280 * @param request contains the radio access networks with bands/channels to scan
6281 * @param messenger callback messenger for scan results or errors
6282 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006283 * @return the id of the requested scan which can be used to stop the scan.
6284 */
6285 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006286 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6287 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006288 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6290 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006291 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006292 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6293 if (!renounceFineLocationAccess) {
6294 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6295 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6296 .setCallingPackage(callingPackage)
6297 .setCallingFeatureId(callingFeatureId)
6298 .setCallingPid(Binder.getCallingPid())
6299 .setCallingUid(Binder.getCallingUid())
6300 .setMethod("requestNetworkScan")
6301 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6302 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6303 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6304 .build());
6305 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006306 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006307 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6308 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006309 if (e != null) {
6310 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6311 throw e;
6312 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006313 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006314 return TelephonyScanManager.INVALID_SCAN_ID;
6315 }
6316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317 }
Hall Liu912dfd32019-04-25 14:02:26 -07006318 int callingUid = Binder.getCallingUid();
6319 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006320 final long identity = Binder.clearCallingIdentity();
6321 try {
6322 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006323 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006324 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006325 } finally {
6326 Binder.restoreCallingIdentity(identity);
6327 }
yinxu504e1392017-04-12 16:03:22 -07006328 }
6329
Hall Liub2ac8ef2019-02-28 15:56:23 -08006330 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006331 NetworkScanRequest request, int subId, String callingPackage) {
6332 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006333 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6334 boolean hasNetworkScanPermission =
6335 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6336 == PERMISSION_GRANTED;
6337
6338 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6339 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6340 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006341 }
6342
6343 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6344 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006345 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6346 return new SecurityException("Specific channels must not be"
6347 + " scanned without location access.");
6348 }
6349 }
6350 }
6351
Hall Liub2ac8ef2019-02-28 15:56:23 -08006352 return null;
6353 }
6354
yinxu504e1392017-04-12 16:03:22 -07006355 /**
6356 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006357 *
6358 * @param subId id of the subscription
6359 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006360 */
6361 @Override
6362 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6364 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365
Hall Liu912dfd32019-04-25 14:02:26 -07006366 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367 final long identity = Binder.clearCallingIdentity();
6368 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006369 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006370 } finally {
6371 Binder.restoreCallingIdentity(identity);
6372 }
yinxu504e1392017-04-12 16:03:22 -07006373 }
6374
6375 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006376 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006377 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006378 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006379 */
6380 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006381 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006382 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006383 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006384 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385
6386 final long identity = Binder.clearCallingIdentity();
6387 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006388 if (DBG) log("getAllowedNetworkTypesBitmask");
6389 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6390 int networkTypesBitmask = (result != null ? result[0] : -1);
6391 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6392 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006393 } finally {
6394 Binder.restoreCallingIdentity(identity);
6395 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006396 }
6397
6398 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006399 * Get the allowed network types for certain reason.
6400 *
6401 * @param subId the id of the subscription.
6402 * @param reason the reason the allowed network type change is taking place
6403 * @return the allowed network types.
6404 */
6405 @Override
6406 public long getAllowedNetworkTypesForReason(int subId,
6407 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006408 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006409 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006410 final long identity = Binder.clearCallingIdentity();
6411 try {
6412 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6413 } finally {
6414 Binder.restoreCallingIdentity(identity);
6415 }
6416 }
6417
6418 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006419 * Enable/Disable E-UTRA-NR Dual Connectivity
6420 * @param subId subscription id of the sim card
6421 * @param nrDualConnectivityState expected NR dual connectivity state
6422 * This can be passed following states
6423 * <ol>
6424 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6425 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6426 * <li>Disable NR dual connectivity and force secondary cell to be released
6427 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6428 * </ol>
6429 * @return operation result.
6430 */
6431 @Override
6432 public int setNrDualConnectivityState(int subId,
6433 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6435 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006436 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006437 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6438 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6439 }
6440
Sooraj Sasindran37444802020-08-11 10:40:43 -07006441 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6442 final long identity = Binder.clearCallingIdentity();
6443 try {
6444 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6445 nrDualConnectivityState, subId,
6446 workSource);
6447 if (DBG) log("enableNRDualConnectivity result: " + result);
6448 return result;
6449 } finally {
6450 Binder.restoreCallingIdentity(identity);
6451 }
6452 }
6453
6454 /**
6455 * Is E-UTRA-NR Dual Connectivity enabled
6456 * @return true if dual connectivity is enabled else false
6457 */
6458 @Override
6459 public boolean isNrDualConnectivityEnabled(int subId) {
6460 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006461 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006462 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006463 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006464 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6465 return false;
6466 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006467 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6468 final long identity = Binder.clearCallingIdentity();
6469 try {
6470 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6471 null, subId, workSource);
6472 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6473 return isEnabled;
6474 } finally {
6475 Binder.restoreCallingIdentity(identity);
6476 }
6477 }
6478
6479 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006480 * Set the allowed network types of the device and
6481 * provide the reason triggering the allowed network change.
6482 *
6483 * @param subId the id of the subscription.
6484 * @param reason the reason the allowed network type change is taking place
6485 * @param allowedNetworkTypes the allowed network types.
6486 * @return true on success; false on any failure.
6487 */
6488 @Override
6489 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006490 @TelephonyManager.AllowedNetworkTypesReason int reason,
6491 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6493 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006494 // If the caller only has carrier privileges, then they should not be able to override
6495 // any network types which were set for security reasons.
6496 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6497 != PERMISSION_GRANTED
6498 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6499 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6500 throw new SecurityException(
6501 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6502 + " reason "
6503 + reason);
6504 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006505 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006506 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6507 return false;
6508 }
6509 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6510 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006511 return false;
6512 }
6513
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006514 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6515 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6516
6517
6518 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6519 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6520 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006521 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006522
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006523 final long identity = Binder.clearCallingIdentity();
6524 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006525 Boolean success = (Boolean) sendRequest(
6526 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6527 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6528
6529 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6530 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006531 } finally {
6532 Binder.restoreCallingIdentity(identity);
6533 }
6534 }
6535
6536 /**
Miaoa84611c2019-03-15 09:21:10 +08006537 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006538 *
Miaoa84611c2019-03-15 09:21:10 +08006539 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006540 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006541 * @hide
6542 */
6543 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006544 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006545 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006546 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006547 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006548 try {
Miaoa84611c2019-03-15 09:21:10 +08006549 if (phone != null) {
6550 return phone.hasMatchedTetherApnSetting();
6551 } else {
6552 return false;
6553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554 } finally {
6555 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006556 }
Junda Liu475951f2014-11-07 16:45:03 -08006557 }
6558
6559 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006560 * Get the user enabled state of Mobile Data.
6561 *
6562 * TODO: remove and use isUserDataEnabled.
6563 * This can't be removed now because some vendor codes
6564 * calls through ITelephony directly while they should
6565 * use TelephonyManager.
6566 *
6567 * @return true on enabled
6568 */
6569 @Override
6570 public boolean getDataEnabled(int subId) {
6571 return isUserDataEnabled(subId);
6572 }
6573
6574 /**
6575 * Get whether mobile data is enabled per user setting.
6576 *
6577 * There are other factors deciding whether mobile data is actually enabled, but they are
6578 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006579 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006580 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6581 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006582 *
6583 * @return {@code true} if data is enabled else {@code false}
6584 */
6585 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006586 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006587 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006588 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006589 try {
6590 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6591 functionName);
6592 } catch (Exception e) {
6593 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6594 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006595 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006597 mApp, subId, functionName);
6598
Robert Greenwalt646120a2014-05-23 11:54:03 -07006599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006600
6601 final long identity = Binder.clearCallingIdentity();
6602 try {
Jack Yudf049d72022-12-02 22:48:35 -08006603 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6605 Phone phone = PhoneFactory.getPhone(phoneId);
6606 if (phone != null) {
6607 boolean retVal = phone.isUserDataEnabled();
6608 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6609 return retVal;
6610 } else {
6611 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6612 return false;
6613 }
6614 } finally {
6615 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006616 }
6617 }
6618
6619 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006620 * Checks if the device is capable of mobile data by considering whether whether the
6621 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6622 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006623 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006624 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006625 */
6626 @Override
6627 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006628 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006629 try {
6630 try {
6631 mApp.enforceCallingOrSelfPermission(
6632 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006633 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006634 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006635 try {
6636 mApp.enforceCallingOrSelfPermission(
6637 android.Manifest.permission.READ_PHONE_STATE,
6638 functionName);
6639 } catch (Exception e2) {
6640 mApp.enforceCallingOrSelfPermission(
6641 permission.READ_BASIC_PHONE_STATE, functionName);
6642 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006643 }
6644 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006645 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006646 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006647
6648 final long identity = Binder.clearCallingIdentity();
6649 try {
Jack Yudf049d72022-12-02 22:48:35 -08006650 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006651 Phone phone = PhoneFactory.getPhone(phoneId);
6652 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006653 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006654 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006655 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656 return retVal;
6657 } else {
6658 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6659 return false;
6660 }
6661 } finally {
6662 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006663 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006664 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006665
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006666 /**
6667 * Check if data is enabled for a specific reason
6668 * @param subId Subscription index
6669 * @param reason the reason the data enable change is taking place
6670 * @return {@code true} if the overall data is enabled; {@code false} if not.
6671 */
6672 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006673 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006674 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006675 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006676 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006677 try {
6678 mApp.enforceCallingOrSelfPermission(
6679 android.Manifest.permission.ACCESS_NETWORK_STATE,
6680 functionName);
6681 } catch (Exception e) {
6682 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6683 functionName);
6684 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006685 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006686 try {
6687 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006688 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006689 } catch (Exception e2) {
6690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006691 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006692 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006693 }
6694
6695
6696 final long identity = Binder.clearCallingIdentity();
6697 try {
Jack Yudf049d72022-12-02 22:48:35 -08006698 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006699 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006700 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006701 + " reason=" + reason);
6702 }
6703 Phone phone = PhoneFactory.getPhone(phoneId);
6704 if (phone != null) {
6705 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006706 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006707 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006708 return retVal;
6709 } else {
6710 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006711 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006712 + subId + " retVal=false");
6713 }
6714 return false;
6715 }
6716 } finally {
6717 Binder.restoreCallingIdentity(identity);
6718 }
6719 }
6720
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006721 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006722 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006723 // No permission needed; this only lets the caller inspect their own status.
6724 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006725 }
Junda Liu29340342014-07-10 15:23:27 -07006726
6727 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006728 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006729 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006730 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6731 }
6732
6733 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6734 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006735 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006736 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006737 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6738 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006739 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6740 if (cpt == null) {
6741 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006742 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6743 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006744 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006745 }
6746
6747 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006748 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006749 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006750 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006751 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006752 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006753 Phone phone = getPhone(subId);
6754 if (phone == null) {
6755 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6756 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6757 }
6758 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6759 if (cpt == null) {
6760 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006761 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6762 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006763 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006764 }
6765
6766 @Override
6767 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006768 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006769 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6770 }
6771
6772 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006773 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006774 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006775 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006776 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006777 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6778 Phone phone = PhoneFactory.getPhone(phoneId);
6779 if (phone == null) {
6780 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006781 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006782 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6783 if (cpt == null) {
6784 continue;
6785 }
6786 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006787 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6788 break;
6789 }
6790 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006791 return result;
Junda Liu29340342014-07-10 15:23:27 -07006792 }
Derek Tan89e89d42014-07-08 17:00:10 -07006793
6794 @Override
Junda Liue64de782015-04-16 17:19:16 -07006795 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006796 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006797 Phone phone = PhoneFactory.getPhone(phoneId);
6798 if (phone == null) {
6799 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006800 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006801 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6802 if (cpt == null) {
6803 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006804 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006805 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006806 }
6807
Amith Yamasani6e118872016-02-19 12:53:51 -08006808 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006809 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006810 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006811 Phone phone = PhoneFactory.getPhone(phoneId);
6812 if (phone == null) {
6813 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006814 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006815 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6816 if (cpt == null) {
6817 return Collections.emptyList();
6818 }
6819 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006820 }
6821
chen xuf7e9fe82019-05-09 19:31:02 -07006822 @Override
6823 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006824 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006825 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006826 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006827 try {
6828 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6829 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6830 }
6831 } finally {
6832 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006833 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006834 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006835 }
6836
Rambo Wang6812ffb2022-03-15 16:54:17 -07006837 @Override
6838 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6839 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6840
6841 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6842 if (phone == null) {
6843 return null;
6844 }
6845 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6846 if (cpt == null) {
6847 return null;
6848 }
6849 return cpt.getCarrierServicePackageName();
6850 }
6851
Wink Savilleb564aae2014-10-23 10:18:09 -07006852 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006853 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006854 UiccPort port = phone == null ? null : phone.getUiccPort();
6855 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006856 return null;
6857 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006858 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006859 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006860 return null;
6861 }
6862 return iccId;
6863 }
6864
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006865 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006866 public void setCallComposerStatus(int subId, int status) {
6867 enforceModifyPermission();
6868
6869 final long identity = Binder.clearCallingIdentity();
6870 try {
6871 Phone phone = getPhone(subId);
6872 if (phone != null) {
6873 Phone defaultPhone = phone.getImsPhone();
6874 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6875 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6876 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006877 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6878 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006879 }
6880 }
Shuo Qian284ae752020-12-22 19:10:14 -08006881 } catch (ImsException e) {
6882 throw new ServiceSpecificException(e.getCode());
6883 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006884 Binder.restoreCallingIdentity(identity);
6885 }
6886 }
6887
6888 @Override
6889 public int getCallComposerStatus(int subId) {
6890 enforceReadPrivilegedPermission("getCallComposerStatus");
6891
6892 final long identity = Binder.clearCallingIdentity();
6893 try {
6894 Phone phone = getPhone(subId);
6895 if (phone != null) {
6896 Phone defaultPhone = phone.getImsPhone();
6897 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6898 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6899 return imsPhone.getCallComposerStatus();
6900 }
6901 }
6902 } finally {
6903 Binder.restoreCallingIdentity(identity);
6904 }
6905 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6906 }
6907
6908 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006909 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6910 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006911 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006912 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006914 final long identity = Binder.clearCallingIdentity();
6915 try {
6916 final String iccId = getIccId(subId);
6917 final Phone phone = getPhone(subId);
6918 if (phone == null) {
6919 return false;
6920 }
6921 final String subscriberId = phone.getSubscriberId();
6922
6923 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006924 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006925 + subscriberId + " to " + number);
6926 }
6927
6928 if (TextUtils.isEmpty(iccId)) {
6929 return false;
6930 }
6931
6932 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6933
6934 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6935 if (alphaTag == null) {
6936 editor.remove(alphaTagPrefKey);
6937 } else {
6938 editor.putString(alphaTagPrefKey, alphaTag);
6939 }
6940
6941 // Record both the line number and IMSI for this ICCID, since we need to
6942 // track all merged IMSIs based on line number
6943 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6944 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6945 if (number == null) {
6946 editor.remove(numberPrefKey);
6947 editor.remove(subscriberPrefKey);
6948 } else {
6949 editor.putString(numberPrefKey, number);
6950 editor.putString(subscriberPrefKey, subscriberId);
6951 }
6952
6953 editor.commit();
6954 return true;
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006957 }
Derek Tan7226c842014-07-02 17:42:23 -07006958 }
6959
6960 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006961 public String getLine1NumberForDisplay(int subId, String callingPackage,
6962 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006963 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006965 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006966 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006967 return null;
6968 }
Derek Tan97ebb422014-09-05 16:55:38 -07006969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006970 final long identity = Binder.clearCallingIdentity();
6971 try {
6972 String iccId = getIccId(subId);
6973 if (iccId != null) {
6974 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6975 if (DBG_MERGE) {
6976 log("getLine1NumberForDisplay returning "
6977 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6978 }
6979 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006981 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6982 return null;
6983 } finally {
6984 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006985 }
Derek Tan7226c842014-07-02 17:42:23 -07006986 }
6987
6988 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006989 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6990 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006992 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006993 return null;
6994 }
Derek Tan97ebb422014-09-05 16:55:38 -07006995
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996 final long identity = Binder.clearCallingIdentity();
6997 try {
6998 String iccId = getIccId(subId);
6999 if (iccId != null) {
7000 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7001 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7002 }
7003 return null;
7004 } finally {
7005 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007006 }
Derek Tan7226c842014-07-02 17:42:23 -07007007 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007008
7009 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007010 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7011 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007012 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7013 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007015 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007016 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007017 return null;
7018 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007019
Jordan Liub49b04b2019-05-06 14:45:15 -07007020 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7021 // the process, where TelephonyManager was instantiated.
7022 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007023 final long identity = Binder.clearCallingIdentity();
7024 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007025 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007026 final TelephonyManager tele = TelephonyManager.from(context);
7027 final SubscriptionManager sub = SubscriptionManager.from(context);
7028
7029 // Figure out what subscribers are currently active
7030 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031
Jordan Liub49b04b2019-05-06 14:45:15 -07007032 // Only consider subs which match the current subId
7033 // This logic can be simplified. See b/131189269 for progress.
7034 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007035 activeSubscriberIds.add(tele.getSubscriberId(subId));
7036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007037
7038 // First pass, find a number override for an active subscriber
7039 String mergeNumber = null;
7040 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7041 for (String key : prefs.keySet()) {
7042 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7043 final String subscriberId = (String) prefs.get(key);
7044 if (activeSubscriberIds.contains(subscriberId)) {
7045 final String iccId = key.substring(
7046 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7047 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7048 mergeNumber = (String) prefs.get(numberKey);
7049 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007050 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 + " for active subscriber " + subscriberId);
7052 }
7053 if (!TextUtils.isEmpty(mergeNumber)) {
7054 break;
7055 }
7056 }
7057 }
7058 }
7059
7060 // Shortcut when no active merged subscribers
7061 if (TextUtils.isEmpty(mergeNumber)) {
7062 return null;
7063 }
7064
7065 // Second pass, find all subscribers under that line override
7066 final ArraySet<String> result = new ArraySet<>();
7067 for (String key : prefs.keySet()) {
7068 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7069 final String number = (String) prefs.get(key);
7070 if (mergeNumber.equals(number)) {
7071 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7072 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7073 final String subscriberId = (String) prefs.get(subscriberKey);
7074 if (!TextUtils.isEmpty(subscriberId)) {
7075 result.add(subscriberId);
7076 }
7077 }
7078 }
7079 }
7080
7081 final String[] resultArray = result.toArray(new String[result.size()]);
7082 Arrays.sort(resultArray);
7083 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007084 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007085 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7086 }
7087 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007088 } finally {
7089 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007090 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007091 }
7092
7093 @Override
zoey chen38003472019-12-13 17:16:31 +08007094 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7095 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007096
7097 final long identity = Binder.clearCallingIdentity();
7098 try {
7099 final TelephonyManager telephonyManager = mApp.getSystemService(
7100 TelephonyManager.class);
7101 String subscriberId = telephonyManager.getSubscriberId(subId);
7102 if (subscriberId == null) {
7103 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007104 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007105 + subId);
7106 }
7107 return null;
7108 }
7109
Jack Yudf049d72022-12-02 22:48:35 -08007110 ParcelUuid groupUuid;
7111 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7112 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7113 .getSubscriptionInfo(subId);
7114 groupUuid = info.getGroupUuid();
7115 } else {
7116 final SubscriptionInfo info = mSubscriptionController
7117 .getSubscriptionInfo(subId);
7118 groupUuid = info.getGroupUuid();
7119 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007120 // If it doesn't belong to any group, return just subscriberId of itself.
7121 if (groupUuid == null) {
7122 return new String[]{subscriberId};
7123 }
7124
7125 // Get all subscriberIds from the group.
7126 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yudf049d72022-12-02 22:48:35 -08007127 List<SubscriptionInfo> groupInfos;
7128 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7129 groupInfos = SubscriptionManagerService.getInstance()
7130 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7131 mApp.getAttributionTag());
7132 } else {
7133 groupInfos = mSubscriptionController
7134 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7135 mApp.getAttributionTag());
7136 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007137 for (SubscriptionInfo subInfo : groupInfos) {
7138 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7139 if (subscriberId != null) {
7140 mergedSubscriberIds.add(subscriberId);
7141 }
7142 }
7143
7144 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7145 } finally {
7146 Binder.restoreCallingIdentity(identity);
7147
7148 }
7149 }
7150
7151 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007152 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007153 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007154 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007155
7156 final long identity = Binder.clearCallingIdentity();
7157 try {
7158 final Phone phone = getPhone(subId);
7159 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7160 } finally {
7161 Binder.restoreCallingIdentity(identity);
7162 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007163 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007164
7165 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007166 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007167 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7168 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007169 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7170 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171
7172 final long identity = Binder.clearCallingIdentity();
7173 try {
7174 final Phone phone = getPhone(subId);
7175 if (phone == null) {
7176 return false;
7177 }
7178 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7179 cdmaNonRoamingList);
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007182 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007183 }
7184
7185 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007186 @Deprecated
7187 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7188 enforceModifyPermission();
7189
7190 int returnValue = 0;
7191 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007192 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007193 if(result.exception == null) {
7194 if (result.result != null) {
7195 byte[] responseData = (byte[])(result.result);
7196 if(responseData.length > oemResp.length) {
7197 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7198 responseData.length + "bytes. Buffer Size is " +
7199 oemResp.length + "bytes.");
7200 }
7201 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7202 returnValue = responseData.length;
7203 }
7204 } else {
7205 CommandException ex = (CommandException) result.exception;
7206 returnValue = ex.getCommandError().ordinal();
7207 if(returnValue > 0) returnValue *= -1;
7208 }
7209 } catch (RuntimeException e) {
7210 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7211 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7212 if(returnValue > 0) returnValue *= -1;
7213 }
7214
7215 return returnValue;
7216 }
7217
7218 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007219 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007220 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007221 try {
7222 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007223 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007224 mApp, phone.getSubId(), "getRadioAccessFamily");
7225 } catch (SecurityException e) {
7226 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7227 throw e;
7228 }
chen xub97461a2018-10-26 14:17:57 -07007229 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007230 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007231 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007233 final long identity = Binder.clearCallingIdentity();
7234 try {
chen xub97461a2018-10-26 14:17:57 -07007235 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007236 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007237 mApp, phone.getSubId(), "getRadioAccessFamily");
7238 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239 } finally {
7240 Binder.restoreCallingIdentity(identity);
7241 }
chen xub97461a2018-10-26 14:17:57 -07007242 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007243 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007244
7245 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007246 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007247 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007248 try {
7249 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7250 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007251 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007252 }
7253 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007254 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007255 }
7256 RoleManager rm = mApp.getSystemService(RoleManager.class);
7257 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7258 if (!dialerRoleHolders.contains(callingPackage)) {
7259 throw new SecurityException("App must be the dialer role holder to"
7260 + " upload a call composer pic");
7261 }
7262
7263 Executors.newSingleThreadExecutor().execute(() -> {
7264 ByteArrayOutputStream output = new ByteArrayOutputStream(
7265 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7266 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7267 boolean readUntilEnd = false;
7268 int totalBytesRead = 0;
7269 byte[] buffer = new byte[16 * 1024];
7270 while (true) {
7271 int numRead;
7272 try {
7273 numRead = input.read(buffer);
7274 } catch (IOException e) {
7275 try {
7276 fd.checkError();
7277 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7278 null);
7279 } catch (IOException e1) {
7280 // This means that the other side closed explicitly with an error. If this
7281 // happens, log and ignore.
7282 loge("Remote end of call composer picture pipe closed: " + e1);
7283 }
7284 break;
7285 }
7286 if (numRead == -1) {
7287 readUntilEnd = true;
7288 break;
7289 }
7290 totalBytesRead += numRead;
7291 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7292 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7293 try {
7294 input.close();
7295 } catch (IOException e) {
7296 // ignore
7297 }
7298 break;
7299 }
7300 output.write(buffer, 0, numRead);
7301 }
7302 // Generally, the remote end will close the file descriptors. The only case where we
7303 // close is above, where the picture size is too big.
7304
7305 try {
7306 fd.checkError();
7307 } catch (IOException e) {
7308 loge("Remote end for call composer closed with an error: " + e);
7309 return;
7310 }
7311
Hall Liuaa4211e2021-01-20 15:43:39 -08007312 if (!readUntilEnd) {
7313 loge("Did not finish reading entire image; aborting");
7314 return;
7315 }
Hall Liu82694d52020-12-11 18:22:04 -08007316
Hall Liuaa4211e2021-01-20 15:43:39 -08007317 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7318 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7319 new CallComposerPictureTransfer.Factory() {},
7320 imageData,
7321 (result) -> {
7322 if (result.first != null) {
7323 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7324 Bundle outputResult = new Bundle();
7325 outputResult.putParcelable(
7326 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7327 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7328 outputResult);
7329 } else {
7330 callback.send(result.second, null);
7331 }
7332 }
7333 );
Hall Liu82694d52020-12-11 18:22:04 -08007334 });
7335 }
7336
7337 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007338 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007339 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007340 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341
7342 final long identity = Binder.clearCallingIdentity();
7343 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007344 ImsManager.getInstance(defaultPhone.getContext(),
7345 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007346 } finally {
7347 Binder.restoreCallingIdentity(identity);
7348 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007349 }
7350
7351 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007352 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007353 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007354 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7355 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007356 return false;
7357 }
Svet Ganovb320e182015-04-16 12:30:10 -07007358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007359 final long identity = Binder.clearCallingIdentity();
7360 try {
7361 // Check the user preference and the system-level IMS setting. Even if the user has
7362 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7363 // In the long run, we may instead need to check if there exists a connection service
7364 // which can support video calling.
7365 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007366 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 return imsManager.isVtEnabledByPlatform()
7368 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7369 && imsManager.isVtEnabledByUser();
7370 } finally {
7371 Binder.restoreCallingIdentity(identity);
7372 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007373 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007374
Andrew Leea1239f22015-03-02 17:44:07 -08007375 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007376 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7377 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007379 mApp, subId, callingPackage, callingFeatureId,
7380 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007381 return false;
7382 }
7383
7384 final long identity = Binder.clearCallingIdentity();
7385 try {
7386 CarrierConfigManager configManager =
7387 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007388 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7390 } finally {
7391 Binder.restoreCallingIdentity(identity);
7392 }
Andrew Leea1239f22015-03-02 17:44:07 -08007393 }
7394
7395 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007396 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007398 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007399 return false;
7400 }
7401
7402 final long identity = Binder.clearCallingIdentity();
7403 try {
7404 CarrierConfigManager configManager =
7405 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007406 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7408 } finally {
7409 Binder.restoreCallingIdentity(identity);
7410 }
Andrew Leea1239f22015-03-02 17:44:07 -08007411 }
7412
Andrew Lee9431b832015-03-09 18:46:45 -07007413 @Override
7414 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007415 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007416 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007417 }
7418
7419 @Override
7420 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421 final long identity = Binder.clearCallingIdentity();
7422 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007423 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 } finally {
7425 Binder.restoreCallingIdentity(identity);
7426 }
Andrew Lee9431b832015-03-09 18:46:45 -07007427 }
7428
Hall Liuf6668912018-10-31 17:05:23 -07007429 /**
7430 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7431 * support for the feature and device firmware support.
7432 *
7433 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7434 */
7435 @Override
7436 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007438 final Phone phone = getPhone(subscriptionId);
7439 if (phone == null) {
7440 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7441 return false;
7442 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007444 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7446 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007447 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007448 return isCarrierSupported && isDeviceSupported;
7449 } finally {
7450 Binder.restoreCallingIdentity(identity);
7451 }
Hall Liu98187582018-01-22 19:15:32 -08007452 }
7453
Hall Liuf6668912018-10-31 17:05:23 -07007454 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007455 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7456 * RTT setting, will return true if the device and carrier both support RTT.
7457 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007458 */
7459 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 final long identity = Binder.clearCallingIdentity();
7461 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007462 boolean isRttSupported = isRttSupported(subscriptionId);
7463 boolean isUserRttSettingOn = Settings.Secure.getInt(
7464 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7465 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7466 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7467 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 } finally {
7469 Binder.restoreCallingIdentity(identity);
7470 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007471 }
7472
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007473 @Deprecated
7474 @Override
7475 public String getDeviceId(String callingPackage) {
7476 return getDeviceIdWithFeature(callingPackage, null);
7477 }
7478
Sanket Padawe7310cc72015-01-14 09:53:20 -08007479 /**
7480 * Returns the unique device ID of phone, for example, the IMEI for
7481 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7482 *
7483 * <p>Requires Permission:
7484 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7485 */
7486 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007487 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007488 try {
7489 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7490 } catch (SecurityException se) {
7491 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7492 throw new SecurityException("Package " + callingPackage + " does not belong to "
7493 + Binder.getCallingUid());
7494 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007495 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007496 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007497 return null;
7498 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007499 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007500 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007501 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007502 return null;
7503 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504
7505 final long identity = Binder.clearCallingIdentity();
7506 try {
7507 return phone.getDeviceId();
7508 } finally {
7509 Binder.restoreCallingIdentity(identity);
7510 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007511 }
7512
Ping Sunc67b7c22016-03-02 19:16:45 +08007513 /**
7514 * {@hide}
7515 * Returns the IMS Registration Status on a particular subid
7516 *
7517 * @param subId
7518 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007519 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007520 Phone phone = getPhone(subId);
7521 if (phone != null) {
7522 return phone.isImsRegistered();
7523 } else {
7524 return false;
7525 }
7526 }
7527
Santos Cordon7a1885b2015-02-03 11:15:19 -08007528 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007529 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007530 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007532 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007533 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7534 }
7535 final long identity = Binder.clearCallingIdentity();
7536 try {
7537 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7538 } finally {
7539 Binder.restoreCallingIdentity(identity);
7540 }
7541 }
7542
7543 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007544 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007545 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007546 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007547 mApp,
7548 subscriptionId,
7549 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007550 final long identity = Binder.clearCallingIdentity();
7551 try {
7552 Phone phone = getPhone(subscriptionId);
7553 if (phone == null) {
7554 return null;
7555 }
7556 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7557 } finally {
7558 Binder.restoreCallingIdentity(identity);
7559 }
7560 }
7561
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007562 /**
7563 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007564 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007565 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 final long identity = Binder.clearCallingIdentity();
7567 try {
7568 Phone phone = getPhone(subId);
7569 if (phone != null) {
7570 return phone.isWifiCallingEnabled();
7571 } else {
7572 return false;
7573 }
7574 } finally {
7575 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007576 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007577 }
7578
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007579 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007580 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007581 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007582 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583 final long identity = Binder.clearCallingIdentity();
7584 try {
7585 Phone phone = getPhone(subId);
7586 if (phone != null) {
7587 return phone.isVideoEnabled();
7588 } else {
7589 return false;
7590 }
7591 } finally {
7592 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007593 }
7594 }
7595
7596 /**
7597 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7598 * defined in {@link ImsRegistrationImplBase}.
7599 */
7600 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007601 final long identity = Binder.clearCallingIdentity();
7602 try {
7603 Phone phone = getPhone(subId);
7604 if (phone != null) {
7605 return phone.getImsRegistrationTech();
7606 } else {
7607 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7608 }
7609 } finally {
7610 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007611 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007612 }
7613
Stuart Scott8eef64f2015-04-08 15:13:54 -07007614 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007615 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007616 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007617 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7618 return;
7619 }
Kai Shif70f46f2021-03-03 13:59:46 -08007620 Phone defaultPhone = getDefaultPhone();
7621 if (defaultPhone != null) {
7622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7623 mApp, getDefaultPhone().getSubId(), "factoryReset");
7624 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007625 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007626
Svet Ganovcc087f82015-05-12 20:35:54 -07007627 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007628 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7629 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007630 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007631 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007632 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007633 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007634 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007635 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007636 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007637 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007638 // There has been issues when Sms raw table somehow stores orphan
7639 // fragments. They lead to garbled message when new fragments come
7640 // in and combined with those stale ones. In case this happens again,
7641 // user can reset all network settings which will clean up this table.
7642 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007643 // Clean up IMS settings as well here.
7644 int slotId = getSlotIndex(subId);
7645 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7646 ImsManager.getInstance(mApp, slotId).factoryReset();
7647 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007648
Kai Shif70f46f2021-03-03 13:59:46 -08007649 if (defaultPhone == null) {
7650 return;
7651 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007652 // Erase modem config if erase modem on network setting is enabled.
7653 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7654 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7655 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007656 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007657 }
Kai Shif70f46f2021-03-03 13:59:46 -08007658
7659 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007660 } finally {
7661 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007662 }
7663 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007664
SongFerngWangfd89b102021-05-27 22:44:54 +08007665 @VisibleForTesting
7666 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7667 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7668 return;
7669 }
7670 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7671 RILConstants.PREFERRED_NETWORK_MODE);
7672 SubscriptionManager.setSubscriptionProperty(subId,
7673 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7674 "user=" + defaultNetworkType);
7675 phone.loadAllowedNetworksFromSubscriptionDatabase();
7676 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7677 defaultNetworkType, null);
7678 }
7679
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007680 private void cleanUpSmsRawTable(Context context) {
7681 ContentResolver resolver = context.getContentResolver();
7682 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7683 resolver.delete(uri, null, null);
7684 }
7685
Narayan Kamath1c496c22015-04-16 14:40:19 +01007686 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007687 public String getSimLocaleForSubscriber(int subId) {
7688 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7689 final Phone phone = getPhone(subId);
7690 if (phone == null) {
7691 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007692 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007694 final long identity = Binder.clearCallingIdentity();
7695 try {
Jack Yudf049d72022-12-02 22:48:35 -08007696 SubscriptionInfo info;
7697 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7698 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
7699 phone.getContext().getOpPackageName(),
7700 phone.getContext().getAttributionTag());
7701 if (info == null) {
7702 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7703 return null;
7704 }
7705 } else {
7706 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
7707 phone.getContext().getOpPackageName(),
7708 phone.getContext().getAttributionTag());
7709 if (info == null) {
7710 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7711 return null;
7712 }
chen xu6291c472019-02-04 12:55:53 -08007713 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007714 // Try and fetch the locale from the carrier properties or from the SIM language
7715 // preferences (EF-PL and EF-LI)...
7716 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007717 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007718 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7719 if (localeFromDefaultSim != null) {
7720 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7721 if (DBG) log("Using locale from subId: " + subId + " locale: "
7722 + localeFromDefaultSim);
tom hsu22b7c3e2022-10-27 00:10:04 +08007723 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007724 } else {
7725 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007726 }
7727 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007729 // The SIM language preferences only store a language (e.g. fr = French), not an
7730 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7731 // the SIM and carrier preferences does not include a country we add the country
7732 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007733 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007735 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu22b7c3e2022-10-27 00:10:04 +08007736 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007737 }
7738
7739 if (DBG) log("No locale found - returning null");
7740 return null;
7741 } finally {
7742 Binder.restoreCallingIdentity(identity);
7743 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007744 }
7745
tom hsue9360cd2022-09-29 23:49:21 +08007746 @VisibleForTesting
tom hsu22b7c3e2022-10-27 00:10:04 +08007747 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsue9360cd2022-09-29 23:49:21 +08007748 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu22b7c3e2022-10-27 00:10:04 +08007749 phone.getContext());
tom hsue9360cd2022-09-29 23:49:21 +08007750 for (String localeTag : supportedLocale) {
tom hsu22b7c3e2022-10-27 00:10:04 +08007751 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7752 && TextUtils.equals(inputLocale.getCountry(),
tom hsue9360cd2022-09-29 23:49:21 +08007753 Locale.forLanguageTag(localeTag).getCountry())) {
7754 return localeTag;
7755 }
7756 }
7757 return inputLocale.toLanguageTag();
7758 }
7759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 /**
7761 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7762 */
7763 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yudf049d72022-12-02 22:48:35 -08007764 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7765 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
7766 mApp.getOpPackageName(), mApp.getAttributionTag());
7767 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007768 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007769 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007770 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007771
Gary Jian3aa9a762022-01-24 16:41:19 +08007772 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7773 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007774
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007775 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007776 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7777 * representing the state of the modem.
7778 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007779 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7780 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007781 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007782 */
7783 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007784 public void requestModemActivityInfo(ResultReceiver result) {
7785 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007786 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007787
7788 final long identity = Binder.clearCallingIdentity();
7789 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007790 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007791 } finally {
7792 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007793 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007794 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007795
Siddharth Rayb8114062018-06-17 15:02:38 -07007796 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7797 // less than total activity duration.
7798 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7799 if (info == null) {
7800 return false;
7801 }
7802 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007803 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7804 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7805
Siddharth Rayb8114062018-06-17 15:02:38 -07007806 return (info.isValid()
7807 && (info.getSleepTimeMillis() <= activityDurationMs)
7808 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007809 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007810 && (totalTxTimeMs <= activityDurationMs));
7811 }
7812
Gary Jian3aa9a762022-01-24 16:41:19 +08007813 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7814 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7815 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7816 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7817
7818 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7819 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7820 }
7821
7822 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7823 mLastModemActivityInfo.setReceiveTimeMillis(
7824 rat,
7825 freq,
7826 info.getReceiveTimeMillis(rat, freq)
7827 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7828 }
7829
7830 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7831 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7832 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7833 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7834
7835 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7836 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7837 }
7838 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7839 mLastModemActivityInfo.setReceiveTimeMillis(
7840 rat,
7841 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7842 }
7843
7844 /**
7845 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7846 * @param info recent ModemActivityInfo
7847 */
7848 private void mergeModemActivityInfo(ModemActivityInfo info) {
7849 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7850 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7851 boolean matched;
7852 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7853 matched = false;
7854 int rat = info.getSpecificInfoRat(i);
7855 int freq = info.getSpecificInfoFrequencyRange(i);
7856 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7857 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7858 //if it already exists
7859 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7860 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7861 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7862 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7863 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7864 updateLastModemActivityInfo(info, rat, freq);
7865 matched = true;
7866 }
7867 } else {
7868 updateLastModemActivityInfo(info, rat);
7869 matched = true;
7870 }
7871 }
7872 }
7873
7874 if (!matched) {
7875 mDeltaSpecificInfo =
7876 new ActivityStatsTechSpecificInfo(
7877 rat,
7878 freq,
7879 info.getTransmitTimeMillis(rat, freq),
7880 (int) info.getReceiveTimeMillis(rat, freq));
7881 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7882 }
7883 }
7884 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7885 mLastModemActivitySpecificInfo =
7886 new ActivityStatsTechSpecificInfo[merged.size()];
7887 merged.toArray(mLastModemActivitySpecificInfo);
7888
7889 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7890 mLastModemActivityInfo.setSleepTimeMillis(
7891 info.getSleepTimeMillis()
7892 + mLastModemActivityInfo.getSleepTimeMillis());
7893 mLastModemActivityInfo.setIdleTimeMillis(
7894 info.getIdleTimeMillis()
7895 + mLastModemActivityInfo.getIdleTimeMillis());
7896 }
7897
Jack Yu85bd38a2015-11-09 11:34:32 -08007898 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007899 * Returns the service state information on specified subscription.
7900 */
7901 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007902 public ServiceState getServiceStateForSubscriber(int subId,
7903 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7904 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007906 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007907 return null;
7908 }
7909
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007910 boolean hasFinePermission = false;
7911 boolean hasCoarsePermission = false;
7912 if (!renounceFineLocationAccess) {
7913 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7914 LocationAccessPolicy.checkLocationPermission(mApp,
7915 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7916 .setCallingPackage(callingPackage)
7917 .setCallingFeatureId(callingFeatureId)
7918 .setCallingPid(Binder.getCallingPid())
7919 .setCallingUid(Binder.getCallingUid())
7920 .setMethod("getServiceStateForSubscriber")
7921 .setLogAsInfo(true)
7922 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7923 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7924 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7925 .build());
7926 hasFinePermission =
7927 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7928 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007929
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007930 if (!renounceCoarseLocationAccess) {
7931 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7932 LocationAccessPolicy.checkLocationPermission(mApp,
7933 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7934 .setCallingPackage(callingPackage)
7935 .setCallingFeatureId(callingFeatureId)
7936 .setCallingPid(Binder.getCallingPid())
7937 .setCallingUid(Binder.getCallingUid())
7938 .setMethod("getServiceStateForSubscriber")
7939 .setLogAsInfo(true)
7940 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7941 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7942 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7943 .build());
7944 hasCoarsePermission =
7945 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7946 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007947
Jack Yu479f40e2020-10-27 21:29:25 -07007948 final Phone phone = getPhone(subId);
7949 if (phone == null) {
7950 return null;
7951 }
7952
Jordan Liu0f2bc442020-11-18 16:47:37 -08007953 final long identity = Binder.clearCallingIdentity();
7954
Jack Yu479f40e2020-10-27 21:29:25 -07007955 boolean isCallingPackageDataService = phone.getDataServicePackages()
7956 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007958 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yudf049d72022-12-02 22:48:35 -08007959 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7960 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
7961 .getSubscriptionInfoInternal(subId);
7962 if (subInfo == null || !subInfo.isActive()) {
7963 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
7964 + "subId=" + subId);
7965 return null;
7966 }
7967 } else {
7968 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
7969 callingFeatureId)) {
7970 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
7971 + "subId=" + subId);
7972 return null;
7973 }
Jordan Liuc437b192020-08-17 10:59:12 -07007974 }
7975
Hall Liuf19c44f2018-11-27 14:38:17 -08007976 ServiceState ss = phone.getServiceState();
7977
7978 // Scrub out the location info in ServiceState depending on what level of access
7979 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007980 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007981 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7982 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007983 } finally {
7984 Binder.restoreCallingIdentity(identity);
7985 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007986 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007987
7988 /**
7989 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7990 *
7991 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7992 * voicemail ringtone.
7993 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7994 * PhoneAccount.
7995 */
7996 @Override
7997 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007998 final long identity = Binder.clearCallingIdentity();
7999 try {
8000 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8001 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008002 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008003 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8006 } finally {
8007 Binder.restoreCallingIdentity(identity);
8008 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008009 }
8010
8011 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008012 * Sets the per-account voicemail ringtone.
8013 *
8014 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8015 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8016 *
8017 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8018 * voicemail ringtone.
8019 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8020 * PhoneAccount.
8021 */
8022 @Override
8023 public void setVoicemailRingtoneUri(String callingPackage,
8024 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008025 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008026 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008027 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8028 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8030 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8031 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008033
8034 final long identity = Binder.clearCallingIdentity();
8035 try {
8036 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8037 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008038 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008039 }
8040 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8041 } finally {
8042 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008043 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008044 }
8045
8046 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008047 * Returns whether vibration is set for voicemail notification in Phone settings.
8048 *
8049 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8050 * voicemail vibration setting.
8051 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8052 */
8053 @Override
8054 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055 final long identity = Binder.clearCallingIdentity();
8056 try {
8057 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8058 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008059 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008060 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008061
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008062 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8063 } finally {
8064 Binder.restoreCallingIdentity(identity);
8065 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008066 }
8067
Youhan Wange64578a2016-05-02 15:32:42 -07008068 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008069 * Sets the per-account voicemail vibration.
8070 *
8071 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8072 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8073 *
8074 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8075 * voicemail vibration setting.
8076 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8077 * specific PhoneAccount.
8078 */
8079 @Override
8080 public void setVoicemailVibrationEnabled(String callingPackage,
8081 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008082 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008083 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008084 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8085 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8087 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8088 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008089 }
8090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091 final long identity = Binder.clearCallingIdentity();
8092 try {
8093 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8094 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008095 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008096 }
8097 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8098 } finally {
8099 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008100 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008101 }
8102
8103 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008104 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8105 *
8106 * @throws SecurityException if the caller does not have the required permission
8107 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008108 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008109 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008110 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008111 }
8112
8113 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008114 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8115 * permission.
8116 *
8117 * @throws SecurityException if the caller does not have the required permission
8118 */
8119 private void enforceSendSmsPermission() {
8120 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8121 }
8122
8123 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008124 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008125 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008126 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008127 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008128 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008129 final long identity = Binder.clearCallingIdentity();
8130 try {
8131 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008132 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133 if (componentName == null) {
8134 throw new SecurityException(
8135 "Caller not current active visual voicemail package[null]");
8136 }
8137 String vvmPackage = componentName.getPackageName();
8138 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008139 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008140 }
8141 } finally {
8142 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008143 }
8144 }
8145
8146 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008147 * Return the application ID for the app type.
8148 *
8149 * @param subId the subscription ID that this request applies to.
8150 * @param appType the uicc app type.
8151 * @return Application ID for specificied app type, or null if no uicc.
8152 */
8153 @Override
8154 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008155 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008156 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008157
8158 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008159 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008160 if (phone == null) {
8161 return null;
8162 }
8163 String aid = null;
8164 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008165 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008166 .getApplicationByType(appType).getAid();
8167 } catch (Exception e) {
8168 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8169 }
8170 return aid;
8171 } finally {
8172 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008173 }
Youhan Wange64578a2016-05-02 15:32:42 -07008174 }
8175
Youhan Wang4001d252016-05-11 10:29:41 -07008176 /**
8177 * Return the Electronic Serial Number.
8178 *
8179 * @param subId the subscription ID that this request applies to.
8180 * @return ESN or null if error.
8181 */
8182 @Override
8183 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008184 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008185 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008186
8187 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008188 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189 if (phone == null) {
8190 return null;
8191 }
8192 String esn = null;
8193 try {
8194 esn = phone.getEsn();
8195 } catch (Exception e) {
8196 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8197 }
8198 return esn;
8199 } finally {
8200 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008201 }
Youhan Wang4001d252016-05-11 10:29:41 -07008202 }
8203
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008204 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008205 * Return the Preferred Roaming List Version.
8206 *
8207 * @param subId the subscription ID that this request applies to.
8208 * @return PRLVersion or null if error.
8209 */
8210 @Override
8211 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008212 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008213 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214
8215 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008216 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008217 if (phone == null) {
8218 return null;
8219 }
8220 String cdmaPrlVersion = null;
8221 try {
8222 cdmaPrlVersion = phone.getCdmaPrlVersion();
8223 } catch (Exception e) {
8224 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8225 }
8226 return cdmaPrlVersion;
8227 } finally {
8228 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008229 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008230 }
8231
8232 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008233 * Get snapshot of Telephony histograms
8234 * @return List of Telephony histograms
8235 * @hide
8236 */
8237 @Override
8238 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8240 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241
8242 final long identity = Binder.clearCallingIdentity();
8243 try {
8244 return RIL.getTelephonyRILTimingHistograms();
8245 } finally {
8246 Binder.restoreCallingIdentity(identity);
8247 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008248 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008249
8250 /**
8251 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008252 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8253 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008254 * Require system privileges. In the future we may add this to carrier APIs.
8255 *
Michele Berionne482f8202018-11-27 18:57:59 -08008256 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008257 */
8258 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008259 @TelephonyManager.SetCarrierRestrictionResult
8260 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008261 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008262 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008263
Michele Berionne482f8202018-11-27 18:57:59 -08008264 if (carrierRestrictionRules == null) {
8265 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008266 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008267
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008268 final long identity = Binder.clearCallingIdentity();
8269 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008270 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008271 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008272 } finally {
8273 Binder.restoreCallingIdentity(identity);
8274 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008275 }
8276
8277 /**
8278 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008279 * Get the allowed carrier list and the excluded carrier list, including the priority between
8280 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008281 * Require system privileges. In the future we may add this to carrier APIs.
8282 *
Michele Berionne482f8202018-11-27 18:57:59 -08008283 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008284 */
8285 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008286 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008287 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008288 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008289
8290 final long identity = Binder.clearCallingIdentity();
8291 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008292 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8293 if (response instanceof CarrierRestrictionRules) {
8294 return (CarrierRestrictionRules) response;
8295 }
8296 // Response is an Exception of some kind,
8297 // which is signalled to the user as a NULL retval
8298 return null;
8299 } catch (Exception e) {
8300 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8301 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302 } finally {
8303 Binder.restoreCallingIdentity(identity);
8304 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008305 }
8306
fionaxu59545b42016-05-25 15:53:37 -07008307 /**
fionaxu59545b42016-05-25 15:53:37 -07008308 * Action set from carrier signalling broadcast receivers to enable/disable radio
8309 * @param subId the subscription ID that this action applies to.
8310 * @param enabled control enable or disable radio.
8311 * {@hide}
8312 */
8313 @Override
8314 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8315 enforceModifyPermission();
8316 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008317
8318 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008319 if (phone == null) {
8320 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8321 return;
8322 }
8323 try {
8324 phone.carrierActionSetRadioEnabled(enabled);
8325 } catch (Exception e) {
8326 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008327 } finally {
8328 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008329 }
8330 }
8331
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008332 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008333 * Enable or disable Voice over NR (VoNR)
8334 * @param subId the subscription ID that this action applies to.
8335 * @param enabled enable or disable VoNR.
8336 * @return operation result.
8337 */
8338 @Override
8339 public int setVoNrEnabled(int subId, boolean enabled) {
8340 enforceModifyPermission();
8341 final Phone phone = getPhone(subId);
8342
8343 final long identity = Binder.clearCallingIdentity();
8344 if (phone == null) {
8345 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8346 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8347 }
8348
8349 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8350 try {
8351 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8352 workSource);
8353 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008354
8355 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8356 if (DBG) {
8357 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8358 }
8359 SubscriptionManager.setSubscriptionProperty(
8360 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8361 (enabled ? "1" : "0"));
8362 }
8363
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008364 return result;
8365 } finally {
8366 Binder.restoreCallingIdentity(identity);
8367 }
8368 }
8369
8370 /**
8371 * Is voice over NR enabled
8372 * @return true if VoNR is enabled else false
8373 */
8374 @Override
8375 public boolean isVoNrEnabled(int subId) {
8376 enforceReadPrivilegedPermission("isVoNrEnabled");
8377 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8378 final long identity = Binder.clearCallingIdentity();
8379 try {
8380 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8381 null, subId, workSource);
8382 if (DBG) log("isVoNrEnabled: " + isEnabled);
8383 return isEnabled;
8384 } finally {
8385 Binder.restoreCallingIdentity(identity);
8386 }
8387 }
8388
8389 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008390 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8391 * network status based on which carrier apps could apply actions accordingly,
8392 * enable/disable default url handler for example.
8393 *
8394 * @param subId the subscription ID that this action applies to.
8395 * @param report control start/stop reporting the default network status.
8396 * {@hide}
8397 */
8398 @Override
8399 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8400 enforceModifyPermission();
8401 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008402
8403 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008404 if (phone == null) {
8405 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8406 return;
8407 }
8408 try {
8409 phone.carrierActionReportDefaultNetworkStatus(report);
8410 } catch (Exception e) {
8411 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008412 } finally {
8413 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008414 }
8415 }
8416
8417 /**
fionaxud9622282017-07-17 17:51:30 -07008418 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8419 * @param subId the subscription ID that this action applies to.
8420 * {@hide}
8421 */
8422 @Override
8423 public void carrierActionResetAll(int subId) {
8424 enforceModifyPermission();
8425 final Phone phone = getPhone(subId);
8426 if (phone == null) {
8427 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8428 return;
8429 }
8430 try {
8431 phone.carrierActionResetAll();
8432 } catch (Exception e) {
8433 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8434 }
8435 }
8436
8437 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008438 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8439 * bug report is being generated.
8440 */
8441 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008442 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008443 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8444 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008445 writer.println("Permission Denial: can't dump Phone from pid="
8446 + Binder.getCallingPid()
8447 + ", uid=" + Binder.getCallingUid()
8448 + "without permission "
8449 + android.Manifest.permission.DUMP);
8450 return;
8451 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008452 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008453 }
Jack Yueb89b242016-06-22 13:27:47 -07008454
Brad Ebingerdac2f002018-04-03 15:17:52 -07008455 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008456 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8457 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8458 @NonNull String[] args) {
8459 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8460 this, in.getFileDescriptor(), out.getFileDescriptor(),
8461 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008462 }
8463
Jack Yueb89b242016-06-22 13:27:47 -07008464 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008465 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008466 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008467 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008468 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008469 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008470 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008471 */
8472 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008473 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008474 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008475 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8476 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8477 try {
8478 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008479 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008480 } catch (SecurityException se) {
8481 enforceModifyPermission();
8482 }
8483 } else {
8484 enforceModifyPermission();
8485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008486
8487 final long identity = Binder.clearCallingIdentity();
8488 try {
8489 Phone phone = getPhone(subId);
8490 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008491 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8492 phone.carrierActionSetMeteredApnsEnabled(enabled);
8493 } else {
Jack Yuabb10902022-07-31 00:43:21 -07008494 phone.getDataSettingsManager().setDataEnabled(
8495 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008497 }
8498 } finally {
8499 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008500 }
8501 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008502
8503 /**
8504 * Get Client request stats
8505 * @return List of Client Request Stats
8506 * @hide
8507 */
8508 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008509 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8510 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008511 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008512 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008513 return null;
8514 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008515 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008516
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008517 final long identity = Binder.clearCallingIdentity();
8518 try {
8519 if (phone != null) {
8520 return phone.getClientRequestStats();
8521 }
8522
8523 return null;
8524 } finally {
8525 Binder.restoreCallingIdentity(identity);
8526 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008527 }
8528
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008529 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008530 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008531 if (uid == Process.ROOT_UID && packageName == null) {
8532 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8533 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8534 // exception. ROOT_UID seems not to have a valid package name returned by
8535 // PackageManager, so just fake it here to avoid issues when running telephony shell
8536 // commands that plumb through the RIL as root, like so:
8537 // $ adb root
8538 // $ adb shell cmd phone ...
8539 packageName = "root";
8540 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008541 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008542 }
Jack Yueb4124c2017-02-16 15:32:43 -08008543
8544 /**
Grace Chen70990072017-03-24 17:21:30 -07008545 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008546 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008547 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008548 * @param state State of SIM (power down, power up, pass through)
8549 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8550 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8551 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008552 *
8553 **/
8554 @Override
Grace Chen70990072017-03-24 17:21:30 -07008555 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008556 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008557 Phone phone = PhoneFactory.getPhone(slotIndex);
8558
vagdeviaf9a5b92018-08-15 16:01:53 -07008559 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008561 final long identity = Binder.clearCallingIdentity();
8562 try {
8563 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008564 phone.setSimPowerState(state, null, workSource);
8565 }
8566 } finally {
8567 Binder.restoreCallingIdentity(identity);
8568 }
8569 }
8570
8571 /**
8572 * Set SIM card power state.
8573 *
8574 * @param slotIndex SIM slot id.
8575 * @param state State of SIM (power down, power up, pass through)
8576 * @param callback callback to trigger after success or failure
8577 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8578 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8579 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8580 *
8581 **/
8582 @Override
8583 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8584 IIntegerConsumer callback) {
8585 enforceModifyPermission();
8586 Phone phone = PhoneFactory.getPhone(slotIndex);
8587
8588 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8589
8590 final long identity = Binder.clearCallingIdentity();
8591 try {
8592 if (phone != null) {
8593 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8594 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008595 }
8596 } finally {
8597 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008598 }
8599 }
Shuo Qiandd210312017-04-12 22:11:33 +00008600
Tyler Gunn65d45c22017-06-05 11:22:26 -07008601 private boolean isUssdApiAllowed(int subId) {
8602 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008603 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008604 if (configManager == null) {
8605 return false;
8606 }
8607 PersistableBundle pb = configManager.getConfigForSubId(subId);
8608 if (pb == null) {
8609 return false;
8610 }
8611 return pb.getBoolean(
8612 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8613 }
8614
Shuo Qiandd210312017-04-12 22:11:33 +00008615 /**
8616 * Check if phone is in emergency callback mode
8617 * @return true if phone is in emergency callback mode
8618 * @param subId sub id
8619 */
goneil9c5f4872017-12-05 14:07:56 -08008620 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008621 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008622 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008623 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008624
8625 final long identity = Binder.clearCallingIdentity();
8626 try {
8627 if (phone != null) {
8628 return phone.isInEcm();
8629 } else {
8630 return false;
8631 }
8632 } finally {
8633 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008634 }
8635 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008636
8637 /**
8638 * Get the current signal strength information for the given subscription.
8639 * Because this information is not updated when the device is in a low power state
8640 * it should not be relied-upon to be current.
8641 * @param subId Subscription index
8642 * @return the most recent cached signal strength info from the modem
8643 */
8644 @Override
8645 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008646 final long identity = Binder.clearCallingIdentity();
8647 try {
8648 Phone p = getPhone(subId);
8649 if (p == null) {
8650 return null;
8651 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008653 return p.getSignalStrength();
8654 } finally {
8655 Binder.restoreCallingIdentity(identity);
8656 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008657 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008658
Pengquan Meng77b7f132018-08-22 14:49:57 -07008659 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008660 * Get the current modem radio state for the given slot.
8661 * @param slotIndex slot index.
8662 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008663 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008664 * @return the current radio power state from the modem
8665 */
8666 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008667 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008668 Phone phone = PhoneFactory.getPhone(slotIndex);
8669 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008670 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8671 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008672 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8673 }
8674
8675 final long identity = Binder.clearCallingIdentity();
8676 try {
8677 return phone.getRadioPowerState();
8678 } finally {
8679 Binder.restoreCallingIdentity(identity);
8680 }
8681 }
8682 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8683 }
8684
8685 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008686 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8687 *
8688 * <p>Requires one of the following permissions:
8689 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008690 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008691 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8692 * privileges.
8693 *
8694 * @param subId subscription id
8695 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8696 * {@code false}.
8697 */
8698 @Override
8699 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008700 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008701 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008702 try {
8703 mApp.enforceCallingOrSelfPermission(
8704 android.Manifest.permission.ACCESS_NETWORK_STATE,
8705 functionName);
8706 } catch (Exception e) {
8707 mApp.enforceCallingOrSelfPermission(
8708 permission.READ_BASIC_PHONE_STATE, functionName);
8709 }
Shuo Qian093013d2020-08-13 15:42:55 -07008710 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008711 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008712 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008713 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008714
Pengquan Menga1bb6272018-09-06 09:59:22 -07008715 boolean isEnabled = false;
8716 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008717 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008718 Phone phone = getPhone(subId);
8719 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008720 } finally {
8721 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008722 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008723 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008724 }
8725
8726
8727 /**
8728 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8729 *
8730 * <p> Requires permission:
8731 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8732 * privileges.
8733 *
8734 * @param subId subscription id
8735 * @param isEnabled {@code true} means enable, {@code false} means disable.
8736 */
8737 @Override
8738 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8740 mApp, subId, "setDataRoamingEnabled");
8741
Pengquan Menga1bb6272018-09-06 09:59:22 -07008742 final long identity = Binder.clearCallingIdentity();
8743 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008744 Phone phone = getPhone(subId);
8745 if (phone != null) {
8746 phone.setDataRoamingEnabled(isEnabled);
8747 }
8748 } finally {
8749 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008750 }
8751 }
8752
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008753 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008754 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008755 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008756 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008757 mApp, subId, "isManualNetworkSelectionAllowed");
8758
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008759 boolean isAllowed = true;
8760 final long identity = Binder.clearCallingIdentity();
8761 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008762 Phone phone = getPhone(subId);
8763 if (phone != null) {
8764 isAllowed = phone.isCspPlmnEnabled();
8765 }
8766 } finally {
8767 Binder.restoreCallingIdentity(identity);
8768 }
8769 return isAllowed;
8770 }
8771
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008772 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8773 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008774 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008775 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008776 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008777 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8778 if (phone == null) {
8779 return false;
8780 }
8781 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8782 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8783 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008784 }
8785
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008786 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008787 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008788 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008789 mApp.getSystemService(AppOpsManager.class)
8790 .checkPackage(Binder.getCallingUid(), callingPackage);
8791
Jordan Liu1e142fc2019-04-22 15:10:43 -07008792 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008793 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008794 try {
8795 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008796 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008797 } catch (SecurityException e) {
8798 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8799 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008800 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008801 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008802 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008803 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008804 }
sandeepjsb6c87872021-09-27 15:34:44 +00008805 // checking compatibility, if calling app's target SDK is T and beyond.
8806 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8807 Binder.getCallingUid())) {
8808 isIccIdAccessRestricted = true;
8809 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008810 final long identity = Binder.clearCallingIdentity();
8811 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008812 UiccController uiccController = UiccController.getInstance();
8813 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008814 if (hasReadPermission) {
8815 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008816 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008817
8818 // Remove private info if the caller doesn't have access
8819 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8820 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008821 //setting the value after compatibility check
8822 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008823 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8824 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008825 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008826 if (card == null) {
8827 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008828 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008829 continue;
8830 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008831 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8832 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008833 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008834 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008835 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008836 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8837 for (UiccPortInfo portInfo : portInfos) {
8838 UiccPort port = uiccController.getUiccPortForSlot(
8839 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8840 if (port == null) {
8841 // assume no access if port is null
8842 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8843 continue;
8844 }
8845 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8846 uiccPortInfos.add(portInfo);
8847 } else {
8848 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8849 }
8850 }
8851 filteredInfos.add(new UiccCardInfo(
8852 cardInfo.isEuicc(),
8853 cardInfo.getCardId(),
8854 null,
8855 cardInfo.getPhysicalSlotIndex(),
8856 cardInfo.isRemovable(),
8857 cardInfo.isMultipleEnabledProfilesSupported(),
8858 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008859 }
8860 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008861 } finally {
8862 Binder.restoreCallingIdentity(identity);
8863 }
8864 }
8865
sandeepjsb6c87872021-09-27 15:34:44 +00008866 /**
8867 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8868 * generally private and require carrier privileges to view.
8869 *
8870 * @hide
8871 */
8872 @NonNull
8873 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8874 List<UiccPortInfo> portinfo = new ArrayList<>();
8875 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8876 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8877 }
8878 return new UiccCardInfo(
8879 cardInfo.isEuicc(),
8880 cardInfo.getCardId(),
8881 null,
8882 cardInfo.getPhysicalSlotIndex(),
8883 cardInfo.isRemovable(),
8884 cardInfo.isMultipleEnabledProfilesSupported(),
8885 portinfo
8886 );
8887 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008888
sandeepjsb6c87872021-09-27 15:34:44 +00008889 /**
8890 * @hide
8891 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8892 * These values are generally private and require carrier privileges to view.
8893 */
8894 @NonNull
8895 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8896 return new UiccPortInfo(
8897 UiccPortInfo.ICCID_REDACTED,
8898 portInfo.getPortIndex(),
8899 portInfo.getLogicalSlotIndex(),
8900 portInfo.isActive()
8901 );
8902 }
8903 @Override
8904 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008905 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008906 mApp.getSystemService(AppOpsManager.class)
8907 .checkPackage(Binder.getCallingUid(), callingPackage);
8908
sandeepjsb6c87872021-09-27 15:34:44 +00008909 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008910
Aman Guptaf3c90b32022-03-17 04:54:16 +00008911 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8912 // we are reading iccId which is PII data.
8913 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008914
8915 // checking compatibility, if calling app's target SDK is T and beyond.
8916 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8917 Binder.getCallingUid())) {
8918 isLogicalSlotAccessRestricted = true;
8919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008920 final long identity = Binder.clearCallingIdentity();
8921 try {
8922 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008923 if (slots == null || slots.length == 0) {
8924 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008925 return null;
8926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008927 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8928 for (int i = 0; i < slots.length; i++) {
8929 UiccSlot slot = slots[i];
8930 if (slot == null) {
8931 continue;
8932 }
8933
Jordan Liu7be7e652019-05-06 18:55:02 +00008934 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008935 UiccCard card = slot.getUiccCard();
8936 if (card != null) {
8937 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008938 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008939 cardId = slot.getEid();
8940 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00008941 // If cardId is null, use iccId of default port as cardId.
8942 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07008943 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008944 }
8945
Jordan Liu857451f2019-05-09 16:35:35 -07008946 if (cardId != null) {
8947 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8948 // if cardId is an EID, it's all digits so this is fine
8949 cardId = IccUtils.stripTrailingFs(cardId);
8950 }
8951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008952 int cardState = 0;
8953 switch (slot.getCardState()) {
8954 case CARDSTATE_ABSENT:
8955 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8956 break;
8957 case CARDSTATE_PRESENT:
8958 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8959 break;
8960 case CARDSTATE_ERROR:
8961 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8962 break;
8963 case CARDSTATE_RESTRICTED:
8964 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8965 break;
8966 default:
8967 break;
8968
8969 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008970 List<UiccPortInfo> portInfos = new ArrayList<>();
8971 int[] portIndexes = slot.getPortList();
8972 for (int portIdx : portIndexes) {
8973 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00008974 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008975 portInfos.add(new UiccPortInfo(iccId, portIdx,
8976 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008977 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008978 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008979 slot.isEuicc(),
8980 cardId,
8981 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008982 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008983 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008984 //setting the value after compatibility check
8985 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008986 }
8987 return infos;
8988 } finally {
8989 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008990 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008991 }
8992
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008993 /* Returns null if doesn't have read permission or carrier privilege access. */
8994 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8995 boolean hasReadPermission) {
8996 String iccId = slot.getIccId(portIndex);
8997 if (hasReadPermission) { // if has read permission
8998 return iccId;
8999 } else {
9000 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9001 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9002 // if no read permission, checking carrier privilege access
9003 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9004 return iccId;
9005 }
9006 }
9007 }
9008 // No read permission or carrier privilege access.
9009 return UiccPortInfo.ICCID_REDACTED;
9010 }
9011
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009012 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009013 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009014 public boolean switchSlots(int[] physicalSlots) {
9015 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009016
9017 final long identity = Binder.clearCallingIdentity();
9018 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009019 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9020 for (int i = 0; i < physicalSlots.length; i++) {
9021 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9022 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9023 physicalSlots[i], i));
9024 }
9025 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009026 } finally {
9027 Binder.restoreCallingIdentity(identity);
9028 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009029 }
Jack Yu4c988042018-02-27 15:30:01 -08009030
9031 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009032 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9033 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9034 enforceModifyPermission();
9035
9036 final long identity = Binder.clearCallingIdentity();
9037 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009038 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009039 } finally {
9040 Binder.restoreCallingIdentity(identity);
9041 }
9042 }
9043
9044 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009045 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009046 final long identity = Binder.clearCallingIdentity();
9047 try {
9048 return UiccController.getInstance().getCardIdForDefaultEuicc();
9049 } finally {
9050 Binder.restoreCallingIdentity(identity);
9051 }
9052 }
9053
Pengquan Meng85728fb2018-03-12 16:31:21 -07009054 /**
goneil47ffb6e2018-04-06 15:40:58 -07009055 * A test API to reload the UICC profile.
9056 *
9057 * <p>Requires that the calling app has permission
9058 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9059 * @hide
9060 */
9061 @Override
9062 public void refreshUiccProfile(int subId) {
9063 enforceModifyPermission();
9064
9065 final long identity = Binder.clearCallingIdentity();
9066 try {
9067 Phone phone = getPhone(subId);
9068 if (phone == null) {
9069 return;
9070 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009071 UiccPort uiccPort = phone.getUiccPort();
9072 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009073 return;
9074 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009075 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009076 if (uiccProfile == null) {
9077 return;
9078 }
9079 uiccProfile.refresh();
9080 } finally {
9081 Binder.restoreCallingIdentity(identity);
9082 }
9083 }
9084
9085 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009086 * Returns false if the mobile data is disabled by default, otherwise return true.
9087 */
9088 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009089 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009090 }
9091
9092 /**
9093 * Returns true if the data roaming is enabled by default, i.e the system property
9094 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9095 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9096 */
9097 private boolean getDefaultDataRoamingEnabled(int subId) {
9098 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009099 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009100 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009101 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9102 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9103 return isDataRoamingEnabled;
9104 }
9105
9106 /**
9107 * Returns the default network type for the given {@code subId}, if the default network type is
9108 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9109 */
9110 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009111 List<Integer> list = TelephonyProperties.default_network();
Jack Yudf049d72022-12-02 22:48:35 -08009112 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009113 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9114 return list.get(phoneId);
9115 }
9116 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009117 }
fionaxua13278b2018-03-21 00:08:13 -07009118
9119 @Override
9120 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009121 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009122 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009123
9124 final long identity = Binder.clearCallingIdentity();
9125 try {
9126 final Phone phone = getPhone(subId);
9127 if (phone == null) {
9128 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9129 return;
9130 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009131 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9132 if (cpt != null) {
9133 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9134 }
9135 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009136 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9137 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009138 if (carrierPrivilegeRules == null) {
9139 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9140 } else {
9141 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9142 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009143 } finally {
9144 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009145 }
fionaxua13278b2018-03-21 00:08:13 -07009146 }
9147
9148 @Override
9149 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009150 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009151
9152 final long identity = Binder.clearCallingIdentity();
9153 try {
9154 final Phone phone = getPhone(subId);
9155 if (phone == null) {
9156 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9157 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9158 }
9159 return phone.getCarrierIdListVersion();
9160 } finally {
9161 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009162 }
fionaxua13278b2018-03-21 00:08:13 -07009163 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009164
9165 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009166 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9167 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009168 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009169 mApp, subId, callingPackage, callingFeatureId,
9170 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009171 return -1;
9172 }
9173
9174 final long identity = Binder.clearCallingIdentity();
9175 try {
9176 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9177 } finally {
9178 Binder.restoreCallingIdentity(identity);
9179 }
9180 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009181
9182 @Override
9183 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009184 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009185 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009186 mApp, subId, "getCdmaRoamingMode");
9187
9188 final long identity = Binder.clearCallingIdentity();
9189 try {
9190 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9191 } finally {
9192 Binder.restoreCallingIdentity(identity);
9193 }
9194 }
9195
9196 @Override
9197 public boolean setCdmaRoamingMode(int subId, int mode) {
9198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9199 mApp, subId, "setCdmaRoamingMode");
9200
9201 final long identity = Binder.clearCallingIdentity();
9202 try {
9203 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9204 } finally {
9205 Binder.restoreCallingIdentity(identity);
9206 }
9207 }
9208
9209 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009210 public int getCdmaSubscriptionMode(int subId) {
9211 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009212 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009213 mApp, subId, "getCdmaSubscriptionMode");
9214
9215 final long identity = Binder.clearCallingIdentity();
9216 try {
9217 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9218 } finally {
9219 Binder.restoreCallingIdentity(identity);
9220 }
9221 }
9222
9223 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009224 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9226 mApp, subId, "setCdmaSubscriptionMode");
9227
9228 final long identity = Binder.clearCallingIdentity();
9229 try {
9230 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9231 } finally {
9232 Binder.restoreCallingIdentity(identity);
9233 }
9234 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009235
sqianc5eccab2018-10-19 18:46:41 -07009236 @Override
sqian8c685422019-02-22 15:55:18 -08009237 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009238 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009239 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009240 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9241 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009242 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9243 }
9244 final long identity = Binder.clearCallingIdentity();
9245 try {
sqian854d44b2018-12-12 16:48:18 -08009246 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9247 for (Phone phone: PhoneFactory.getPhones()) {
9248 if (phone.getEmergencyNumberTracker() != null
9249 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9250 emergencyNumberListInternal.put(
9251 phone.getSubId(),
9252 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9253 }
sqian11b7a0e2018-12-05 18:48:28 -08009254 }
sqian854d44b2018-12-12 16:48:18 -08009255 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009256 } finally {
9257 Binder.restoreCallingIdentity(identity);
9258 }
sqianc5eccab2018-10-19 18:46:41 -07009259 }
9260
9261 @Override
sqian8c685422019-02-22 15:55:18 -08009262 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009263 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009264 if (!exactMatch) {
9265 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009266 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009267 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009268 }
9269 final long identity = Binder.clearCallingIdentity();
9270 try {
sqian854d44b2018-12-12 16:48:18 -08009271 for (Phone phone: PhoneFactory.getPhones()) {
9272 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009273 && phone.getEmergencyNumberTracker()
9274 .isEmergencyNumber(number, exactMatch)) {
9275 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009276 }
sqian11b7a0e2018-12-05 18:48:28 -08009277 }
9278 return false;
9279 } finally {
9280 Binder.restoreCallingIdentity(identity);
9281 }
9282 }
9283
sqianf4ca7ed2019-01-15 18:32:07 -08009284 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009285 * Start emergency callback mode for GsmCdmaPhone for testing.
9286 */
9287 @Override
9288 public void startEmergencyCallbackMode() {
9289 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9290 "startEmergencyCallbackMode");
9291 enforceModifyPermission();
9292 final long identity = Binder.clearCallingIdentity();
9293 try {
9294 for (Phone phone : PhoneFactory.getPhones()) {
9295 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9296 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9297 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9298 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9299 gsmCdmaPhone.obtainMessage(
9300 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9301 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9302 }
9303 }
9304 } finally {
9305 Binder.restoreCallingIdentity(identity);
9306 }
9307 }
9308
9309 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009310 * Update emergency number list for test mode.
9311 */
9312 @Override
9313 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9314 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9315 "updateEmergencyNumberListTestMode");
9316
9317 final long identity = Binder.clearCallingIdentity();
9318 try {
9319 for (Phone phone: PhoneFactory.getPhones()) {
9320 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9321 if (tracker != null) {
9322 tracker.executeEmergencyNumberTestModeCommand(action, num);
9323 }
9324 }
9325 } finally {
9326 Binder.restoreCallingIdentity(identity);
9327 }
9328 }
9329
9330 /**
9331 * Get the full emergency number list for test mode.
9332 */
9333 @Override
9334 public List<String> getEmergencyNumberListTestMode() {
9335 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9336 "getEmergencyNumberListTestMode");
9337
9338 final long identity = Binder.clearCallingIdentity();
9339 try {
9340 Set<String> emergencyNumbers = new HashSet<>();
9341 for (Phone phone: PhoneFactory.getPhones()) {
9342 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9343 if (tracker != null) {
9344 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9345 emergencyNumbers.add(num.getNumber());
9346 }
9347 }
9348 }
9349 return new ArrayList<>(emergencyNumbers);
9350 } finally {
9351 Binder.restoreCallingIdentity(identity);
9352 }
9353 }
9354
chen xud6b45bd2018-10-30 22:27:10 -07009355 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009356 public int getEmergencyNumberDbVersion(int subId) {
9357 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9358
9359 final long identity = Binder.clearCallingIdentity();
9360 try {
9361 final Phone phone = getPhone(subId);
9362 if (phone == null) {
9363 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9364 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9365 }
9366 return phone.getEmergencyNumberDbVersion();
9367 } finally {
9368 Binder.restoreCallingIdentity(identity);
9369 }
9370 }
9371
9372 @Override
9373 public void notifyOtaEmergencyNumberDbInstalled() {
9374 enforceModifyPermission();
9375
9376 final long identity = Binder.clearCallingIdentity();
9377 try {
9378 for (Phone phone: PhoneFactory.getPhones()) {
9379 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9380 if (tracker != null) {
9381 tracker.updateOtaEmergencyNumberDatabase();
9382 }
9383 }
9384 } finally {
9385 Binder.restoreCallingIdentity(identity);
9386 }
9387 }
9388
9389 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009390 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009391 enforceActiveEmergencySessionPermission();
9392
9393 final long identity = Binder.clearCallingIdentity();
9394 try {
9395 for (Phone phone: PhoneFactory.getPhones()) {
9396 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9397 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009398 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9399 }
9400 }
9401 } finally {
9402 Binder.restoreCallingIdentity(identity);
9403 }
9404 }
9405
9406 @Override
9407 public void resetOtaEmergencyNumberDbFilePath() {
9408 enforceActiveEmergencySessionPermission();
9409
9410 final long identity = Binder.clearCallingIdentity();
9411 try {
9412 for (Phone phone: PhoneFactory.getPhones()) {
9413 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9414 if (tracker != null) {
9415 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009416 }
9417 }
9418 } finally {
9419 Binder.restoreCallingIdentity(identity);
9420 }
9421 }
9422
9423 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009424 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9425 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9426 Phone phone = getPhone(subId);
9427 if (phone == null) {
9428 return null;
9429 }
9430 final long identity = Binder.clearCallingIdentity();
9431 try {
9432 UiccProfile profile = UiccController.getInstance()
9433 .getUiccProfileForPhone(phone.getPhoneId());
9434 if (profile != null) {
9435 return profile.getCertsFromCarrierPrivilegeAccessRules();
9436 }
9437 } finally {
9438 Binder.restoreCallingIdentity(identity);
9439 }
9440 return null;
9441 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009442
9443 /**
9444 * Enable or disable a modem stack.
9445 */
9446 @Override
9447 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9448 enforceModifyPermission();
9449
9450 final long identity = Binder.clearCallingIdentity();
9451 try {
9452 Phone phone = PhoneFactory.getPhone(slotIndex);
9453 if (phone == null) {
9454 return false;
9455 } else {
9456 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9457 }
9458 } finally {
9459 Binder.restoreCallingIdentity(identity);
9460 }
9461 }
Michelecea4cf22018-12-21 15:00:11 -08009462
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009463 /**
9464 * Whether a modem stack is enabled or not.
9465 */
9466 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009467 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9468 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009469 Phone phone = PhoneFactory.getPhone(slotIndex);
9470 if (phone == null) return false;
9471
9472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009473 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9474 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009475 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9476 }
9477
9478 final long identity = Binder.clearCallingIdentity();
9479 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009480 try {
9481 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9482 } catch (NoSuchElementException ex) {
9483 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9484 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009485 } finally {
9486 Binder.restoreCallingIdentity(identity);
9487 }
9488 }
9489
Michelecea4cf22018-12-21 15:00:11 -08009490 @Override
Michele0ea7d782019-03-19 14:58:42 -07009491 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009492 enforceModifyPermission();
9493
9494 final long identity = Binder.clearCallingIdentity();
9495 try {
9496 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009497 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009498 .commit();
9499 } finally {
9500 Binder.restoreCallingIdentity(identity);
9501 }
9502 }
9503
9504 @Override
Michele0ea7d782019-03-19 14:58:42 -07009505 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009506 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009507 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009508 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9509 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009510 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009511 }
Michelecea4cf22018-12-21 15:00:11 -08009512
9513 final long identity = Binder.clearCallingIdentity();
9514 try {
Michele0ea7d782019-03-19 14:58:42 -07009515 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009516 } finally {
9517 Binder.restoreCallingIdentity(identity);
9518 }
9519 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009520
Michele0ea7d782019-03-19 14:58:42 -07009521 @TelephonyManager.IsMultiSimSupportedResult
9522 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009523 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9524 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9525 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009526 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9527 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009528 }
9529 // Check if the hardware supports multisim functionality. If usage of multisim is not
9530 // supported by the modem, indicate that it is restricted.
9531 PhoneCapability staticCapability =
9532 mPhoneConfigurationManager.getStaticPhoneCapability();
9533 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009534 loge("isMultiSimSupportedInternal: no static configuration available");
9535 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009536 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009537 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009538 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9539 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009540 }
9541 // Check if support of multiple SIMs is restricted by carrier
9542 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009543 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009544 }
9545
Michele0ea7d782019-03-19 14:58:42 -07009546 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009547 }
9548
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009549 /**
9550 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009551 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9552 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9553 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009554 * @param numOfSims number of active sims we want to switch to
9555 */
9556 @Override
9557 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009558 if (numOfSims == 1) {
9559 enforceModifyPermission();
9560 } else {
9561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9562 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9563 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009564 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009565
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009566 try {
Michele30b57b22019-03-01 12:01:14 -08009567 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009568 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009569 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9570 return;
9571 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009572 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9573 } finally {
9574 Binder.restoreCallingIdentity(identity);
9575 }
9576 }
9577
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009578 @Override
9579 public boolean isApplicationOnUicc(int subId, int appType) {
9580 enforceReadPrivilegedPermission("isApplicationOnUicc");
9581 Phone phone = getPhone(subId);
9582 if (phone == null) {
9583 return false;
9584 }
9585 final long identity = Binder.clearCallingIdentity();
9586 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009587 UiccPort uiccPort = phone.getUiccPort();
9588 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009589 return false;
9590 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009591 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009592 if (uiccProfile == null) {
9593 return false;
9594 }
9595 if (TelephonyManager.APPTYPE_SIM <= appType
9596 && appType <= TelephonyManager.APPTYPE_ISIM) {
9597 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9598 }
9599 return false;
9600 } finally {
9601 Binder.restoreCallingIdentity(identity);
9602 }
9603 }
9604
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009605 /**
chen xub4baa772019-04-03 10:23:41 -07009606 * Get whether making changes to modem configurations will trigger reboot.
9607 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009608 */
9609 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009610 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9611 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009612 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009613 mApp, subId, callingPackage, callingFeatureId,
9614 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009615 return false;
9616 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009617 final long identity = Binder.clearCallingIdentity();
9618 try {
9619 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9620 } finally {
9621 Binder.restoreCallingIdentity(identity);
9622 }
9623 }
9624
Nathan Harold29f5f052019-02-15 13:41:57 -08009625 private void updateModemStateMetrics() {
9626 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9627 // TODO: check the state for each modem if the api is ready.
9628 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9629 }
9630
Pengquan Meng3889a572019-01-23 11:16:29 -08009631 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009632 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009633 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009634 // Verify that the callingPackage belongs to the calling UID
9635 mApp.getSystemService(AppOpsManager.class)
9636 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009637 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009638 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009639 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009640 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9641 if (slotInfos != null) {
9642 for (int i = 0; i < slotInfos.length; i++) {
9643 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9644 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9645 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9646 portInfo.getLogicalSlotIndex()));
9647 }
9648 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009649 }
9650 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009651 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009652 } finally {
9653 Binder.restoreCallingIdentity(identity);
9654 }
9655 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009656
9657 /**
9658 * Get the IRadio HAL Version
9659 */
9660 @Override
9661 public int getRadioHalVersion() {
9662 Phone phone = getDefaultPhone();
9663 if (phone == null) return -1;
9664 HalVersion hv = phone.getHalVersion();
9665 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9666 return hv.major * 100 + hv.minor;
9667 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009668
9669 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009670 * Get the current calling package name.
9671 * @return the current calling package name
9672 */
9673 @Override
9674 public String getCurrentPackageName() {
9675 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9676 }
9677
9678 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009679 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9680 * corresponding network requests on a subId.
9681 *
9682 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009683 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009684 * 2) APN is un-metered for this subscription, or
9685 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009686 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009687 *
9688 * @return whether data is allowed for a apn type.
9689 *
9690 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009691 */
9692 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009693 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009694 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9695 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009696
9697 // Now that all security checks passes, perform the operation as ourselves.
9698 final long identity = Binder.clearCallingIdentity();
9699 try {
9700 Phone phone = getPhone(subId);
9701 if (phone == null) return false;
9702
Jack Yu27422a52022-03-21 10:38:05 -07009703 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009704 boolean isDataEnabled;
Jack Yuabb10902022-07-31 00:43:21 -07009705 isMetered = phone.getDataNetworkController().getDataConfigManager()
9706 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9707 phone.getServiceState().getDataRoaming());
9708 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009709 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009710 } finally {
9711 Binder.restoreCallingIdentity(identity);
9712 }
9713 }
9714
9715 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009716 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009717 enforceReadPrivilegedPermission("isApnMetered");
9718
9719 // Now that all security checks passes, perform the operation as ourselves.
9720 final long identity = Binder.clearCallingIdentity();
9721 try {
9722 Phone phone = getPhone(subId);
9723 if (phone == null) return true; // By default return true.
Jack Yuabb10902022-07-31 00:43:21 -07009724 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9725 DataUtils.apnTypeToNetworkCapability(apnType),
9726 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009727 } finally {
9728 Binder.restoreCallingIdentity(identity);
9729 }
9730 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009731
9732 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009733 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9734 int subscriptionId, IBooleanConsumer resultCallback) {
9735 enforceModifyPermission();
9736 long token = Binder.clearCallingIdentity();
9737 try {
9738 Phone phone = getPhone(subscriptionId);
9739 if (phone == null) {
9740 try {
9741 if (resultCallback != null) {
9742 resultCallback.accept(false);
9743 }
9744 } catch (RemoteException e) {
9745 // ignore
9746 }
9747 return;
9748 }
9749 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9750 Pair.create(specifiers, (x) -> {
9751 try {
9752 if (resultCallback != null) {
9753 resultCallback.accept(x);
9754 }
9755 } catch (RemoteException e) {
9756 // ignore
9757 }
9758 });
9759 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9760 } finally {
9761 Binder.restoreCallingIdentity(token);
9762 }
9763 }
9764
9765 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009766 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9767 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009768 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009769 mApp, subId, "getSystemSelectionChannels");
9770 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9771 final long identity = Binder.clearCallingIdentity();
9772 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009773 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9774 if (result instanceof IllegalStateException) {
9775 throw (IllegalStateException) result;
9776 }
9777 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009778 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9779 return specifiers;
9780 } finally {
9781 Binder.restoreCallingIdentity(identity);
9782 }
9783 }
9784
9785 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009786 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009787 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009788 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009789 }
9790
9791 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009792 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9793 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009794 if (callingPackage == null) {
9795 callingPackage = getCurrentPackageName();
9796 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009797 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9798 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009799 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9800 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009801 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9802 }
9803 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9804 Intent intent = new Intent();
9805 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9806 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9807 // Bring up choose default SMS subscription dialog right now
9808 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9809 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9810 mApp.startActivity(intent);
9811 }
chen xud5ca2d52019-05-28 15:20:57 -07009812
9813 @Override
9814 public String getMmsUAProfUrl(int subId) {
9815 //TODO investigate if this API should require proper permission check in R b/133791609
9816 final long identity = Binder.clearCallingIdentity();
9817 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009818 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9819 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9820 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9821 return carrierUAProfUrl;
9822 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009823 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9824 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009825 } finally {
9826 Binder.restoreCallingIdentity(identity);
9827 }
9828 }
9829
9830 @Override
9831 public String getMmsUserAgent(int subId) {
9832 //TODO investigate if this API should require proper permission check in R b/133791609
9833 final long identity = Binder.clearCallingIdentity();
9834 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009835 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9836 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9837 if (!TextUtils.isEmpty(carrierUserAgent)) {
9838 return carrierUserAgent;
9839 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009840 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9841 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009842 } finally {
9843 Binder.restoreCallingIdentity(identity);
9844 }
9845 }
Jack Yub07d4972019-05-28 16:12:25 -07009846
9847 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009848 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9849 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009850
Jack Yub07d4972019-05-28 16:12:25 -07009851 final long identity = Binder.clearCallingIdentity();
9852 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009853 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009854 if (phone == null) return false;
9855
Ling Ma58448e42022-09-16 15:22:36 -07009856 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -07009857 } finally {
9858 Binder.restoreCallingIdentity(identity);
9859 }
9860 }
9861
9862 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009863 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009864 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009865 enforceModifyPermission();
9866
changbettyd5c246e2019-12-24 15:40:37 +08009867 final long identity = Binder.clearCallingIdentity();
9868 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009869 Phone phone = getPhone(subscriptionId);
9870 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009871
Ling Ma58448e42022-09-16 15:22:36 -07009872 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +08009873 } finally {
9874 Binder.restoreCallingIdentity(identity);
9875 }
9876 }
9877
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009878 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009879 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009880 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9881 * otherwise.
9882 */
9883 @Override
9884 public void setCepEnabled(boolean isCepEnabled) {
9885 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9886
9887 final long identity = Binder.clearCallingIdentity();
9888 try {
9889 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9890 for (Phone phone : PhoneFactory.getPhones()) {
9891 Phone defaultPhone = phone.getImsPhone();
9892 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9893 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9894 ImsPhoneCallTracker imsPhoneCallTracker =
9895 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9896 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9897 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9898 + imsPhone.getMsisdn());
9899 }
9900 }
9901 } finally {
9902 Binder.restoreCallingIdentity(identity);
9903 }
9904 }
allenwtsu46dcc572020-01-08 18:24:03 +08009905
9906 /**
9907 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9908 *
9909 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9910 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9911 * before being read.
9912 */
9913 @Override
9914 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9915 isCompressed) {
9916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9917 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009918 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9919 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9920 }
9921 if (!isImsAvailableOnDevice()) {
9922 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9923 "IMS not available on device.");
9924 }
9925
9926 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009927 try {
Hui Wang761a6682020-10-31 05:12:53 +00009928 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9929 } finally {
9930 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009931 }
9932 }
zoey chene02881a2019-12-30 16:11:23 +08009933
9934 @Override
9935 public boolean isIccLockEnabled(int subId) {
9936 enforceReadPrivilegedPermission("isIccLockEnabled");
9937
9938 // Now that all security checks passes, perform the operation as ourselves.
9939 final long identity = Binder.clearCallingIdentity();
9940 try {
9941 Phone phone = getPhone(subId);
9942 if (phone != null && phone.getIccCard() != null) {
9943 return phone.getIccCard().getIccLockEnabled();
9944 } else {
9945 return false;
9946 }
9947 } finally {
9948 Binder.restoreCallingIdentity(identity);
9949 }
9950 }
9951
9952 /**
9953 * Set the ICC pin lock enabled or disabled.
9954 *
9955 * @return an integer representing the status of IccLock enabled or disabled in the following
9956 * three cases:
9957 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9958 * successfully.
9959 * - Positive number and zero for remaining password attempts.
9960 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9961 *
9962 */
9963 @Override
9964 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9965 enforceModifyPermission();
9966
9967 Phone phone = getPhone(subId);
9968 if (phone == null) {
9969 return 0;
9970 }
9971 // Now that all security checks passes, perform the operation as ourselves.
9972 final long identity = Binder.clearCallingIdentity();
9973 try {
9974 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9975 new Pair<Boolean, String>(enabled, password), phone, null);
9976 return attemptsRemaining;
9977
9978 } catch (Exception e) {
9979 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9980 } finally {
9981 Binder.restoreCallingIdentity(identity);
9982 }
9983 return 0;
9984 }
9985
9986 /**
9987 * Change the ICC password used in ICC pin lock.
9988 *
9989 * @return an integer representing the status of IccLock changed in the following three cases:
9990 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9991 * - Positive number and zero for remaining password attempts.
9992 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9993 *
9994 */
9995 @Override
9996 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9997 enforceModifyPermission();
9998
9999 Phone phone = getPhone(subId);
10000 if (phone == null) {
10001 return 0;
10002 }
10003 // Now that all security checks passes, perform the operation as ourselves.
10004 final long identity = Binder.clearCallingIdentity();
10005 try {
10006 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10007 new Pair<String, String>(oldPassword, newPassword), phone, null);
10008 return attemptsRemaining;
10009
10010 } catch (Exception e) {
10011 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10012 } finally {
10013 Binder.restoreCallingIdentity(identity);
10014 }
10015 return 0;
10016 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010017
10018 /**
10019 * Request for receiving user activity notification
10020 */
10021 @Override
10022 public void requestUserActivityNotification() {
10023 if (!mNotifyUserActivity.get()
10024 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10025 mNotifyUserActivity.set(true);
10026 }
10027 }
10028
10029 /**
10030 * Called when userActivity is signalled in the power manager.
10031 * This is safe to call from any thread, with any window manager locks held or not.
10032 */
10033 @Override
10034 public void userActivity() {
10035 // ***************************************
10036 // * Inherited from PhoneWindowManager *
10037 // ***************************************
10038 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10039 // WITH ITS LOCKS HELD.
10040 //
10041 // This code must be VERY careful about the locks
10042 // it acquires.
10043 // In fact, the current code acquires way too many,
10044 // and probably has lurking deadlocks.
10045
10046 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10047 throw new SecurityException("Only the OS may call notifyUserActivity()");
10048 }
10049
10050 if (mNotifyUserActivity.getAndSet(false)) {
10051 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10052 USER_ACTIVITY_NOTIFICATION_DELAY);
10053 }
10054 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010055
10056 @Override
10057 public boolean canConnectTo5GInDsdsMode() {
10058 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10059 }
Jack Yud10cdd42020-09-28 20:28:01 -070010060
10061 @Override
10062 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10063 String callingFeatureId) {
10064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10065 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10066 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10067 }
10068
10069 Phone phone = getPhone(subId);
10070 if (phone == null) {
10071 throw new RuntimeException("phone is not available");
10072 }
10073 // Now that all security checks passes, perform the operation as ourselves.
10074 final long identity = Binder.clearCallingIdentity();
10075 try {
10076 return phone.getEquivalentHomePlmns();
10077 } finally {
10078 Binder.restoreCallingIdentity(identity);
10079 }
10080 }
Daniel Bright59e67312020-11-13 11:49:37 -080010081
10082 @Override
10083 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010084 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10085 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010086 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010087 if (radioInterfaceCapabilities == null) {
10088 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010089 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010090 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010091 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010092
Hui Wang641e81c2020-10-12 12:14:23 -070010093 @Override
10094 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10095 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010096 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10097 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10098 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10099 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10100 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010101 if (DBG) {
10102 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10103 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10104 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10105 }
10106
10107 if (!SubscriptionManager.isValidSubscriptionId(subId)
10108 || appType < TelephonyManager.APPTYPE_UNKNOWN
10109 || appType > TelephonyManager.APPTYPE_ISIM
10110 || nafUrl == null || securityProtocol == null || callback == null) {
10111 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10112 if (callback != null) {
10113 try {
10114 callback.onAuthenticationFailure(
10115 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10116 } catch (RemoteException exception) {
10117 log("Fail to notify onAuthenticationFailure due to " + exception);
10118 }
10119 return;
10120 }
10121 }
10122
10123 final long token = Binder.clearCallingIdentity();
10124 try {
10125 getGbaManager(subId).bootstrapAuthenticationRequest(
10126 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10127 forceBootStrapping, callback));
10128 } finally {
10129 Binder.restoreCallingIdentity(token);
10130 }
10131 }
10132
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010133 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010134 * Attempts to set the radio power state for all phones for thermal reason.
10135 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010136 * requested radio power state will actually be set. See {@link
10137 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10138 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010139 * @param enable {@code true} if trying to turn radio on.
10140 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10141 * false}.
10142 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010143 private boolean setRadioPowerForThermal(boolean enable) {
10144 boolean isPhoneAvailable = false;
10145 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10146 Phone phone = PhoneFactory.getPhone(i);
10147 if (phone != null) {
10148 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10149 isPhoneAvailable = true;
10150 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010151 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010152
10153 // return true if successfully informed the phone object about the thermal radio power
10154 // request.
10155 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010156 }
10157
10158 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010159 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010160 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10161 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10162 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10163 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10164 throw new IllegalArgumentException("modem does not support data throttling");
10165 }
10166
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010167 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10168 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010169 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010170 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10171 }
10172
Sarah Chinecc78c42022-03-31 21:16:48 -070010173 setDataEnabledForReason(
10174 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010175
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010176 if (isDataThrottlingSupported) {
10177 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010178 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010179 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10180 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10181 } else if (thermalMitigationResult
10182 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010183 log("Modem likely does not support data throttling on secondary carrier. Data " +
10184 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10185 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010186 }
10187 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010188 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010189
10190 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010191 }
10192
Jack Nudelman644b91a2021-03-12 14:09:48 -080010193 private static List<String> getThermalMitigationAllowlist(Context context) {
10194 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10195 for (String pckg : context.getResources()
10196 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10197 sThermalMitigationAllowlistedPackages.add(pckg);
10198 }
10199 }
10200
10201 return sThermalMitigationAllowlistedPackages;
10202 }
10203
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010204 private boolean isAnyPhoneInEmergencyState() {
10205 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10206 if (tm.isInEmergencyCall()) {
10207 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10208 return true;
10209 }
10210 for (Phone phone : PhoneFactory.getPhones()) {
10211 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10212 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10213 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10214 + phone.isInEcm());
10215 return true;
10216 }
10217 }
10218
10219 return false;
10220 }
10221
Jack Nudelman644b91a2021-03-12 14:09:48 -080010222 /**
10223 * Used by shell commands to add an authorized package name for thermal mitigation.
10224 * @param packageName name of package to be allowlisted
10225 * @param context
10226 */
10227 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10228 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10229 sThermalMitigationAllowlistedPackages.add(packageName);
10230 }
10231
10232 /**
10233 * Used by shell commands to remove an authorized package name for thermal mitigation.
10234 * @param packageName name of package to remove from allowlist
10235 * @param context
10236 */
10237 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10238 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10239 sThermalMitigationAllowlistedPackages.remove(packageName);
10240 }
10241
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010242 /**
10243 * Thermal mitigation request to control functionalities at modem.
10244 *
10245 * @param subId the id of the subscription.
10246 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010247 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010248 *
10249 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10250 */
10251 @Override
10252 @ThermalMitigationResult
10253 public int sendThermalMitigationRequest(
10254 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010255 ThermalMitigationRequest thermalMitigationRequest,
10256 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010257 enforceModifyPermission();
10258
Jack Nudelman644b91a2021-03-12 14:09:48 -080010259 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10260 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10261 .contains(callingPackage)) {
10262 throw new SecurityException("Calling package must be configured in the device config. "
10263 + "calling package: " + callingPackage);
10264 }
10265
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010266 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10267 final long identity = Binder.clearCallingIdentity();
10268
10269 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10270 try {
10271 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10272 switch (thermalMitigationAction) {
10273 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10274 thermalMitigationResult =
10275 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010276 thermalMitigationRequest.getDataThrottlingRequest(),
10277 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010278 break;
10279 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10280 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10281 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10282 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10283 }
10284
10285 // Ensure that radio is on. If not able to power on due to phone being
10286 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010287 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010288 thermalMitigationResult =
10289 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10290 break;
10291 }
10292
10293 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010294 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010295 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10296 break;
10297 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10298 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10299 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10300 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10301 }
10302
10303 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10304 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010305 Phone phone = getPhone(subId);
10306 if (phone == null) {
10307 thermalMitigationResult =
10308 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10309 break;
10310 }
10311
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010312 TelephonyConnectionService service =
10313 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010314 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010315 Log.e(LOG_TAG, "An emergency call is pending");
10316 thermalMitigationResult =
10317 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10318 break;
10319 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010320 thermalMitigationResult =
10321 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10322 break;
10323 }
10324 } else {
10325 thermalMitigationResult =
10326 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10327 break;
10328 }
10329
10330 // Turn radio off. If not able to power off due to phone being unavailable,
10331 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010332 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010333 thermalMitigationResult =
10334 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10335 break;
10336 }
10337 thermalMitigationResult =
10338 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10339 break;
10340 default:
10341 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10342 + "not exist. Requested action: " + thermalMitigationAction);
10343 }
10344 } catch (IllegalArgumentException e) {
10345 throw e;
10346 } catch (Exception e) {
10347 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10348 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10349 } finally {
10350 Binder.restoreCallingIdentity(identity);
10351 }
10352
10353 if (DBG) {
10354 log("thermalMitigationRequest returning with thermalMitigationResult: "
10355 + thermalMitigationResult);
10356 }
10357
10358 return thermalMitigationResult;
10359 }
Hui Wang641e81c2020-10-12 12:14:23 -070010360
10361 /**
10362 * Set the GbaService Package Name that Telephony will bind to.
10363 *
10364 * @param subId The sim that the GbaService is associated with.
10365 * @param packageName The name of the package to be replaced with.
10366 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10367 */
10368 @Override
10369 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10370 enforceModifyPermission();
10371
10372 final long identity = Binder.clearCallingIdentity();
10373 try {
10374 return getGbaManager(subId).overrideServicePackage(packageName);
10375 } finally {
10376 Binder.restoreCallingIdentity(identity);
10377 }
10378 }
10379
10380 /**
10381 * Return the package name of the currently bound GbaService.
10382 *
10383 * @param subId The sim that the GbaService is associated with.
10384 * @return the package name of the GbaService configuration, null if GBA is not supported.
10385 */
10386 @Override
10387 public String getBoundGbaService(int subId) {
10388 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10389
10390 final long identity = Binder.clearCallingIdentity();
10391 try {
10392 return getGbaManager(subId).getServicePackage();
10393 } finally {
10394 Binder.restoreCallingIdentity(identity);
10395 }
10396 }
10397
10398 /**
10399 * Set the release time for telephony to unbind GbaService.
10400 *
10401 * @param subId The sim that the GbaService is associated with.
10402 * @param interval The release time to unbind GbaService by millisecond.
10403 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10404 */
10405 @Override
10406 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10407 enforceModifyPermission();
10408
10409 final long identity = Binder.clearCallingIdentity();
10410 try {
10411 return getGbaManager(subId).overrideReleaseTime(interval);
10412 } finally {
10413 Binder.restoreCallingIdentity(identity);
10414 }
10415 }
10416
10417 /**
10418 * Return the release time for telephony to unbind GbaService.
10419 *
10420 * @param subId The sim that the GbaService is associated with.
10421 * @return The release time to unbind GbaService by millisecond.
10422 */
10423 @Override
10424 public int getGbaReleaseTime(int subId) {
10425 enforceReadPrivilegedPermission("getGbaReleaseTime");
10426
10427 final long identity = Binder.clearCallingIdentity();
10428 try {
10429 return getGbaManager(subId).getReleaseTime();
10430 } finally {
10431 Binder.restoreCallingIdentity(identity);
10432 }
10433 }
10434
10435 private GbaManager getGbaManager(int subId) {
10436 GbaManager instance = GbaManager.getInstance(subId);
10437 if (instance == null) {
10438 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10439 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10440 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10441 }
10442 return instance;
10443 }
Hui Wang761a6682020-10-31 05:12:53 +000010444
10445 /**
10446 * indicate whether the device and the carrier can support
10447 * RCS VoLTE single registration.
10448 */
10449 @Override
10450 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010451 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10452 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10453 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10454 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010455
10456 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10457 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10458 }
10459
10460 final long identity = Binder.clearCallingIdentity();
10461 try {
10462 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10463 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010464 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10465 if (isCapable != null) {
10466 return isCapable;
10467 }
Hui Wang761a6682020-10-31 05:12:53 +000010468 }
Hui Wang67af90e2021-06-04 16:57:15 -070010469 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10470 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010471 } finally {
10472 Binder.restoreCallingIdentity(identity);
10473 }
10474 }
10475
10476 /**
10477 * Register RCS provisioning callback.
10478 */
10479 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010480 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010481 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010482 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010483 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010484 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10485 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010486
10487 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10488 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10489 }
10490 if (!isImsAvailableOnDevice()) {
10491 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10492 "IMS not available on device.");
10493 }
10494
10495 final long identity = Binder.clearCallingIdentity();
10496 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010497 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010498 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010499 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10500 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010501 }
Hui Wang761a6682020-10-31 05:12:53 +000010502 } finally {
10503 Binder.restoreCallingIdentity(identity);
10504 }
10505 }
10506
10507 /**
10508 * Unregister RCS provisioning callback.
10509 */
10510 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010511 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010512 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010513 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010514 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010515 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10516 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010517
10518 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10519 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10520 }
10521 if (!isImsAvailableOnDevice()) {
10522 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10523 "IMS not available on device.");
10524 }
10525
10526 final long identity = Binder.clearCallingIdentity();
10527 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010528 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010529 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010530 } finally {
10531 Binder.restoreCallingIdentity(identity);
10532 }
10533 }
10534
10535 /**
10536 * trigger RCS reconfiguration.
10537 */
10538 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010539 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10540 "triggerRcsReconfiguration",
10541 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010542
10543 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10544 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10545 }
10546 if (!isImsAvailableOnDevice()) {
10547 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10548 "IMS not available on device.");
10549 }
10550
10551 final long identity = Binder.clearCallingIdentity();
10552 try {
10553 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10554 } finally {
10555 Binder.restoreCallingIdentity(identity);
10556 }
10557 }
10558
10559 /**
10560 * Provide the client configuration parameters of the RCS application.
10561 */
10562 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010563 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10564 "setRcsClientConfiguration",
10565 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010566
10567 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10568 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10569 }
10570 if (!isImsAvailableOnDevice()) {
10571 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10572 "IMS not available on device.");
10573 }
10574
10575 final long identity = Binder.clearCallingIdentity();
10576
10577 try {
10578 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10579 if (configBinder == null) {
10580 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010581 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10582 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010583 } else {
10584 configBinder.setRcsClientConfiguration(rcc);
10585 }
joonhunshin3e154242021-09-17 06:33:39 +000010586
10587 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10588 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010589 } catch (RemoteException e) {
10590 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010591 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10592 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010593 } finally {
10594 Binder.restoreCallingIdentity(identity);
10595 }
10596 }
10597
10598 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010599 * Enables or disables the test mode for RCS VoLTE single registration.
10600 */
10601 @Override
10602 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10603 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10604 "setRcsSingleRegistrationTestModeEnabled");
10605
10606 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10607 }
10608
10609 /**
10610 * Gets the test mode for RCS VoLTE single registration.
10611 */
10612 @Override
10613 public boolean getRcsSingleRegistrationTestModeEnabled() {
10614 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10615 "getRcsSingleRegistrationTestModeEnabled");
10616
10617 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10618 }
10619
10620 /**
Hui Wang761a6682020-10-31 05:12:53 +000010621 * Overrides the config of RCS VoLTE single registration enabled for the device.
10622 */
10623 @Override
10624 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10625 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10626 "setDeviceSingleRegistrationEnabledOverride");
10627 enforceModifyPermission();
10628
10629 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10630 : Boolean.parseBoolean(enabledStr);
10631 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010632 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010633 }
10634
10635 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010636 * Sends a device to device communication message. Only usable via shell.
10637 * @param message message to send.
10638 * @param value message value.
10639 */
10640 @Override
10641 public void sendDeviceToDeviceMessage(int message, int value) {
10642 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010643 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010644 enforceModifyPermission();
10645
10646 final long identity = Binder.clearCallingIdentity();
10647 try {
10648 TelephonyConnectionService service =
10649 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10650 if (service == null) {
10651 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10652 return;
10653 }
10654 service.sendTestDeviceToDeviceMessage(message, value);
10655 } finally {
10656 Binder.restoreCallingIdentity(identity);
10657 }
10658 }
10659
Tyler Gunnbabbda02021-02-10 11:05:02 -080010660 /**
10661 * Sets the specified device to device transport active.
10662 * @param transport The transport to set active.
10663 */
10664 @Override
10665 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10666 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10667 "setActiveDeviceToDeviceTransport");
10668 enforceModifyPermission();
10669
10670 final long identity = Binder.clearCallingIdentity();
10671 try {
10672 TelephonyConnectionService service =
10673 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10674 if (service == null) {
10675 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10676 return;
10677 }
10678 service.setActiveDeviceToDeviceTransport(transport);
10679 } finally {
10680 Binder.restoreCallingIdentity(identity);
10681 }
10682 }
Tyler Gunn92479152021-01-20 16:30:10 -080010683
Tyler Gunnd4339262021-05-03 14:46:49 -070010684 @Override
10685 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10686 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10687 "setDeviceToDeviceForceEnabled");
10688
10689 final long identity = Binder.clearCallingIdentity();
10690 try {
10691 Arrays.stream(PhoneFactory.getPhones()).forEach(
10692 p -> {
10693 Phone thePhone = p.getImsPhone();
10694 if (thePhone != null && thePhone instanceof ImsPhone) {
10695 ImsPhone imsPhone = (ImsPhone) thePhone;
10696 CallTracker tracker = imsPhone.getCallTracker();
10697 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10698 ImsPhoneCallTracker imsPhoneCallTracker =
10699 (ImsPhoneCallTracker) tracker;
10700 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10701 }
10702 }
10703 }
10704 );
10705 } finally {
10706 Binder.restoreCallingIdentity(identity);
10707 }
10708 }
10709
Tyler Gunn92479152021-01-20 16:30:10 -080010710 /**
Hui Wang761a6682020-10-31 05:12:53 +000010711 * Gets the config of RCS VoLTE single registration enabled for the device.
10712 */
10713 @Override
10714 public boolean getDeviceSingleRegistrationEnabled() {
10715 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10716 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10717 }
10718
10719 /**
10720 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10721 */
10722 @Override
10723 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10724 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10725 "setCarrierSingleRegistrationEnabledOverride");
10726 enforceModifyPermission();
10727
10728 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10729 : Boolean.parseBoolean(enabledStr);
10730 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10731 subId, enabled);
10732 }
10733
10734 /**
10735 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10736 */
10737 @Override
10738 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10739 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10740 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10741 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010742
10743 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010744 * Overrides the ims feature validation result
10745 */
10746 @Override
10747 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10748 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10749 "setImsFeatureValidationOverride");
10750
10751 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10752 : Boolean.parseBoolean(enabledStr);
10753 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10754 subId, enabled);
10755 }
10756
10757 /**
10758 * Gets the ims feature validation override value
10759 */
10760 @Override
10761 public boolean getImsFeatureValidationOverride(int subId) {
10762 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10763 "getImsFeatureValidationOverride");
10764 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10765 }
10766
10767 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010768 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10769 * their mobile plan.
10770 */
10771 @Override
10772 public String getMobileProvisioningUrl() {
10773 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10774 final long identity = Binder.clearCallingIdentity();
10775 try {
10776 return getDefaultPhone().getMobileProvisioningUrl();
10777 } finally {
10778 Binder.restoreCallingIdentity(identity);
10779 }
10780 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010781
James.cf Linbcdf8b32021-01-14 16:44:13 +080010782 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010783 * Get the EAB contact from the EAB database.
10784 */
10785 @Override
10786 public String getContactFromEab(String contact) {
10787 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10788 enforceModifyPermission();
10789 final long identity = Binder.clearCallingIdentity();
10790 try {
10791 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10792 } finally {
10793 Binder.restoreCallingIdentity(identity);
10794 }
10795 }
10796
10797 /**
Calvin Pana1434322021-07-01 19:27:01 +080010798 * Get the EAB capability from the EAB database.
10799 */
10800 @Override
10801 public String getCapabilityFromEab(String contact) {
10802 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10803 enforceModifyPermission();
10804 final long identity = Binder.clearCallingIdentity();
10805 try {
10806 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10807 } finally {
10808 Binder.restoreCallingIdentity(identity);
10809 }
10810 }
10811
10812 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010813 * Remove the EAB contacts from the EAB database.
10814 */
10815 @Override
10816 public int removeContactFromEab(int subId, String contacts) {
10817 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10818 enforceModifyPermission();
10819 final long identity = Binder.clearCallingIdentity();
10820 try {
10821 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10822 } finally {
10823 Binder.restoreCallingIdentity(identity);
10824 }
10825 }
10826
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010827 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010828 public boolean getDeviceUceEnabled() {
10829 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10830 final long identity = Binder.clearCallingIdentity();
10831 try {
10832 return mApp.getDeviceUceEnabled();
10833 } finally {
10834 Binder.restoreCallingIdentity(identity);
10835 }
10836 }
10837
10838 @Override
10839 public void setDeviceUceEnabled(boolean isEnabled) {
10840 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10841 final long identity = Binder.clearCallingIdentity();
10842 try {
10843 mApp.setDeviceUceEnabled(isEnabled);
10844 } finally {
10845 Binder.restoreCallingIdentity(identity);
10846 }
10847 }
10848
Brad Ebinger14d467f2021-02-12 06:18:28 +000010849 /**
10850 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10851 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10852 */
10853 // Used for SHELL command only right now.
10854 @Override
10855 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10856 List<String> featureTags) {
10857 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10858 "addUceRegistrationOverrideShell");
10859 final long identity = Binder.clearCallingIdentity();
10860 try {
10861 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10862 new ArraySet<>(featureTags));
10863 } catch (ImsException e) {
10864 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10865 } finally {
10866 Binder.restoreCallingIdentity(identity);
10867 }
10868 }
10869
10870 /**
10871 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10872 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10873 */
10874 // Used for SHELL command only right now.
10875 @Override
10876 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10877 List<String> featureTags) {
10878 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10879 "removeUceRegistrationOverrideShell");
10880 final long identity = Binder.clearCallingIdentity();
10881 try {
10882 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10883 new ArraySet<>(featureTags));
10884 } catch (ImsException e) {
10885 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10886 } finally {
10887 Binder.restoreCallingIdentity(identity);
10888 }
10889 }
10890
10891 /**
10892 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10893 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10894 */
10895 // Used for SHELL command only right now.
10896 @Override
10897 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10898 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10899 "clearUceRegistrationOverrideShell");
10900 final long identity = Binder.clearCallingIdentity();
10901 try {
10902 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10903 } catch (ImsException e) {
10904 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10905 } finally {
10906 Binder.restoreCallingIdentity(identity);
10907 }
10908 }
10909
10910 /**
10911 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10912 */
10913 // Used for SHELL command only right now.
10914 @Override
10915 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10916 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10917 "getLatestRcsContactUceCapabilityShell");
10918 final long identity = Binder.clearCallingIdentity();
10919 try {
10920 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10921 } catch (ImsException e) {
10922 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10923 } finally {
10924 Binder.restoreCallingIdentity(identity);
10925 }
10926 }
10927
10928 /**
10929 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10930 * device does not have an active PUBLISH.
10931 */
10932 // Used for SHELL command only right now.
10933 @Override
10934 public String getLastUcePidfXmlShell(int subId) {
10935 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10936 final long identity = Binder.clearCallingIdentity();
10937 try {
10938 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10939 } catch (ImsException e) {
10940 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10941 } finally {
10942 Binder.restoreCallingIdentity(identity);
10943 }
10944 }
10945
James.cf Line8713a42021-04-29 16:04:26 +080010946 /**
10947 * Remove UCE requests cannot be sent to the network status.
10948 */
10949 // Used for SHELL command only right now.
10950 @Override
10951 public boolean removeUceRequestDisallowedStatus(int subId) {
10952 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10953 final long identity = Binder.clearCallingIdentity();
10954 try {
10955 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10956 } catch (ImsException e) {
10957 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10958 } finally {
10959 Binder.restoreCallingIdentity(identity);
10960 }
10961 }
10962
James.cf Lin18bb9002021-05-25 01:37:38 +080010963 /**
10964 * Remove UCE requests cannot be sent to the network status.
10965 */
10966 // Used for SHELL command only.
10967 @Override
10968 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10969 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10970 final long identity = Binder.clearCallingIdentity();
10971 try {
10972 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10973 } catch (ImsException e) {
10974 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10975 } finally {
10976 Binder.restoreCallingIdentity(identity);
10977 }
10978 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010979
James.cf Lin4b784aa2021-01-31 03:25:15 +080010980 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010981 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10982 String callingPackage) {
10983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10984 mApp, subId, "setSignalStrengthUpdateRequest");
10985
10986 final int callingUid = Binder.getCallingUid();
10987 // Verify that tha callingPackage belongs to the calling UID
10988 mApp.getSystemService(AppOpsManager.class)
10989 .checkPackage(callingUid, callingPackage);
10990
Rambo Wang3607f502021-02-01 21:51:40 -080010991 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010992
10993 final long identity = Binder.clearCallingIdentity();
10994 try {
10995 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10996 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10997
10998 if (result instanceof IllegalStateException) {
10999 throw (IllegalStateException) result;
11000 }
11001 } finally {
11002 Binder.restoreCallingIdentity(identity);
11003 }
11004 }
11005
11006 @Override
11007 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11008 String callingPackage) {
11009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11010 mApp, subId, "clearSignalStrengthUpdateRequest");
11011
11012 final int callingUid = Binder.getCallingUid();
11013 // Verify that tha callingPackage belongs to the calling UID
11014 mApp.getSystemService(AppOpsManager.class)
11015 .checkPackage(callingUid, callingPackage);
11016
11017 final long identity = Binder.clearCallingIdentity();
11018 try {
11019 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11020 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11021
11022 if (result instanceof IllegalStateException) {
11023 throw (IllegalStateException) result;
11024 }
11025 } finally {
11026 Binder.restoreCallingIdentity(identity);
11027 }
11028 }
11029
Rambo Wang3607f502021-02-01 21:51:40 -080011030 private static void validateSignalStrengthUpdateRequest(Context context,
11031 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011032 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11033 // phone/system process do not have further restriction on request
11034 return;
11035 }
11036
11037 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011038 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011039 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011040 context.enforceCallingOrSelfPermission(
11041 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11042 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011043 }
11044
11045 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11046 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11047 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11048 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11049 || info.isEnabled()) {
11050 throw new IllegalArgumentException(
11051 "Only system can set hide fields in SignalThresholdInfo");
11052 }
11053
11054 // Thresholds length for each RAN need in range. This has been validated in
11055 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11056 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11057 final int[] thresholds = info.getThresholds();
11058 Objects.requireNonNull(thresholds);
11059 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11060 || thresholds.length
11061 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11062 throw new IllegalArgumentException(
11063 "thresholds length is out of range: " + thresholds.length);
11064 }
11065 }
11066 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011067
11068 /**
11069 * Gets the current phone capability.
11070 *
11071 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11072 * @return the PhoneCapability which describes the data connection capability of modem.
11073 * It's used to evaluate possible phone config change, for example from single
11074 * SIM device to multi-SIM device.
11075 */
11076 @Override
11077 public PhoneCapability getPhoneCapability() {
11078 enforceReadPrivilegedPermission("getPhoneCapability");
11079 final long identity = Binder.clearCallingIdentity();
11080 try {
11081 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11082 } finally {
11083 Binder.restoreCallingIdentity(identity);
11084 }
11085 }
Michele Berionne5e411512020-11-13 02:36:59 +000011086
11087 /**
11088 * Prepare TelephonyManager for an unattended reboot. The reboot is
11089 * required to be done shortly after the API is invoked.
11090 */
11091 @Override
11092 @TelephonyManager.PrepareUnattendedRebootResult
11093 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011094 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011095 enforceRebootPermission();
11096
11097 final long identity = Binder.clearCallingIdentity();
11098 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011099 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011100 } finally {
11101 Binder.restoreCallingIdentity(identity);
11102 }
11103 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011104
11105 /**
11106 * Request to get the current slicing configuration including URSP rules and
11107 * NSSAIs (configured, allowed and rejected).
11108 *
11109 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11110 */
11111 @Override
11112 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011113 TelephonyPermissions
11114 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11115 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011116
11117 final long identity = Binder.clearCallingIdentity();
11118 try {
11119 Phone phone = getDefaultPhone();
11120 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11121 } finally {
11122 Binder.restoreCallingIdentity(identity);
11123 }
11124 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011125
11126 /**
11127 * Register an IMS connection state callback
11128 */
11129 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011130 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11131 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011132 if (feature == ImsFeature.FEATURE_MMTEL) {
11133 // ImsMmTelManager
11134 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11135 TelephonyPermissions
11136 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11137 mApp, subId, "registerImsStateCallback");
11138 } else if (feature == ImsFeature.FEATURE_RCS) {
11139 // ImsRcsManager or SipDelegateManager
11140 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11141 Binder.getCallingUid(), "registerImsStateCallback",
11142 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11143 Manifest.permission.READ_PRECISE_PHONE_STATE,
11144 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11145 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11146 }
11147
11148 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11149 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11150 "IMS not available on device.");
11151 }
11152
11153 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11154 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11155 }
11156
11157 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11158 if (controller == null) {
11159 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11160 "IMS not available on device.");
11161 }
11162
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011163 if (callingPackage == null) {
11164 callingPackage = getCurrentPackageName();
11165 }
11166
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011167 final long token = Binder.clearCallingIdentity();
11168 try {
11169 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011170 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011171 } catch (ImsException e) {
11172 throw new ServiceSpecificException(e.getCode());
11173 } finally {
11174 Binder.restoreCallingIdentity(token);
11175 }
11176 }
11177
11178 /**
11179 * Unregister an IMS connection state callback
11180 */
11181 @Override
11182 public void unregisterImsStateCallback(IImsStateCallback cb) {
11183 final long token = Binder.clearCallingIdentity();
11184 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11185 if (controller == null) {
11186 return;
11187 }
11188 try {
11189 controller.unregisterImsStateCallback(cb);
11190 } finally {
11191 Binder.restoreCallingIdentity(token);
11192 }
11193 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011194
11195 /**
11196 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11197 *
11198 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11199 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11200 * SecurityException.
11201 * If there is current registered network this value will be same as the registered cell
11202 * identity. If the device goes out of service the previous cell identity is cached and
11203 * will be returned. If the cache age of the Cell identity is more than 24 hours
11204 * it will be cleared and null will be returned.
11205 *
11206 */
11207 @Override
11208 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11209 String callingFeatureId) {
11210 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11211 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11212 LocationAccessPolicy.checkLocationPermission(mApp,
11213 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11214 .setCallingPackage(callingPackage)
11215 .setCallingFeatureId(callingFeatureId)
11216 .setCallingPid(Binder.getCallingPid())
11217 .setCallingUid(Binder.getCallingUid())
11218 .setMethod("getLastKnownCellIdentity")
11219 .setLogAsInfo(true)
11220 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11221 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11222 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11223 .build());
11224
11225 boolean hasFinePermission =
11226 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11227 if (!hasFinePermission
11228 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11229 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011230 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011231 }
11232
11233 final long identity = Binder.clearCallingIdentity();
11234 try {
11235 Phone phone = getPhone(subId);
11236 if (phone == null) return null;
11237 ServiceStateTracker sst = phone.getServiceStateTracker();
11238 if (sst == null) return null;
11239 return sst.getLastKnownCellIdentity();
11240 } finally {
11241 Binder.restoreCallingIdentity(identity);
11242 }
11243 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011244
jimsun3b9ccac2021-10-26 15:01:23 +080011245 /**
11246 * Sets the modem service class Name that Telephony will bind to.
11247 *
11248 * @param serviceName The class name of the modem service.
11249 * @return true if the operation is succeed, otherwise false.
11250 */
11251 public boolean setModemService(String serviceName) {
11252 Log.d(LOG_TAG, "setModemService - " + serviceName);
11253 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11255 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11256 "setModemService");
11257 return mPhoneConfigurationManager.setModemService(serviceName);
11258 }
11259
11260 /**
11261 * Return the class name of the currently bounded modem service.
11262 *
11263 * @return the class name of the modem service.
11264 */
11265 public String getModemService() {
11266 String result;
11267 Log.d(LOG_TAG, "getModemService");
11268 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11269 TelephonyPermissions
11270 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11271 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11272 "getModemService");
11273 result = mPhoneConfigurationManager.getModemService();
11274 Log.d(LOG_TAG, "result = " + result);
11275 return result;
11276 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011277
11278 @Override
11279 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11280 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11281 mApp.enforceCallingOrSelfPermission(
11282 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11283 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11284
11285 final long identity = Binder.clearCallingIdentity();
11286 try {
11287 Phone phone = getPhone(subId);
11288 if (phone == null) return;
11289 phone.setVoiceServiceStateOverride(hasService);
11290 } finally {
11291 Binder.restoreCallingIdentity(identity);
11292 }
11293 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011294
11295 /**
11296 * set removable eSIM as default eUICC.
11297 *
11298 * @hide
11299 */
11300 @Override
11301 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11302 enforceModifyPermission();
11303 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11304
11305 final long identity = Binder.clearCallingIdentity();
11306 try {
11307 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11308 } finally {
11309 Binder.restoreCallingIdentity(identity);
11310 }
11311 }
11312
11313 /**
11314 * Returns whether the removable eSIM is default eUICC or not.
11315 *
11316 * @hide
11317 */
11318 @Override
11319 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11320 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11321 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11322
11323 final long identity = Binder.clearCallingIdentity();
11324 try {
11325 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11326 } finally {
11327 Binder.restoreCallingIdentity(identity);
11328 }
11329 }
11330
Ryan Savitskicab25c52023-03-14 14:23:49 +000011331 /**
11332 * Get the SIM state for the slot index.
11333 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11334 *
11335 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11336 */
11337 @Override
11338 @SimState
11339 public int getSimStateForSlotIndex(int slotIndex) {
11340 IccCardConstants.State simState;
11341 if (slotIndex < 0) {
11342 simState = IccCardConstants.State.UNKNOWN;
11343 } else {
11344 Phone phone = null;
11345 try {
11346 phone = PhoneFactory.getPhone(slotIndex);
11347 } catch (IllegalStateException e) {
11348 // ignore
11349 }
11350 if (phone == null) {
11351 simState = IccCardConstants.State.UNKNOWN;
11352 } else {
11353 IccCard icc = phone.getIccCard();
11354 if (icc == null) {
11355 simState = IccCardConstants.State.UNKNOWN;
11356 } else {
11357 simState = icc.getState();
11358 }
11359 }
11360 }
11361 return simState.ordinal();
11362 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011363}