blob: d05619ffb2e297cc87a8609d59ebc7eb957334e2 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070034import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000035import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080036import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080053import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.Looper;
55import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080057import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070058import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070059import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080060import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080061import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070062import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070063import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080064import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070066import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070067import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070068import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070069import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080070import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070071import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090072import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080073import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080074import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070075import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080076import android.telephony.AccessNetworkConstants;
77import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070078import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070079import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080080import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080081import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070082import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080083import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070084import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080085import android.telephony.CellIdentityCdma;
86import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070088import android.telephony.CellInfoGsm;
89import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070090import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080091import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070092import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070093import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070094import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080095import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070096import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080097import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070098import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080099import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800100import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700101import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800102import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800104import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800105import android.telephony.SignalStrengthUpdateRequest;
106import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800107import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800109import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700110import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700111import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800112import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800113import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800114import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000115import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000116import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000117import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700118import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700119import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800120import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800121import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700122import android.telephony.gba.GbaAuthRequest;
123import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700124import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800125import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000126import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000127import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700128import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000129import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700130import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800131import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700132import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800133import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700134import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000135import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700136import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800137import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800138import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800140import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700141import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800143import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800144
Andrew Lee312e8172014-10-23 17:01:36 -0700145import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800146import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800147import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800148import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800149import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700150import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700151import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700152import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800153import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800154import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700155import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700156import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800157import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700158import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800159import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800160import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800161import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700162import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000163import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800165import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800167import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800168import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700170import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700171import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700173import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800174import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700175import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700176import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700177import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700178import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800179import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800180import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700181import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700182import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700183import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800184import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800185import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800186import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700187import com.android.internal.telephony.data.DataUtils;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700188import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800189import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700190import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800191import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700192import com.android.internal.telephony.imsphone.ImsPhone;
193import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000194import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800195import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700196import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700197import com.android.internal.telephony.uicc.IccIoResult;
198import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700200import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000203import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800204import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000205import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800206import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700207import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700208import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800209import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800210import com.android.phone.callcomposer.CallComposerPictureManager;
211import com.android.phone.callcomposer.CallComposerPictureTransfer;
212import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700213import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700214import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800215import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700216import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700217import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800218import com.android.services.telephony.TelecomAccountRegistry;
219import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800220import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800221
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700223import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.io.IOException;
225import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700226import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800228import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000229import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800230import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800231import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800232import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800233import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100234import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800235import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700236import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800237import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800238import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800239import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800240import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800241import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242
243/**
244 * Implementation of the ITelephony interface.
245 */
Santos Cordon117fee72014-05-16 17:56:12 -0700246public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247 private static final String LOG_TAG = "PhoneInterfaceManager";
248 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
249 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800250 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251
252 // Message codes used with mMainThreadHandler
253 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700254 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
255 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700256 private static final int CMD_OPEN_CHANNEL = 9;
257 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
258 private static final int CMD_CLOSE_CHANNEL = 11;
259 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800260 private static final int CMD_NV_READ_ITEM = 13;
261 private static final int EVENT_NV_READ_ITEM_DONE = 14;
262 private static final int CMD_NV_WRITE_ITEM = 15;
263 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
264 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
265 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700266 private static final int CMD_RESET_MODEM_CONFIG = 19;
267 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800268 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
269 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800270 private static final int CMD_SEND_ENVELOPE = 25;
271 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000272 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
273 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700274 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
275 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
276 private static final int CMD_EXCHANGE_SIM_IO = 31;
277 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800278 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
279 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700280 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
281 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700282 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
283 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700284 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
285 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
286 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
287 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700288 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
289 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
290 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
291 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700292 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800293 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
294 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000295 private static final int CMD_SWITCH_SLOTS = 50;
296 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700297 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
298 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
299 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
300 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
301 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
302 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
303 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
304 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700305 private static final int CMD_GET_ALL_CELL_INFO = 60;
306 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
307 private static final int CMD_GET_CELL_LOCATION = 62;
308 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700309 private static final int CMD_MODEM_REBOOT = 64;
310 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700311 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
312 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800313 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
314 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700315 private static final int CMD_GET_MODEM_STATUS = 70;
316 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700317 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
318 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700319 private static final int CMD_ERASE_MODEM_CONFIG = 74;
320 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800321 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
322 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
323 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
324 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800325 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
326 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800327 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800328 private static final int CMD_GET_CALL_FORWARDING = 83;
329 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
330 private static final int CMD_SET_CALL_FORWARDING = 85;
331 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
332 private static final int CMD_GET_CALL_WAITING = 87;
333 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
334 private static final int CMD_SET_CALL_WAITING = 89;
335 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700336 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
337 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
338 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
339 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700340 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
341 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800342 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
343 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800344 private static final int CMD_SET_DATA_THROTTLING = 99;
345 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800346 private static final int CMD_SET_SIM_POWER = 101;
347 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800348 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
349 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
350 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
351 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800352 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
353 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000354 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800355 private static final int CMD_GET_SLICING_CONFIG = 110;
356 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800357 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700358 private static final int CMD_ENABLE_VONR = 113;
359 private static final int EVENT_ENABLE_VONR_DONE = 114;
360 private static final int CMD_IS_VONR_ENABLED = 115;
361 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800363 // Parameters of select command.
364 private static final int SELECT_COMMAND = 0xA4;
365 private static final int SELECT_P1 = 0x04;
366 private static final int SELECT_P2 = 0;
367 private static final int SELECT_P3 = 0x10;
368
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 /** The singleton instance. */
370 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800371 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
Wink Saville3ab207e2014-11-20 13:07:20 -0800373 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800375 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700376 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700378 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800379 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800380 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800381 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700382 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800383 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000384 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385
Peter Wangdafb9ac2020-01-15 14:13:38 -0800386 /** User Activity */
387 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800388 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
389
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700390 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
391
Derek Tan97ebb422014-09-05 16:55:38 -0700392 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
393 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800394 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800395 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700396
Michelecea4cf22018-12-21 15:00:11 -0800397 // String to store multi SIM allowed
398 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
399
Derek Tan740e1672017-06-27 14:56:27 -0700400 // The AID of ISD-R.
401 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
402
yinxub1bed742017-04-17 11:45:04 -0700403 private NetworkScanRequestTracker mNetworkScanRequestTracker;
404
David Kelly5e06a7f2018-03-12 14:10:59 +0000405 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
406 private static final int MANUFACTURER_CODE_LENGTH = 8;
407
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800408 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800409 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800410
Derek Tan89e89d42014-07-08 17:00:10 -0700411 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700412 * Experiment flag to enable erase modem config on reset network, default value is false
413 */
414 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
415 "reset_network_erase_modem_config_enabled";
416
Rambo Wang0f050d82021-02-12 11:43:36 -0800417 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800418
sandeepjsb6c87872021-09-27 15:34:44 +0000419 /**
420 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
421 * one ICCID active at the same time.
422 * Apps should use below API signatures if targeting SDK is T and beyond.
423 *
424 * @hide
425 */
426 @ChangeId
427 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
428 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800429
Naina Nallurid63128d2019-09-17 14:10:30 -0700430 /**
Chen Xu540470b2021-12-14 17:15:47 -0800431 * Apps targeting on Android T and beyond will get exception whenever icc close channel
432 * operation fails.
433 */
434 @ChangeId
435 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
436 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
437
438 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700439 * A request object to use for transmitting data to an ICC.
440 */
441 private static final class IccAPDUArgument {
442 public int channel, cla, command, p1, p2, p3;
443 public String data;
444
445 public IccAPDUArgument(int channel, int cla, int command,
446 int p1, int p2, int p3, String data) {
447 this.channel = channel;
448 this.cla = cla;
449 this.command = command;
450 this.p1 = p1;
451 this.p2 = p2;
452 this.p3 = p3;
453 this.data = data;
454 }
455 }
456
457 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700458 * A request object to use for transmitting data to an ICC.
459 */
460 private static final class ManualNetworkSelectionArgument {
461 public OperatorInfo operatorInfo;
462 public boolean persistSelection;
463
464 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
465 this.operatorInfo = operatorInfo;
466 this.persistSelection = persistSelection;
467 }
468 }
469
470 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700471 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
472 * request after sending. The main thread will notify the request when it is complete.
473 */
474 private static final class MainThreadRequest {
475 /** The argument to use for the request */
476 public Object argument;
477 /** The result of the request that is run on the main thread */
478 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800479 // The subscriber id that this request applies to. Defaults to
480 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
481 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482
Nathan Harold92bed182018-10-12 18:16:49 -0700483 // In cases where subId is unavailable, the caller needs to specify the phone.
484 public Phone phone;
485
vagdeviaf9a5b92018-08-15 16:01:53 -0700486 public WorkSource workSource;
487
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488 public MainThreadRequest(Object argument) {
489 this.argument = argument;
490 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800491
Nathan Harold92bed182018-10-12 18:16:49 -0700492 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
493 this.argument = argument;
494 if (phone != null) {
495 this.phone = phone;
496 }
497 this.workSource = workSource;
498 }
499
vagdeviaf9a5b92018-08-15 16:01:53 -0700500 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800501 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800502 if (subId != null) {
503 this.subId = subId;
504 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700505 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507 }
508
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800509 private static final class IncomingThirdPartyCallArgs {
510 public final ComponentName component;
511 public final String callId;
512 public final String callerDisplayName;
513
514 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
515 String callerDisplayName) {
516 this.component = component;
517 this.callId = callId;
518 this.callerDisplayName = callerDisplayName;
519 }
520 }
521
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700522 /**
523 * A handler that processes messages on the main thread in the phone process. Since many
524 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
525 * inbound binder threads to the main thread in the phone process. The Binder thread
526 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
527 * on, which will be notified when the operation completes and will contain the result of the
528 * request.
529 *
530 * <p>If a MainThreadRequest object is provided in the msg.obj field,
531 * note that request.result must be set to something non-null for the calling thread to
532 * unblock.
533 */
534 private final class MainThreadHandler extends Handler {
535 @Override
536 public void handleMessage(Message msg) {
537 MainThreadRequest request;
538 Message onCompleted;
539 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000540 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800542 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543
544 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 case CMD_HANDLE_USSD_REQUEST: {
546 request = (MainThreadRequest) msg.obj;
547 final Phone phone = getPhoneFromRequest(request);
548 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800549 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700551
Pengquan Menga1bb6272018-09-06 09:59:22 -0700552 if (!isUssdApiAllowed(request.subId)) {
553 // Carrier does not support use of this API, return failure.
554 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
555 UssdResponse response = new UssdResponse(ussdRequest, null);
556 Bundle returnData = new Bundle();
557 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
558 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700559
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 request.result = true;
561 notifyRequester(request);
562 return;
563 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700564
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 try {
566 request.result = phone != null
567 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
568 } catch (CallStateException cse) {
569 request.result = false;
570 }
571 // Wake up the requesting thread
572 notifyRequester(request);
573 break;
pkanwar32d516d2016-10-14 19:37:38 -0700574 }
575
Yorke Lee716f67e2015-06-17 15:39:16 -0700576 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700577 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700578 final Phone phone = getPhoneFromRequest(request);
579 request.result = phone != null ?
580 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
581 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700582 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700584 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700586
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000590 uiccPort = getUiccPortFromRequest(request);
591 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800593 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800597 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000598 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800599 iccArgument.channel, iccArgument.cla, iccArgument.command,
600 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
601 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700602 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 break;
604
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 ar = (AsyncResult) msg.obj;
607 request = (MainThreadRequest) ar.userObj;
608 if (ar.exception == null && ar.result != null) {
609 request.result = ar.result;
610 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800611 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 if (ar.result == null) {
613 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800614 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800616 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 } else {
618 loge("iccTransmitApduLogicalChannel: Unknown exception");
619 }
620 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 break;
623
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
625 request = (MainThreadRequest) msg.obj;
626 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000627 uiccPort = getUiccPortFromRequest(request);
628 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800630 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 } else {
633 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800634 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000635 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800636 iccArgument.cla, iccArgument.command, iccArgument.p1,
637 iccArgument.p2,
638 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 }
640 break;
641
642 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
643 ar = (AsyncResult) msg.obj;
644 request = (MainThreadRequest) ar.userObj;
645 if (ar.exception == null && ar.result != null) {
646 request.result = ar.result;
647 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800648 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700649 if (ar.result == null) {
650 loge("iccTransmitApduBasicChannel: Empty response");
651 } else if (ar.exception instanceof CommandException) {
652 loge("iccTransmitApduBasicChannel: CommandException: " +
653 ar.exception);
654 } else {
655 loge("iccTransmitApduBasicChannel: Unknown exception");
656 }
657 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 break;
660
661 case CMD_EXCHANGE_SIM_IO:
662 request = (MainThreadRequest) msg.obj;
663 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000664 uiccPort = getUiccPortFromRequest(request);
665 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800667 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700668 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 } else {
670 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
671 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000672 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700673 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
674 iccArgument.data, onCompleted);
675 }
676 break;
677
678 case EVENT_EXCHANGE_SIM_IO_DONE:
679 ar = (AsyncResult) msg.obj;
680 request = (MainThreadRequest) ar.userObj;
681 if (ar.exception == null && ar.result != null) {
682 request.result = ar.result;
683 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800684 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700686 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700687 break;
688
Derek Tan4d5e5c12014-02-04 11:54:58 -0800689 case CMD_SEND_ENVELOPE:
690 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000691 uiccPort = getUiccPortFromRequest(request);
692 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700693 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800694 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700695 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700696 } else {
697 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800698 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700699 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800700 break;
701
702 case EVENT_SEND_ENVELOPE_DONE:
703 ar = (AsyncResult) msg.obj;
704 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700705 if (ar.exception == null && ar.result != null) {
706 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800707 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800708 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700709 if (ar.result == null) {
710 loge("sendEnvelopeWithStatus: Empty response");
711 } else if (ar.exception instanceof CommandException) {
712 loge("sendEnvelopeWithStatus: CommandException: " +
713 ar.exception);
714 } else {
715 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
716 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800717 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800719 break;
720
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 case CMD_OPEN_CHANNEL:
722 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000723 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800724 IccLogicalChannelRequest openChannelRequest =
725 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000726 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700727 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800728 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800729 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700730 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700731 } else {
732 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800733 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
734 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700735 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700736 break;
737
738 case EVENT_OPEN_CHANNEL_DONE:
739 ar = (AsyncResult) msg.obj;
740 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700743 int[] result = (int[]) ar.result;
744 int channelId = result[0];
745 byte[] selectResponse = null;
746 if (result.length > 1) {
747 selectResponse = new byte[result.length - 1];
748 for (int i = 1; i < result.length; ++i) {
749 selectResponse[i - 1] = (byte) result[i];
750 }
751 }
752 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800753 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800754
755 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700756 if (uiccPort == null) {
757 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
758 } else {
759 IccLogicalChannelRequest channelRequest =
760 (IccLogicalChannelRequest) request.argument;
761 channelRequest.channel = channelId;
762 uiccPort.onLogicalChannelOpened(channelRequest);
763 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 if (ar.result == null) {
766 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700767 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700768 if (ar.exception != null) {
769 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
770 }
771
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700772 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700773 if (ar.exception instanceof CommandException) {
774 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800775 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700776 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700777 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700778 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700779 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700780 }
781 }
782 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800783 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700785 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700786 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 break;
788
789 case CMD_CLOSE_CHANNEL:
790 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000791 uiccPort = getUiccPortFromRequest(request);
792 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700793 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800794 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800795 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800796 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700797 } else {
798 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000799 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700800 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700801 break;
802
803 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800804 ar = (AsyncResult) msg.obj;
805 request = (MainThreadRequest) ar.userObj;
806 if (ar.exception == null) {
807 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800808 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700809 if (uiccPort == null) {
810 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
811 } else {
812 final int channelId = (Integer) request.argument;
813 uiccPort.onLogicalChannelClosed(channelId);
814 }
Chen Xu540470b2021-12-14 17:15:47 -0800815 } else {
816 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800817 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800818 if (ar.exception instanceof CommandException) {
819 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
820 CommandException.Error error =
821 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800822 if (error == CommandException.Error.INVALID_ARGUMENTS) {
823 // should only throw exceptions from the binder threads.
824 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800825 "iccCloseLogicalChannel: invalid argument ");
826 }
827 } else {
828 loge("iccCloseLogicalChannel: Unknown exception");
829 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800830 request.result = (exception != null) ? exception :
831 new IllegalStateException(
832 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800833 }
834 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800835 break;
836
837 case CMD_NV_READ_ITEM:
838 request = (MainThreadRequest) msg.obj;
839 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800840 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
841 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800842 break;
843
844 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700845 ar = (AsyncResult) msg.obj;
846 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800847 if (ar.exception == null && ar.result != null) {
848 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700849 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800850 request.result = "";
851 if (ar.result == null) {
852 loge("nvReadItem: Empty response");
853 } else if (ar.exception instanceof CommandException) {
854 loge("nvReadItem: CommandException: " +
855 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700856 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800857 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700858 }
859 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700860 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700861 break;
862
Jake Hambye994d462014-02-03 13:10:13 -0800863 case CMD_NV_WRITE_ITEM:
864 request = (MainThreadRequest) msg.obj;
865 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
866 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800867 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700868 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800869 break;
870
871 case EVENT_NV_WRITE_ITEM_DONE:
872 handleNullReturnEvent(msg, "nvWriteItem");
873 break;
874
875 case CMD_NV_WRITE_CDMA_PRL:
876 request = (MainThreadRequest) msg.obj;
877 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800878 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800879 break;
880
881 case EVENT_NV_WRITE_CDMA_PRL_DONE:
882 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
883 break;
884
chen xu6dac5ab2018-10-26 17:39:23 -0700885 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800886 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700887 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800888 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800889 break;
890
chen xu6dac5ab2018-10-26 17:39:23 -0700891 case EVENT_RESET_MODEM_CONFIG_DONE:
892 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800893 break;
894
Sooraj Sasindran37444802020-08-11 10:40:43 -0700895 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
896 request = (MainThreadRequest) msg.obj;
897 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
898 request);
899 Phone phone = getPhoneFromRequest(request);
900 if (phone != null) {
901 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
902 } else {
903 loge("isNRDualConnectivityEnabled: No phone object");
904 request.result = false;
905 notifyRequester(request);
906 }
907 break;
908 }
909
910 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
913 if (ar.exception == null && ar.result != null) {
914 request.result = ar.result;
915 } else {
916 // request.result must be set to something non-null
917 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700918 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700919 request.result = ar.result;
920 } else {
921 request.result = false;
922 }
923 if (ar.result == null) {
924 loge("isNRDualConnectivityEnabled: Empty response");
925 } else if (ar.exception instanceof CommandException) {
926 loge("isNRDualConnectivityEnabled: CommandException: "
927 + ar.exception);
928 } else {
929 loge("isNRDualConnectivityEnabled: Unknown exception");
930 }
931 }
932 notifyRequester(request);
933 break;
934
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700935 case CMD_IS_VONR_ENABLED: {
936 request = (MainThreadRequest) msg.obj;
937 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
938 request);
939 Phone phone = getPhoneFromRequest(request);
940 if (phone != null) {
941 phone.isVoNrEnabled(onCompleted, request.workSource);
942 } else {
943 loge("isVoNrEnabled: No phone object");
944 request.result = false;
945 notifyRequester(request);
946 }
947 break;
948 }
949
950 case EVENT_IS_VONR_ENABLED_DONE:
951 ar = (AsyncResult) msg.obj;
952 request = (MainThreadRequest) ar.userObj;
953 if (ar.exception == null && ar.result != null) {
954 request.result = ar.result;
955 } else {
956 // request.result must be set to something non-null
957 // for the calling thread to unblock
958 if (ar.result != null) {
959 request.result = ar.result;
960 } else {
961 request.result = false;
962 }
963 if (ar.result == null) {
964 loge("isVoNrEnabled: Empty response");
965 } else if (ar.exception instanceof CommandException) {
966 loge("isVoNrEnabled: CommandException: "
967 + ar.exception);
968 } else {
969 loge("isVoNrEnabled: Unknown exception");
970 }
971 }
972 notifyRequester(request);
973 break;
974
Sooraj Sasindran37444802020-08-11 10:40:43 -0700975 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
976 request = (MainThreadRequest) msg.obj;
977 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
978 Phone phone = getPhoneFromRequest(request);
979 if (phone != null) {
980 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
981 request.workSource);
982 } else {
983 loge("enableNrDualConnectivity: No phone object");
984 request.result =
985 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
986 notifyRequester(request);
987 }
988 break;
989 }
990
991 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
992 ar = (AsyncResult) msg.obj;
993 request = (MainThreadRequest) ar.userObj;
994 if (ar.exception == null) {
995 request.result =
996 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
997 } else {
998 request.result =
999 TelephonyManager
1000 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1001 if (ar.exception instanceof CommandException) {
1002 CommandException.Error error =
1003 ((CommandException) (ar.exception)).getCommandError();
1004 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1005 request.result =
1006 TelephonyManager
1007 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001008 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1009 request.result =
1010 TelephonyManager
1011 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001012 }
1013 loge("enableNrDualConnectivity" + ": CommandException: "
1014 + ar.exception);
1015 } else {
1016 loge("enableNrDualConnectivity" + ": Unknown exception");
1017 }
1018 }
1019 notifyRequester(request);
1020 break;
1021 }
1022
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001023 case CMD_ENABLE_VONR: {
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1026 Phone phone = getPhoneFromRequest(request);
1027 if (phone != null) {
1028 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1029 request.workSource);
1030 } else {
1031 loge("setVoNrEnabled: No phone object");
1032 request.result =
1033 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1034 notifyRequester(request);
1035 }
1036 break;
1037 }
1038
1039 case EVENT_ENABLE_VONR_DONE: {
1040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
1042 if (ar.exception == null) {
1043 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1044 } else {
1045 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1046 if (ar.exception instanceof CommandException) {
1047 CommandException.Error error =
1048 ((CommandException) (ar.exception)).getCommandError();
1049 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1050 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1051 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1052 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1053 } else {
1054 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1055 }
1056 loge("setVoNrEnabled" + ": CommandException: "
1057 + ar.exception);
1058 } else {
1059 loge("setVoNrEnabled" + ": Unknown exception");
1060 }
1061 }
1062 notifyRequester(request);
1063 break;
1064 }
1065
SongFerngWang3ef3e072020-12-21 16:41:52 +08001066 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001067 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001068 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1069 request);
1070 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001071 break;
1072
SongFerngWang3ef3e072020-12-21 16:41:52 +08001073 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001074 ar = (AsyncResult) msg.obj;
1075 request = (MainThreadRequest) ar.userObj;
1076 if (ar.exception == null && ar.result != null) {
1077 request.result = ar.result; // Integer
1078 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301079 // request.result must be set to something non-null
1080 // for the calling thread to unblock
1081 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001082 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001083 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001084 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001085 loge("getAllowedNetworkTypesBitmask: CommandException: "
1086 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001087 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001088 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001089 }
1090 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001091 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001092 break;
1093
SongFerngWang3ef3e072020-12-21 16:41:52 +08001094 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001095 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001096 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1097 request);
1098 Pair<Integer, Long> reasonWithNetworkTypes =
1099 (Pair<Integer, Long>) request.argument;
1100 getPhoneFromRequest(request).setAllowedNetworkTypes(
1101 reasonWithNetworkTypes.first,
1102 reasonWithNetworkTypes.second,
1103 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001104 break;
1105
SongFerngWang3ef3e072020-12-21 16:41:52 +08001106 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1107 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001108 break;
1109
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001110 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1111 request = (MainThreadRequest)msg.obj;
1112 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001113 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001114 break;
1115
1116 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1117 ar = (AsyncResult)msg.obj;
1118 request = (MainThreadRequest)ar.userObj;
1119 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001120 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001121 break;
1122
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001123 case CMD_SET_VOICEMAIL_NUMBER:
1124 request = (MainThreadRequest) msg.obj;
1125 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1126 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001127 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1128 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001129 break;
1130
1131 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1132 handleNullReturnEvent(msg, "setVoicemailNumber");
1133 break;
1134
Stuart Scott54788802015-03-30 13:18:01 -07001135 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1136 request = (MainThreadRequest) msg.obj;
1137 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1138 request);
1139 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1140 break;
1141
1142 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1143 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1144 break;
1145
Shishir Agrawal302c8692015-06-19 13:49:39 -07001146 case CMD_PERFORM_NETWORK_SCAN:
1147 request = (MainThreadRequest) msg.obj;
1148 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1149 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1150 break;
1151
Hall Liu27d24262020-09-18 19:04:59 -07001152 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001153 request = (MainThreadRequest) msg.obj;
1154 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001155 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1156 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1157 request.argument;
1158 int callForwardingReason = args.first;
1159 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001160 break;
Hall Liu27d24262020-09-18 19:04:59 -07001161 }
1162 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001163 ar = (AsyncResult) msg.obj;
1164 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001165 TelephonyManager.CallForwardingInfoCallback callback =
1166 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1167 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001168 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001169 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001170 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1171 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1172 // Service Class is a bit mask per 3gpp 27.007. Search for
1173 // any service for voice call.
1174 if ((callForwardInfo.serviceClass
1175 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001176 callForwardingInfo = new CallForwardingInfo(
1177 callForwardInfo.status
1178 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001179 callForwardInfo.reason,
1180 callForwardInfo.number,
1181 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001182 break;
1183 }
1184 }
1185 // Didn't find a call forward info for voice call.
1186 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001187 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1188 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001189 }
Hall Liu27d24262020-09-18 19:04:59 -07001190 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001191 } else {
1192 if (ar.result == null) {
1193 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1194 }
1195 if (ar.exception != null) {
1196 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1197 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001198 int errorCode = TelephonyManager
1199 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001200 if (ar.exception instanceof CommandException) {
1201 CommandException.Error error =
1202 ((CommandException) (ar.exception)).getCommandError();
1203 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001204 errorCode = TelephonyManager
1205 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001206 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001207 errorCode = TelephonyManager
1208 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001209 }
1210 }
Hall Liu27d24262020-09-18 19:04:59 -07001211 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001212 }
Shuo Qian4a594052020-01-23 11:59:30 -08001213 break;
Hall Liu27d24262020-09-18 19:04:59 -07001214 }
Shuo Qian4a594052020-01-23 11:59:30 -08001215
Hall Liu27d24262020-09-18 19:04:59 -07001216 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001217 request = (MainThreadRequest) msg.obj;
1218 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001219 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001220 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001221 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1222 request.argument).first;
1223 request.phone.setCallForwardingOption(
1224 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001225 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001226 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001227 callForwardingInfoToSet.getReason(),
1228 callForwardingInfoToSet.getNumber(),
1229 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1230 break;
Hall Liu27d24262020-09-18 19:04:59 -07001231 }
Shuo Qian4a594052020-01-23 11:59:30 -08001232
Hall Liu27d24262020-09-18 19:04:59 -07001233 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001234 ar = (AsyncResult) msg.obj;
1235 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001236 Consumer<Integer> callback =
1237 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1238 request.argument).second;
1239 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001240 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001241 int errorCode = TelephonyManager.CallForwardingInfoCallback
1242 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001243 if (ar.exception instanceof CommandException) {
1244 CommandException.Error error =
1245 ((CommandException) (ar.exception)).getCommandError();
1246 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001247 errorCode = TelephonyManager.CallForwardingInfoCallback
1248 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001249 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001250 errorCode = TelephonyManager.CallForwardingInfoCallback
1251 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001252 }
1253 }
1254 callback.accept(errorCode);
1255 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001256 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001257 }
Shuo Qian4a594052020-01-23 11:59:30 -08001258 break;
Hall Liu27d24262020-09-18 19:04:59 -07001259 }
Shuo Qian4a594052020-01-23 11:59:30 -08001260
Hall Liu27d24262020-09-18 19:04:59 -07001261 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001262 request = (MainThreadRequest) msg.obj;
1263 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1264 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1265 break;
Hall Liu27d24262020-09-18 19:04:59 -07001266 }
Shuo Qian4a594052020-01-23 11:59:30 -08001267
Hall Liu27d24262020-09-18 19:04:59 -07001268 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001269 ar = (AsyncResult) msg.obj;
1270 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001271 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001272 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001273 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001274 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001275 // Service Class is a bit mask per 3gpp 27.007.
1276 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001277 if (callForwardResults.length > 1
1278 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001279 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001280 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001281 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1282 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001283 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001284 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001285 }
1286 } else {
1287 if (ar.result == null) {
1288 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1289 }
1290 if (ar.exception != null) {
1291 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1292 }
1293 if (ar.exception instanceof CommandException) {
1294 CommandException.Error error =
1295 ((CommandException) (ar.exception)).getCommandError();
1296 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001297 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001298 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001299 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1300 callWaitingStatus =
1301 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001302 }
1303 }
1304 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001305 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001306 break;
Hall Liu27d24262020-09-18 19:04:59 -07001307 }
Shuo Qian4a594052020-01-23 11:59:30 -08001308
Hall Liu27d24262020-09-18 19:04:59 -07001309 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001310 request = (MainThreadRequest) msg.obj;
1311 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001312 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1313 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001314 break;
Hall Liu27d24262020-09-18 19:04:59 -07001315 }
Shuo Qian4a594052020-01-23 11:59:30 -08001316
Hall Liu27d24262020-09-18 19:04:59 -07001317 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001318 ar = (AsyncResult) msg.obj;
1319 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001320 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1321 Consumer<Integer> callback =
1322 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1323 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001324 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001325 if (ar.exception instanceof CommandException) {
1326 CommandException.Error error =
1327 ((CommandException) (ar.exception)).getCommandError();
1328 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1329 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001330 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1331 callback.accept(
1332 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001333 } else {
1334 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1335 }
1336 } else {
1337 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1338 }
1339 } else {
1340 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1341 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001342 }
Shuo Qian4a594052020-01-23 11:59:30 -08001343 break;
Hall Liu27d24262020-09-18 19:04:59 -07001344 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001345 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1346 ar = (AsyncResult) msg.obj;
1347 request = (MainThreadRequest) ar.userObj;
1348 CellNetworkScanResult cellScanResult;
1349 if (ar.exception == null && ar.result != null) {
1350 cellScanResult = new CellNetworkScanResult(
1351 CellNetworkScanResult.STATUS_SUCCESS,
1352 (List<OperatorInfo>) ar.result);
1353 } else {
1354 if (ar.result == null) {
1355 loge("getCellNetworkScanResults: Empty response");
1356 }
1357 if (ar.exception != null) {
1358 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1359 }
1360 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1361 if (ar.exception instanceof CommandException) {
1362 CommandException.Error error =
1363 ((CommandException) (ar.exception)).getCommandError();
1364 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1365 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1366 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1367 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1368 }
1369 }
1370 cellScanResult = new CellNetworkScanResult(errorCode, null);
1371 }
1372 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001373 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001374 break;
1375
1376 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1377 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001378 ManualNetworkSelectionArgument selArg =
1379 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001380 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1381 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001382 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1383 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001384 break;
1385
1386 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001387 ar = (AsyncResult) msg.obj;
1388 request = (MainThreadRequest) ar.userObj;
1389 if (ar.exception == null) {
1390 request.result = true;
1391 } else {
1392 request.result = false;
1393 loge("setNetworkSelectionModeManual " + ar.exception);
1394 }
1395 notifyRequester(request);
1396 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001397 break;
1398
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001399 case CMD_GET_MODEM_ACTIVITY_INFO:
1400 request = (MainThreadRequest) msg.obj;
1401 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001402 if (defaultPhone != null) {
1403 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001404 } else {
1405 ResultReceiver result = (ResultReceiver) request.argument;
1406 Bundle bundle = new Bundle();
1407 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001408 new ModemActivityInfo(0, 0, 0,
1409 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001410 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001411 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001412 break;
1413
Hall Liud0f208c2020-10-14 16:54:44 -07001414 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001415 ar = (AsyncResult) msg.obj;
1416 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001417 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001418 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001419 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001420 if (mLastModemActivityInfo == null) {
1421 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1422 mLastModemActivitySpecificInfo[0] =
1423 new ActivityStatsTechSpecificInfo(
1424 0,
1425 0,
1426 new int[ModemActivityInfo.getNumTxPowerLevels()],
1427 0);
1428 mLastModemActivityInfo =
1429 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1430 }
1431
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001432 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001433 // Update the last modem activity info and the result of the request.
1434 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1435 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001436 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001437 }
Kai Shi917fdc62022-11-28 14:01:02 -08001438 // This is needed to decouple ret from mLastModemActivityInfo
1439 // We don't want to return mLastModemActivityInfo which is updated
1440 // inside mergeModemActivityInfo()
1441 ret = new ModemActivityInfo(
1442 mLastModemActivityInfo.getTimestampMillis(),
1443 mLastModemActivityInfo.getSleepTimeMillis(),
1444 mLastModemActivityInfo.getIdleTimeMillis(),
1445 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001446
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();
Kai Shi917fdc62022-11-28 14:01:02 -08001463 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001464 bundle.putParcelable(
1465 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001466 ret);
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 Cukierman6dac5eb2022-09-19 16:09:04 +00002355 mTelephony2gUpdater = new Telephony2gUpdater(
2356 Executors.newSingleThreadExecutor(), mApp);
2357 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 publish();
2359 }
2360
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002361 private Phone getDefaultPhone() {
2362 Phone thePhone = getPhone(getDefaultSubscription());
2363 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2364 }
2365
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 private void publish() {
2367 if (DBG) log("publish: " + this);
2368
Peter Wangc035ce42020-01-08 21:00:22 -08002369 TelephonyFrameworkInitializer
2370 .getTelephonyServiceManager()
2371 .getTelephonyServiceRegisterer()
2372 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 }
2374
Stuart Scott584921c2015-01-15 17:10:34 -08002375 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002376 if (request.phone != null) {
2377 return request.phone;
2378 } else {
2379 return getPhoneFromSubId(request.subId);
2380 }
2381 }
2382
2383 private Phone getPhoneFromSubId(int subId) {
2384 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2385 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002386 }
2387
Rambo Wange53e07d2022-05-10 13:01:13 -07002388 @Nullable
2389 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002390 Phone phone = getPhoneFromRequest(request);
2391 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002392 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002393 }
2394
Wink Saville36469e72014-06-11 15:17:00 -07002395 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002396 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002397 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399
Kai Shif70f46f2021-03-03 13:59:46 -08002400 private void sendEraseModemConfig(@NonNull Phone phone) {
2401 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2402 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2403 }
2404
2405 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2406 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2407 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002408 }
2409
Peter Wang44b186e2020-01-13 23:33:09 -08002410 private boolean isImsAvailableOnDevice() {
2411 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2412 if (pm == null) {
2413 // For some reason package manger is not available.. This will fail internally anyway,
2414 // so do not throw error and allow.
2415 return true;
2416 }
2417 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2418 }
2419
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002421 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002422 }
2423
Wink Savilleb564aae2014-10-23 10:18:09 -07002424 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 if (DBG) log("dial: " + number);
2426 // No permission check needed here: This is just a wrapper around the
2427 // ACTION_DIAL intent, which is available to any app since it puts up
2428 // the UI before it does anything.
2429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002430 final long identity = Binder.clearCallingIdentity();
2431 try {
2432 String url = createTelUrl(number);
2433 if (url == null) {
2434 return;
2435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437 // PENDING: should we just silently fail if phone is offhook or ringing?
2438 PhoneConstants.State state = mCM.getState(subId);
2439 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2440 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2441 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2442 mApp.startActivity(intent);
2443 }
2444 } finally {
2445 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 }
2447 }
2448
2449 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002450 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002451 }
2452
Wink Savilleb564aae2014-10-23 10:18:09 -07002453 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 if (DBG) log("call: " + number);
2455
2456 // This is just a wrapper around the ACTION_CALL intent, but we still
2457 // need to do a permission check since we're calling startActivity()
2458 // from the context of the phone app.
2459 enforceCallPermission();
2460
Jordan Liu1617b712019-07-10 15:06:26 -07002461 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 != AppOpsManager.MODE_ALLOWED) {
2463 return;
2464 }
2465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002466 final long identity = Binder.clearCallingIdentity();
2467 try {
2468 String url = createTelUrl(number);
2469 if (url == null) {
2470 return;
2471 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002473 boolean isValid = false;
2474 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2475 if (slist != null) {
2476 for (SubscriptionInfo subInfoRecord : slist) {
2477 if (subInfoRecord.getSubscriptionId() == subId) {
2478 isValid = true;
2479 break;
2480 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002481 }
Wink Saville08874612014-08-31 19:19:58 -07002482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002483 if (!isValid) {
2484 return;
2485 }
Wink Saville08874612014-08-31 19:19:58 -07002486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002487 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2488 intent.putExtra(SUBSCRIPTION_KEY, subId);
2489 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2490 mApp.startActivity(intent);
2491 } finally {
2492 Binder.restoreCallingIdentity(identity);
2493 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002494 }
2495
Wink Savilleb564aae2014-10-23 10:18:09 -07002496 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002497 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002498 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2499 }
2500
Wink Savilleb564aae2014-10-23 10:18:09 -07002501 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002502 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002503 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2504 }
2505
Wink Savilleb564aae2014-10-23 10:18:09 -07002506 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508
2509 final long identity = Binder.clearCallingIdentity();
2510 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002511 Phone phone = getPhone(subId);
2512 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513 checkSimPin.start();
2514 return checkSimPin.unlockSim(null, pin);
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
2517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 }
2519
Wink Savilleb564aae2014-10-23 10:18:09 -07002520 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002522
2523 final long identity = Binder.clearCallingIdentity();
2524 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002525 Phone phone = getPhone(subId);
2526 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527 checkSimPuk.start();
2528 return checkSimPuk.unlockSim(puk, pin);
2529 } finally {
2530 Binder.restoreCallingIdentity(identity);
2531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002532 }
2533
2534 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002535 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002536 * a synchronous one.
2537 */
2538 private static class UnlockSim extends Thread {
2539
2540 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002541 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542
2543 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002544 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2545 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546
2547 // For replies from SimCard interface
2548 private Handler mHandler;
2549
2550 // For async handler to identify request type
2551 private static final int SUPPLY_PIN_COMPLETE = 100;
2552
Michele Berionne5e411512020-11-13 02:36:59 +00002553 UnlockSim(int phoneId, IccCard simCard) {
2554 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002555 mSimCard = simCard;
2556 }
2557
2558 @Override
2559 public void run() {
2560 Looper.prepare();
2561 synchronized (UnlockSim.this) {
2562 mHandler = new Handler() {
2563 @Override
2564 public void handleMessage(Message msg) {
2565 AsyncResult ar = (AsyncResult) msg.obj;
2566 switch (msg.what) {
2567 case SUPPLY_PIN_COMPLETE:
2568 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2569 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002570 mRetryCount = msg.arg1;
2571 if (ar.exception != null) {
2572 if (ar.exception instanceof CommandException &&
2573 ((CommandException)(ar.exception)).getCommandError()
2574 == CommandException.Error.PASSWORD_INCORRECT) {
2575 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002576 } //When UiccCardApp dispose,handle message and return exception
2577 else if (ar.exception instanceof CommandException &&
2578 ((CommandException) (ar.exception)).getCommandError()
2579 == CommandException.Error.ABORTED) {
2580 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002581 } else {
2582 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2583 }
2584 } else {
2585 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587 mDone = true;
2588 UnlockSim.this.notifyAll();
2589 }
2590 break;
2591 }
2592 }
2593 };
2594 UnlockSim.this.notifyAll();
2595 }
2596 Looper.loop();
2597 }
2598
2599 /*
2600 * Use PIN or PUK to unlock SIM card
2601 *
2602 * If PUK is null, unlock SIM card with PIN
2603 *
2604 * If PUK is not null, unlock SIM card with PUK and set PIN code
2605 */
Wink Saville9de0f752013-10-22 19:04:03 -07002606 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002607
2608 while (mHandler == null) {
2609 try {
2610 wait();
2611 } catch (InterruptedException e) {
2612 Thread.currentThread().interrupt();
2613 }
2614 }
2615 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2616
2617 if (puk == null) {
2618 mSimCard.supplyPin(pin, callback);
2619 } else {
2620 mSimCard.supplyPuk(puk, pin, callback);
2621 }
2622
2623 while (!mDone) {
2624 try {
2625 Log.d(LOG_TAG, "wait for done");
2626 wait();
2627 } catch (InterruptedException e) {
2628 // Restore the interrupted status
2629 Thread.currentThread().interrupt();
2630 }
2631 }
2632 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002633 int[] resultArray = new int[2];
2634 resultArray[0] = mResult;
2635 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002636
2637 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002638 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002639 }
2640
Wink Saville9de0f752013-10-22 19:04:03 -07002641 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002642 }
2643 }
2644
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002645 /**
2646 * This method has been removed due to privacy and stability concerns.
2647 */
2648 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002649 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002650 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2651 return;
Wink Saville36469e72014-06-11 15:17:00 -07002652 }
2653
Nathan Harold1f889d82020-06-04 17:05:26 -07002654 @Override
2655 public void updateServiceLocationWithPackageName(String callingPackage) {
2656 mApp.getSystemService(AppOpsManager.class)
2657 .checkPackage(Binder.getCallingUid(), callingPackage);
2658
Nathan Haroldf096d982020-11-18 17:18:06 -08002659 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002660 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2661 // Callers targeting S have no business invoking this method.
2662 return;
2663 }
2664
2665 LocationAccessPolicy.LocationPermissionResult locationResult =
2666 LocationAccessPolicy.checkLocationPermission(mApp,
2667 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2668 .setCallingPackage(callingPackage)
2669 .setCallingFeatureId(null)
2670 .setCallingPid(Binder.getCallingPid())
2671 .setCallingUid(Binder.getCallingUid())
2672 .setMethod("updateServiceLocation")
2673 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2674 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2675 .build());
2676 // Apps that lack location permission have no business calling this method;
2677 // however, because no permission was declared in the public API, denials must
2678 // all be "soft".
2679 switch (locationResult) {
2680 case DENIED_HARD: /* fall through */
2681 case DENIED_SOFT:
2682 return;
2683 }
2684
2685 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 final long identity = Binder.clearCallingIdentity();
2687 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002688 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002690 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002691 }
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 }
2696
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002697 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002698 @Override
2699 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002700 return isRadioOnWithFeature(callingPackage, null);
2701 }
2702
2703
2704 @Override
2705 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2706 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2707 callingFeatureId);
2708 }
2709
2710 @Deprecated
2711 @Override
2712 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2713 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002714 }
2715
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002716 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002717 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2718 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002720 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002721 return false;
2722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002723
2724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 return isRadioOnForSubscriber(subId);
2727 } finally {
2728 Binder.restoreCallingIdentity(identity);
2729 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002730 }
2731
2732 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733 final long identity = Binder.clearCallingIdentity();
2734 try {
2735 final Phone phone = getPhone(subId);
2736 if (phone != null) {
2737 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2738 } else {
2739 return false;
2740 }
2741 } finally {
2742 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 }
2745
2746 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002747 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 }
Wink Saville36469e72014-06-11 15:17:00 -07002749
Wink Savilleb564aae2014-10-23 10:18:09 -07002750 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002752
2753 final long identity = Binder.clearCallingIdentity();
2754 try {
2755 final Phone phone = getPhone(subId);
2756 if (phone != null) {
2757 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2758 }
2759 } finally {
2760 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002761 }
Wink Saville36469e72014-06-11 15:17:00 -07002762 }
2763
2764 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002765 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002766 }
2767
Wink Savilleb564aae2014-10-23 10:18:09 -07002768 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002769 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002770
2771 final long identity = Binder.clearCallingIdentity();
2772 try {
2773 final Phone phone = getPhone(subId);
2774 if (phone == null) {
2775 return false;
2776 }
2777 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2778 toggleRadioOnOffForSubscriber(subId);
2779 }
2780 return true;
2781 } finally {
2782 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002784 }
Wink Saville36469e72014-06-11 15:17:00 -07002785
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002786 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002787 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002788 /*
2789 * If any of the Radios are available, it will need to be
2790 * shutdown. So return true if any Radio is available.
2791 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002792 final long identity = Binder.clearCallingIdentity();
2793 try {
2794 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2795 Phone phone = PhoneFactory.getPhone(i);
2796 if (phone != null && phone.isRadioAvailable()) return true;
2797 }
2798 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2799 return false;
2800 } finally {
2801 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002802 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002803 }
2804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002806 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807 enforceModifyPermission();
2808
2809 final long identity = Binder.clearCallingIdentity();
2810 try {
2811 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2812 logv("Shutting down Phone " + i);
2813 shutdownRadioUsingPhoneId(i);
2814 }
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002817 }
2818 }
2819
2820 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002821 Phone phone = PhoneFactory.getPhone(phoneId);
2822 if (phone != null && phone.isRadioAvailable()) {
2823 phone.shutdownRadio();
2824 }
2825 }
2826
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002828 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829
2830 final long identity = Binder.clearCallingIdentity();
2831 try {
2832 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2833 if (defaultPhone != null) {
2834 defaultPhone.setRadioPower(turnOn);
2835 return true;
2836 } else {
2837 loge("There's no default phone.");
2838 return false;
2839 }
2840 } finally {
2841 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002842 }
Wink Saville36469e72014-06-11 15:17:00 -07002843 }
2844
Wink Savilleb564aae2014-10-23 10:18:09 -07002845 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002846 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002847
2848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 final Phone phone = getPhone(subId);
2851 if (phone != null) {
2852 phone.setRadioPower(turnOn);
2853 return true;
2854 } else {
2855 return false;
2856 }
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 }
2861
Wink Saville36469e72014-06-11 15:17:00 -07002862 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002863 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002864 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002865 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866
2867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 int subId = mSubscriptionController.getDefaultDataSubId();
2870 final Phone phone = getPhone(subId);
2871 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002872 if (phone.isUsingNewDataStack()) {
2873 phone.getDataSettingsManager().setDataEnabled(
Sarah Chinecc78c42022-03-31 21:16:48 -07002874 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Jack Yu99e87332021-12-17 23:14:15 -08002875 } else {
2876 phone.getDataEnabledSettings().setDataEnabled(
2877 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2878 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879 return true;
2880 } else {
2881 return false;
2882 }
2883 } finally {
2884 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002885 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002886 }
2887
Wink Saville36469e72014-06-11 15:17:00 -07002888 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002889 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002890 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892
2893 final long identity = Binder.clearCallingIdentity();
2894 try {
2895 int subId = mSubscriptionController.getDefaultDataSubId();
2896 final Phone phone = getPhone(subId);
2897 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002898 if (phone.isUsingNewDataStack()) {
2899 phone.getDataSettingsManager().setDataEnabled(
Sarah Chinecc78c42022-03-31 21:16:48 -07002900 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Jack Yu99e87332021-12-17 23:14:15 -08002901 } else {
2902 phone.getDataEnabledSettings().setDataEnabled(
2903 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2904 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 return true;
2906 } else {
2907 return false;
2908 }
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 }
2913
Sanket Padawe356d7632015-06-22 14:03:32 -07002914 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002915 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916 final long identity = Binder.clearCallingIdentity();
2917 try {
2918 final Phone phone = getPhone(subId);
2919 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07002920 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 } else {
2922 return false;
2923 }
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002926 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 }
2928
2929 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002930 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002931 }
2932
pkanwarae03a6b2016-11-06 20:37:09 -08002933 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934 enforceCallPermission();
2935
2936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2939 return;
2940 }
2941 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2942 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
2945 }
pkanwar32d516d2016-10-14 19:37:38 -07002946 };
2947
Wink Savilleb564aae2014-10-23 10:18:09 -07002948 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002949 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002950
2951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2954 return false;
2955 }
2956 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2957 } finally {
2958 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002960 }
2961
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002962 /**
2963 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2964 * tag on getCallState Binder call.
2965 */
2966 @Deprecated
2967 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002968 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002969 if (CompatChanges.isChangeEnabled(
2970 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2971 Binder.getCallingUid())) {
2972 // Do not allow this API to be called on API version 31+, it should only be
2973 // called on old apps using this Binder call directly.
2974 throw new SecurityException("This method can only be used for applications "
2975 + "targeting API version 30 or less.");
2976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002977 final long identity = Binder.clearCallingIdentity();
2978 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002979 Phone phone = getPhone(getDefaultSubscription());
2980 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2981 PhoneConstantConversions.convertCallState(phone.getState());
2982 } finally {
2983 Binder.restoreCallingIdentity(identity);
2984 }
2985 }
2986
2987 @Override
2988 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2989 if (CompatChanges.isChangeEnabled(
2990 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2991 Binder.getCallingUid())) {
2992 // Check READ_PHONE_STATE for API version 31+
2993 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2994 featureId, "getCallStateForSubscription")) {
2995 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2996 + "targeting API level 31+.");
2997 }
2998 }
2999 final long identity = Binder.clearCallingIdentity();
3000 try {
3001 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3003 PhoneConstantConversions.convertCallState(phone.getState());
3004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003007 }
3008
Sanket Padawe356d7632015-06-22 14:03:32 -07003009 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003010 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003011 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3012 }
3013
3014 @Override
3015 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016 final long identity = Binder.clearCallingIdentity();
3017 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003018 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08003020 if (phone.isUsingNewDataStack()) {
3021 return phone.getDataNetworkController().getInternetDataNetworkState();
3022 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
3024 } else {
3025 return PhoneConstantConversions.convertDataState(
3026 PhoneConstants.DataState.DISCONNECTED);
3027 }
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003031 }
3032
Sanket Padawe356d7632015-06-22 14:03:32 -07003033 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003034 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003035 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3036 }
3037
3038 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003039 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003040 final long identity = Binder.clearCallingIdentity();
3041 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003042 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003044 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003045 } else {
3046 return TelephonyManager.DATA_ACTIVITY_NONE;
3047 }
3048 } finally {
3049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003051 }
3052
3053 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003054 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003055 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003056 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003057
3058 LocationAccessPolicy.LocationPermissionResult locationResult =
3059 LocationAccessPolicy.checkLocationPermission(mApp,
3060 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3061 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003062 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003063 .setCallingPid(Binder.getCallingPid())
3064 .setCallingUid(Binder.getCallingUid())
3065 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003066 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003067 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3068 .build());
3069 switch (locationResult) {
3070 case DENIED_HARD:
3071 throw new SecurityException("Not allowed to access cell location");
3072 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003073 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3074 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003075 }
3076
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003077 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003078 final long identity = Binder.clearCallingIdentity();
3079 try {
3080 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003081 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003082 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083 } finally {
3084 Binder.restoreCallingIdentity(identity);
3085 }
Svetoslav64fad262015-04-14 14:35:21 -07003086 }
3087
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003088 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003089 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003090 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3091 // registered cell info, so return a NULL country instead.
3092 final long identity = Binder.clearCallingIdentity();
3093 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003094 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3095 // Get default phone in this case.
3096 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3097 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003098 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003099 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003100 if (phone == null) return "";
3101 ServiceStateTracker sst = phone.getServiceStateTracker();
3102 if (sst == null) return "";
3103 LocaleTracker lt = sst.getLocaleTracker();
3104 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003105 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003106 } finally {
3107 Binder.restoreCallingIdentity(identity);
3108 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003109 }
3110
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003111 /**
3112 * This method was removed due to potential issues caused by performing partial
3113 * updates of service state, and lack of a credible use case.
3114 *
3115 * This has the ability to break the telephony implementation by disabling notification of
3116 * changes in device connectivity. DO NOT USE THIS!
3117 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003118 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003119 public void enableLocationUpdates() {
3120 mApp.enforceCallingOrSelfPermission(
3121 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003122 }
3123
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003124 /**
3125 * This method was removed due to potential issues caused by performing partial
3126 * updates of service state, and lack of a credible use case.
3127 *
3128 * This has the ability to break the telephony implementation by disabling notification of
3129 * changes in device connectivity. DO NOT USE THIS!
3130 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003131 @Override
3132 public void disableLocationUpdates() {
3133 mApp.enforceCallingOrSelfPermission(
3134 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003135 }
3136
3137 @Override
3138 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003139 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3140 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003141 try {
3142 mApp.getSystemService(AppOpsManager.class)
3143 .checkPackage(Binder.getCallingUid(), callingPackage);
3144 } catch (SecurityException e) {
3145 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3146 throw e;
3147 }
3148
Nathan Haroldf096d982020-11-18 17:18:06 -08003149 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003150 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3151 throw new SecurityException(
3152 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3153 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003154
Jordan Liu1617b712019-07-10 15:06:26 -07003155 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003156 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3157 return null;
3158 }
Svetoslav64fad262015-04-14 14:35:21 -07003159
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003160 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003161
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003162 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003163 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003164
Nathan Haroldf180aac2018-06-01 18:43:55 -07003165 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3166 for (CellInfo ci : info) {
3167 if (ci instanceof CellInfoGsm) {
3168 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3169 } else if (ci instanceof CellInfoWcdma) {
3170 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003172 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003173 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003174 }
3175
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003176 private List<CellInfo> getCachedCellInfo() {
3177 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3178 for (Phone phone : PhoneFactory.getPhones()) {
3179 List<CellInfo> info = phone.getAllCellInfo();
3180 if (info != null) cellInfos.addAll(info);
3181 }
3182 return cellInfos;
3183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003184
3185 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003186 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003187 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003188 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003189
3190 LocationAccessPolicy.LocationPermissionResult locationResult =
3191 LocationAccessPolicy.checkLocationPermission(mApp,
3192 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3193 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003194 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003195 .setCallingPid(Binder.getCallingPid())
3196 .setCallingUid(Binder.getCallingUid())
3197 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003198 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003199 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3200 .build());
3201 switch (locationResult) {
3202 case DENIED_HARD:
3203 throw new SecurityException("Not allowed to access cell info");
3204 case DENIED_SOFT:
3205 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003206 }
3207
Nathan Haroldf096d982020-11-18 17:18:06 -08003208 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003209 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3210 return getCachedCellInfo();
3211 }
3212
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003213 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003214 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215 final long identity = Binder.clearCallingIdentity();
3216 try {
3217 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3218 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003219 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003220 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 if (info != null) cellInfos.addAll(info);
3222 }
3223 return cellInfos;
3224 } finally {
3225 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003226 }
3227 }
3228
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003229 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003230 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3231 String callingFeatureId) {
3232 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3233 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003234 }
3235
3236 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003237 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3238 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003239 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003240 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003241 }
3242
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003243 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3244 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003245 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003246 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003247
3248 LocationAccessPolicy.LocationPermissionResult locationResult =
3249 LocationAccessPolicy.checkLocationPermission(mApp,
3250 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3251 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003252 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003253 .setCallingPid(Binder.getCallingPid())
3254 .setCallingUid(Binder.getCallingUid())
3255 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003256 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3257 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003258 .build());
3259 switch (locationResult) {
3260 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003261 if (TelephonyPermissions
3262 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003263 // Safetynet logging for b/154934934
3264 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3265 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003266 throw new SecurityException("Not allowed to access cell info");
3267 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003268 if (TelephonyPermissions
3269 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003270 // Safetynet logging for b/154934934
3271 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3272 }
Nathan Harold5320c422019-05-09 10:26:08 -07003273 try {
3274 cb.onCellInfo(new ArrayList<CellInfo>());
3275 } catch (RemoteException re) {
3276 // Drop without consequences
3277 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003278 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003279 }
3280
Nathan Harolda939a962019-05-09 10:13:47 -07003281
3282 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003283 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3284
3285 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3286 }
3287
3288 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003289 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003290 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003291 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292
3293 final long identity = Binder.clearCallingIdentity();
3294 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003295 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003296 } finally {
3297 Binder.restoreCallingIdentity(identity);
3298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003299 }
3300
Shishir Agrawala9f32182016-04-12 12:00:16 -07003301 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003302 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003303 Phone phone = PhoneFactory.getPhone(slotIndex);
3304 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003305 return null;
3306 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003307 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003308 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003309 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003310 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003311 return null;
3312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003313
3314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 return phone.getImei();
3317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003320 }
3321
3322 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003323 public String getTypeAllocationCodeForSlot(int slotIndex) {
3324 Phone phone = PhoneFactory.getPhone(slotIndex);
3325 String tac = null;
3326 if (phone != null) {
3327 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003328 try {
3329 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3330 } catch (IndexOutOfBoundsException e) {
3331 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3332 return null;
3333 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003334 }
3335 return tac;
3336 }
3337
3338 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003339 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003340 try {
3341 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3342 } catch (SecurityException se) {
3343 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3344 throw new SecurityException("Package " + callingPackage + " does not belong to "
3345 + Binder.getCallingUid());
3346 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003347 Phone phone = PhoneFactory.getPhone(slotIndex);
3348 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003349 return null;
3350 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003351
Jeff Davidson913390f2018-02-23 17:11:49 -08003352 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003353 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003354 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003355 return null;
3356 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357
3358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 return phone.getMeid();
3361 } finally {
3362 Binder.restoreCallingIdentity(identity);
3363 }
Jack Yu2af8d712017-03-15 17:14:14 -07003364 }
3365
3366 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003367 public String getManufacturerCodeForSlot(int slotIndex) {
3368 Phone phone = PhoneFactory.getPhone(slotIndex);
3369 String manufacturerCode = null;
3370 if (phone != null) {
3371 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003372 try {
3373 manufacturerCode =
3374 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3375 } catch (IndexOutOfBoundsException e) {
3376 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3377 return null;
3378 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003379 }
3380 return manufacturerCode;
3381 }
3382
3383 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003384 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3385 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003386 Phone phone = PhoneFactory.getPhone(slotIndex);
3387 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003388 return null;
3389 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003390 int subId = phone.getSubId();
3391 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003392 mApp, subId, callingPackage, callingFeatureId,
3393 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003394 return null;
3395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003396
3397 final long identity = Binder.clearCallingIdentity();
3398 try {
3399 return phone.getDeviceSvn();
3400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003403 }
3404
fionaxu43304da2017-11-27 22:51:16 -08003405 @Override
3406 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003407 final long identity = Binder.clearCallingIdentity();
3408 try {
3409 final Phone phone = getPhone(subId);
3410 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3411 } finally {
3412 Binder.restoreCallingIdentity(identity);
3413 }
fionaxu43304da2017-11-27 22:51:16 -08003414 }
3415
3416 @Override
3417 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003418 final long identity = Binder.clearCallingIdentity();
3419 try {
3420 final Phone phone = getPhone(subId);
3421 return phone == null ? null : phone.getCarrierName();
3422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
fionaxu43304da2017-11-27 22:51:16 -08003425 }
3426
calvinpanffe225e2018-11-01 19:43:06 +08003427 @Override
chen xu0026ca62019-03-06 15:28:50 -08003428 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003429 final long identity = Binder.clearCallingIdentity();
3430 try {
3431 final Phone phone = getPhone(subId);
3432 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003433 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003434 } finally {
3435 Binder.restoreCallingIdentity(identity);
3436 }
3437 }
3438
3439 @Override
chen xu0026ca62019-03-06 15:28:50 -08003440 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003444 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003445 } finally {
3446 Binder.restoreCallingIdentity(identity);
3447 }
3448 }
3449
chen xu651eec72018-11-11 19:03:44 -08003450 @Override
chen xu864e11c2018-12-06 22:10:03 -08003451 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3452 if (!isSubscriptionMccMnc) {
3453 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3454 }
chen xu651eec72018-11-11 19:03:44 -08003455 final Phone phone = PhoneFactory.getPhone(slotIndex);
3456 if (phone == null) {
3457 return TelephonyManager.UNKNOWN_CARRIER_ID;
3458 }
3459 final long identity = Binder.clearCallingIdentity();
3460 try {
3461 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3462 } finally {
3463 Binder.restoreCallingIdentity(identity);
3464 }
3465 }
3466
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003467 //
3468 // Internal helper methods.
3469 //
3470
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003471 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003472 * Make sure the caller is the calling package itself
3473 *
3474 * @throws SecurityException if the caller is not the calling package
3475 */
3476 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3477 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003478 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3479 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003480 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003481 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003482 } catch (PackageManager.NameNotFoundException e) {
3483 // packageUid is -1
3484 }
3485 if (packageUid != callingUid) {
3486 throw new SecurityException(message + ": Package " + callingPackage
3487 + " does not belong to " + callingUid);
3488 }
3489 }
3490
3491 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003492 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3493 *
3494 * @throws SecurityException if the caller does not have the required permission
3495 */
3496 private void enforceModifyPermission() {
3497 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3498 }
3499
Shuo Qian3b6ee772019-11-13 17:43:31 -08003500 private void enforceActiveEmergencySessionPermission() {
3501 mApp.enforceCallingOrSelfPermission(
3502 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3503 }
3504
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003505 /**
3506 * Make sure the caller has the CALL_PHONE permission.
3507 *
3508 * @throws SecurityException if the caller does not have the required permission
3509 */
3510 private void enforceCallPermission() {
3511 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3512 }
3513
paulhu5a773602019-08-23 19:17:33 +08003514 private void enforceSettingsPermission() {
3515 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003516 }
3517
Michele Berionne5e411512020-11-13 02:36:59 +00003518 private void enforceRebootPermission() {
3519 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3520 }
3521
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003522 private String createTelUrl(String number) {
3523 if (TextUtils.isEmpty(number)) {
3524 return null;
3525 }
3526
Jake Hambye994d462014-02-03 13:10:13 -08003527 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003528 }
3529
Ihab Awadf9e92732013-12-05 18:02:52 -08003530 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003531 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3532 }
3533
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003534 private static void logv(String msg) {
3535 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3536 }
3537
Ihab Awadf9e92732013-12-05 18:02:52 -08003538 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003539 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3540 }
3541
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003542 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003543 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003544 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003545 }
3546
Sanket Padawe356d7632015-06-22 14:03:32 -07003547 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003548 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 final Phone phone = PhoneFactory.getPhone(slotIndex);
3552 if (phone == null) {
3553 return PhoneConstants.PHONE_TYPE_NONE;
3554 } else {
3555 return phone.getPhoneType();
3556 }
3557 } finally {
3558 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003559 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003560 }
3561
3562 /**
3563 * Returns the CDMA ERI icon index to display
3564 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003565 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003566 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3567 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3568 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003569 }
3570
Sanket Padawe356d7632015-06-22 14:03:32 -07003571 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003572 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3573 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003575 mApp, subId, callingPackage, callingFeatureId,
3576 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003577 return -1;
3578 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579
3580 final long identity = Binder.clearCallingIdentity();
3581 try {
3582 final Phone phone = getPhone(subId);
3583 if (phone != null) {
3584 return phone.getCdmaEriIconIndex();
3585 } else {
3586 return -1;
3587 }
3588 } finally {
3589 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003590 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003591 }
3592
3593 /**
3594 * Returns the CDMA ERI icon mode,
3595 * 0 - ON
3596 * 1 - FLASHING
3597 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003598 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003599 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3600 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3601 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003602 }
3603
Sanket Padawe356d7632015-06-22 14:03:32 -07003604 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003605 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3606 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003608 mApp, subId, callingPackage, callingFeatureId,
3609 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003610 return -1;
3611 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003612
3613 final long identity = Binder.clearCallingIdentity();
3614 try {
3615 final Phone phone = getPhone(subId);
3616 if (phone != null) {
3617 return phone.getCdmaEriIconMode();
3618 } else {
3619 return -1;
3620 }
3621 } finally {
3622 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003623 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003624 }
3625
3626 /**
3627 * Returns the CDMA ERI text,
3628 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003629 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003630 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3631 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3632 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003633 }
3634
Sanket Padawe356d7632015-06-22 14:03:32 -07003635 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003636 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3637 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003638 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003639 mApp, subId, callingPackage, callingFeatureId,
3640 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003641 return null;
3642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643
3644 final long identity = Binder.clearCallingIdentity();
3645 try {
3646 final Phone phone = getPhone(subId);
3647 if (phone != null) {
3648 return phone.getCdmaEriText();
3649 } else {
3650 return null;
3651 }
3652 } finally {
3653 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003655 }
3656
3657 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003658 * Returns the CDMA MDN.
3659 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003660 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003661 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3663 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664
3665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003668 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669 return phone.getLine1Number();
3670 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003671 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672 return null;
3673 }
3674 } finally {
3675 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003676 }
3677 }
3678
3679 /**
3680 * Returns the CDMA MIN.
3681 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003682 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003683 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3685 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 final Phone phone = getPhone(subId);
3690 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3691 return phone.getCdmaMin();
3692 } else {
3693 return null;
3694 }
3695 } finally {
3696 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003697 }
3698 }
3699
Hall Liud892bec2018-11-30 14:51:45 -08003700 @Override
3701 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3702 INumberVerificationCallback callback, String callingPackage) {
3703 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3704 != PERMISSION_GRANTED) {
3705 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3706 }
3707 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3708
3709 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3710 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003711 throw new SecurityException("Calling package must be configured in the device config: "
3712 + "calling package: " + callingPackage
3713 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003714 }
3715
3716 if (range == null) {
3717 throw new NullPointerException("Range must be non-null");
3718 }
3719
3720 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003721 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003722
3723 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3724 }
3725
Junda Liuca05d5d2014-08-14 22:36:34 -07003726 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003727 * Returns true if CDMA provisioning needs to run.
3728 */
3729 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003730 final long identity = Binder.clearCallingIdentity();
3731 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003732 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003733 } finally {
3734 Binder.restoreCallingIdentity(identity);
3735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003736 }
3737
3738 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003739 * Sets the voice mail number of a given subId.
3740 */
3741 @Override
3742 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003743 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3744 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003745
3746 final long identity = Binder.clearCallingIdentity();
3747 try {
3748 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3749 new Pair<String, String>(alphaTag, number), new Integer(subId));
3750 return success;
3751 } finally {
3752 Binder.restoreCallingIdentity(identity);
3753 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003754 }
3755
Ta-wei Yen87c49842016-05-13 21:19:52 -07003756 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003757 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3758 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003759 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3760 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003761 if (!TextUtils.equals(callingPackage, systemDialer)) {
3762 throw new SecurityException("caller must be system dialer");
3763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003764
3765 final long identity = Binder.clearCallingIdentity();
3766 try {
3767 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3768 if (phoneAccountHandle == null) {
3769 return null;
3770 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003771 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772 } finally {
3773 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003774 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003775 }
3776
3777 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003778 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3779 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003780 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003781 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003782 mApp, subId, callingPackage, callingFeatureId,
3783 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003784 return null;
3785 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003786
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003787 final long identity = Binder.clearCallingIdentity();
3788 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003789 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003790 } finally {
3791 Binder.restoreCallingIdentity(identity);
3792 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003793 }
3794
3795 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003796 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3797 VisualVoicemailSmsFilterSettings settings) {
3798 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799
3800 final long identity = Binder.clearCallingIdentity();
3801 try {
3802 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003803 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804 } finally {
3805 Binder.restoreCallingIdentity(identity);
3806 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003807 }
3808
3809 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003810 public void disableVisualVoicemailSmsFilter(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 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
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 Yenb6929602016-05-24 15:48:27 -07003823 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3824 String callingPackage, int subId) {
3825 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826
3827 final long identity = Binder.clearCallingIdentity();
3828 try {
3829 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003830 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831 } finally {
3832 Binder.restoreCallingIdentity(identity);
3833 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003834 }
3835
3836 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003837 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003838 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003839
3840 final long identity = Binder.clearCallingIdentity();
3841 try {
3842 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003843 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003844 } finally {
3845 Binder.restoreCallingIdentity(identity);
3846 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003847 }
3848
3849 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003850 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3851 String callingAttributionTag, int subId, String number, int port, String text,
3852 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003853 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003854 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003855 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003856 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003857 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3858 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003859 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003860
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003861 /**
fionaxu0152e512016-11-14 13:36:14 -08003862 * Sets the voice activation state of a given subId.
3863 */
3864 @Override
3865 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3867 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003868
3869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 final Phone phone = getPhone(subId);
3872 if (phone != null) {
3873 phone.setVoiceActivationState(activationState);
3874 } else {
3875 loge("setVoiceActivationState fails with invalid subId: " + subId);
3876 }
3877 } finally {
3878 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003879 }
3880 }
3881
3882 /**
3883 * Sets the data activation state of a given subId.
3884 */
3885 @Override
3886 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3888 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003889
3890 final long identity = Binder.clearCallingIdentity();
3891 try {
3892 final Phone phone = getPhone(subId);
3893 if (phone != null) {
3894 phone.setDataActivationState(activationState);
3895 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003896 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 }
3898 } finally {
3899 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003900 }
3901 }
3902
3903 /**
3904 * Returns the voice activation state of a given subId.
3905 */
3906 @Override
3907 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003908 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909
fionaxu0152e512016-11-14 13:36:14 -08003910 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003911 final long identity = Binder.clearCallingIdentity();
3912 try {
3913 if (phone != null) {
3914 return phone.getVoiceActivationState();
3915 } else {
3916 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3917 }
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003920 }
3921 }
3922
3923 /**
3924 * Returns the data activation state of a given subId.
3925 */
3926 @Override
3927 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003928 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003929
fionaxu0152e512016-11-14 13:36:14 -08003930 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003931 final long identity = Binder.clearCallingIdentity();
3932 try {
3933 if (phone != null) {
3934 return phone.getDataActivationState();
3935 } else {
3936 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3937 }
3938 } finally {
3939 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003940 }
3941 }
3942
3943 /**
Wink Saville36469e72014-06-11 15:17:00 -07003944 * Returns the unread count of voicemails for a subId
3945 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003946 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003947 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3948 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003949 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003950 mApp, subId, callingPackage, callingFeatureId,
3951 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003952 return 0;
3953 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003954 final long identity = Binder.clearCallingIdentity();
3955 try {
3956 final Phone phone = getPhone(subId);
3957 if (phone != null) {
3958 return phone.getVoiceMessageCount();
3959 } else {
3960 return 0;
3961 }
3962 } finally {
3963 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003964 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003965 }
3966
3967 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003968 * returns true, if the device is in a state where both voice and data
3969 * are supported simultaneously. This can change based on location or network condition.
3970 */
3971 @Override
3972 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 final Phone phone = getPhone(subId);
3976 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3977 } finally {
3978 Binder.restoreCallingIdentity(identity);
3979 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003980 }
3981
3982 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003983 * Send the dialer code if called from the current default dialer or the caller has
3984 * carrier privilege.
3985 * @param inputCode The dialer code to send
3986 */
3987 @Override
3988 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003989 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003990 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003991 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3992 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003993 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003994 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003995 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003997
3998 final long identity = Binder.clearCallingIdentity();
3999 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004000 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004001 } finally {
4002 Binder.restoreCallingIdentity(identity);
4003 }
fionaxu235cc5e2017-03-06 22:25:57 -08004004 }
4005
Pengquan Menga1bb6272018-09-06 09:59:22 -07004006 @Override
4007 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004008 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004009 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004010 mApp, subId, "getNetworkSelectionMode");
4011 final long identity = Binder.clearCallingIdentity();
4012 try {
4013 if (!isActiveSubscription(subId)) {
4014 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4015 }
4016 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004019 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004020 }
4021
Brad Ebinger35c841c2018-10-01 10:40:55 -07004022 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004023 public boolean isInEmergencySmsMode() {
4024 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4025 final long identity = Binder.clearCallingIdentity();
4026 try {
4027 for (Phone phone : PhoneFactory.getPhones()) {
4028 if (phone.isInEmergencySmsMode()) {
4029 return true;
4030 }
4031 }
4032 } finally {
4033 Binder.restoreCallingIdentity(identity);
4034 }
4035 return false;
4036 }
4037
shilu366312e2019-12-17 09:28:10 -08004038 /**
4039 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4040 * @param subId The subscription to use to check the configuration.
4041 * @param c The callback that will be used to send the result.
4042 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004043 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004044 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4045 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004046 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004047 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004048
4049 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4050 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4051 "IMS not available on device.");
4052 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004053 final long token = Binder.clearCallingIdentity();
4054 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004055 int slotId = getSlotIndexOrException(subId);
4056 verifyImsMmTelConfiguredOrThrow(slotId);
4057 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004058 } catch (ImsException e) {
4059 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004060 } finally {
4061 Binder.restoreCallingIdentity(token);
4062 }
4063 }
4064
shilu366312e2019-12-17 09:28:10 -08004065 /**
4066 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4067 * @param subId The subscription to use to check the configuration.
4068 * @param c The callback that will be used to send the result.
4069 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004071 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004072 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004073 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004074 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4075 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4076 }
Meng Wangafbc5852019-09-19 17:37:13 -07004077 final long token = Binder.clearCallingIdentity();
4078 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004079 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4080 .removeRegistrationCallbackForSubscription(c, subId);
4081 } catch (ImsException e) {
4082 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4083 + "is inactive, ignoring unregister.");
4084 // If the subscription is no longer active, just return, since the callback
4085 // will already have been removed internally.
4086 } finally {
4087 Binder.restoreCallingIdentity(token);
4088 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004089 }
4090
Brad Ebingera34a6c22019-10-22 17:36:18 -07004091 /**
4092 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4093 */
4094 @Override
4095 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4096 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4097 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4098 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4099 "IMS not available on device.");
4100 }
4101 final long token = Binder.clearCallingIdentity();
4102 try {
4103 Phone phone = getPhone(subId);
4104 if (phone == null) {
4105 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4106 + subId + "'");
4107 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4108 }
4109 phone.getImsRegistrationState(regState -> {
4110 try {
4111 consumer.accept((regState == null)
4112 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4113 } catch (RemoteException e) {
4114 // Ignore if the remote process is no longer available to call back.
4115 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4116 }
4117 });
4118 } finally {
4119 Binder.restoreCallingIdentity(token);
4120 }
4121 }
4122
4123 /**
4124 * Get the transport type for the IMS service registration state.
4125 */
4126 @Override
4127 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004128 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004129 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004130 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4131 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4132 "IMS not available on device.");
4133 }
4134 final long token = Binder.clearCallingIdentity();
4135 try {
4136 Phone phone = getPhone(subId);
4137 if (phone == null) {
4138 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4139 + subId + "'");
4140 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4141 }
4142 phone.getImsRegistrationTech(regTech -> {
4143 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4144 int regTechConverted = (regTech == null)
4145 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4146 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4147 regTechConverted);
4148 try {
4149 consumer.accept(regTechConverted);
4150 } catch (RemoteException e) {
4151 // Ignore if the remote process is no longer available to call back.
4152 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4153 }
4154 });
4155 } finally {
4156 Binder.restoreCallingIdentity(token);
4157 }
4158 }
4159
shilu366312e2019-12-17 09:28:10 -08004160 /**
4161 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4162 * @param subId The subscription to use to check the configuration.
4163 * @param c The callback that will be used to send the result.
4164 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004165 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004166 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4167 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004168 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004169 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004170 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4171 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4172 "IMS not available on device.");
4173 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004174 final long token = Binder.clearCallingIdentity();
4175 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004176 int slotId = getSlotIndexOrException(subId);
4177 verifyImsMmTelConfiguredOrThrow(slotId);
4178 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004179 } catch (ImsException e) {
4180 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004181 } finally {
4182 Binder.restoreCallingIdentity(token);
4183 }
4184 }
4185
shilu366312e2019-12-17 09:28:10 -08004186 /**
4187 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4188 * @param subId The subscription to use to check the configuration.
4189 * @param c The callback that will be used to send the result.
4190 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004191 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004192 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004193 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004194 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004195 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4196 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4197 }
Meng Wangafbc5852019-09-19 17:37:13 -07004198
4199 final long token = Binder.clearCallingIdentity();
4200 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004201 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004202 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004203 } catch (ImsException e) {
4204 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4205 + "is inactive, ignoring unregister.");
4206 // If the subscription is no longer active, just return, since the callback
4207 // will already have been removed internally.
4208 } finally {
4209 Binder.restoreCallingIdentity(token);
4210 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004211 }
4212
4213 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004214 public boolean isCapable(int subId, int capability, int regTech) {
4215 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 final long token = Binder.clearCallingIdentity();
4217 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004218 int slotId = getSlotIndexOrException(subId);
4219 verifyImsMmTelConfiguredOrThrow(slotId);
4220 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4221 } catch (com.android.ims.ImsException e) {
4222 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4223 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004224 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004225 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4226 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004227 } finally {
4228 Binder.restoreCallingIdentity(token);
4229 }
4230 }
4231
4232 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004233 public boolean isAvailable(int subId, int capability, int regTech) {
4234 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004235 final long token = Binder.clearCallingIdentity();
4236 try {
4237 Phone phone = getPhone(subId);
4238 if (phone == null) return false;
4239 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004240 } catch (com.android.ims.ImsException e) {
4241 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4242 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004243 } finally {
4244 Binder.restoreCallingIdentity(token);
4245 }
4246 }
4247
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004248 /**
4249 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4250 * subscription.
4251 * @param subId The subscription to use to check the configuration.
4252 * @param callback The callback that will be used to send the result.
4253 * @param capability The MmTelFeature capability that will be used to send the result.
4254 * @param transportType The transport type of the MmTelFeature capability.
4255 */
4256 @Override
4257 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4258 int transportType) {
4259 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004260 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4261 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4262 "IMS not available on device.");
4263 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004264 final long token = Binder.clearCallingIdentity();
4265 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004266 int slotId = getSlotIndex(subId);
4267 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4268 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4269 + subId + "'");
4270 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4271 }
4272 verifyImsMmTelConfiguredOrThrow(slotId);
4273 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4274 transportType, aBoolean -> {
4275 try {
4276 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4277 } catch (RemoteException e) {
4278 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4279 + "running. Ignore");
4280 }
4281 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004282 } catch (ImsException e) {
4283 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004284 } finally {
4285 Binder.restoreCallingIdentity(token);
4286 }
4287 }
4288
shilu366312e2019-12-17 09:28:10 -08004289 /**
4290 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4291 * @param subId The subscription to use to check the configuration.
4292 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004293 @Override
4294 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004295 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004296 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004297
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 final long token = Binder.clearCallingIdentity();
4299 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004300 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004301 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004302 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004303 } catch (ImsException e) {
4304 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004305 } finally {
4306 Binder.restoreCallingIdentity(token);
4307 }
4308 }
4309
4310 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004311 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004313 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004314 final long identity = Binder.clearCallingIdentity();
4315 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004316 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004317 // This setting doesn't require an active ImsService connection, so do not verify. The
4318 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004319 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004320 } catch (ImsException e) {
4321 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004322 } finally {
4323 Binder.restoreCallingIdentity(identity);
4324 }
4325 }
4326
shilu366312e2019-12-17 09:28:10 -08004327 /**
4328 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4329 * @param subId The subscription to use to check the configuration.
4330 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004331 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004332 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004333 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004334 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 final long identity = Binder.clearCallingIdentity();
4336 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004337 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004338 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004339 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004340 } catch (ImsException e) {
4341 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004342 } finally {
4343 Binder.restoreCallingIdentity(identity);
4344 }
4345 }
4346
4347 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004348 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004350 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004351 final long identity = Binder.clearCallingIdentity();
4352 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004353 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004354 // This setting doesn't require an active ImsService connection, so do not verify. The
4355 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004356 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004357 } catch (ImsException e) {
4358 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004359 } finally {
4360 Binder.restoreCallingIdentity(identity);
4361 }
4362 }
4363
shilu366312e2019-12-17 09:28:10 -08004364 /**
4365 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4366 * @param subId The subscription to use to check the configuration.
4367 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004368 @Override
4369 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004370 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004371 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 final long identity = Binder.clearCallingIdentity();
4373 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004374 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004375 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004376 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004377 } catch (ImsException e) {
4378 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
4382 }
4383
4384 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004385 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004387 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004388 final long identity = Binder.clearCallingIdentity();
4389 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004390 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004391 // This setting doesn't require an active ImsService connection, so do not verify. The
4392 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004393 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004394 } catch (ImsException e) {
4395 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004396 } finally {
4397 Binder.restoreCallingIdentity(identity);
4398 }
4399 }
4400
shilu366312e2019-12-17 09:28:10 -08004401 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004402 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4403 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4404 * @param subId The subscription to use to check the configuration.
4405 */
4406 @Override
4407 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004408 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004409 mApp, subId, "isCrossSimCallingEnabledByUser");
4410 final long identity = Binder.clearCallingIdentity();
4411 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004412 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004413 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004414 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004415 } catch (ImsException e) {
4416 throw new ServiceSpecificException(e.getCode());
4417 } finally {
4418 Binder.restoreCallingIdentity(identity);
4419 }
4420 }
4421
4422 /**
4423 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4424 * Requires MODIFY_PHONE_STATE permission.
4425 * @param subId The subscription to use to check the configuration.
4426 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4427 * false otherwise
4428 */
4429 @Override
4430 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4432 "setCrossSimCallingEnabled");
4433 final long identity = Binder.clearCallingIdentity();
4434 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004435 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004436 // This setting doesn't require an active ImsService connection, so do not verify. The
4437 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004438 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004439 } catch (ImsException e) {
4440 throw new ServiceSpecificException(e.getCode());
4441 } finally {
4442 Binder.restoreCallingIdentity(identity);
4443 }
4444 }
4445
4446 /**
shilu366312e2019-12-17 09:28:10 -08004447 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4448 * @param subId The subscription to use to check the configuration.
4449 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004450 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004451
Brad Ebinger35c841c2018-10-01 10:40:55 -07004452 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004453 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004454 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004455 final long identity = Binder.clearCallingIdentity();
4456 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004457 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004458 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004459 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004460 } catch (ImsException e) {
4461 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004462 } finally {
4463 Binder.restoreCallingIdentity(identity);
4464 }
4465 }
4466
4467 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004468 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004470 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004471 final long identity = Binder.clearCallingIdentity();
4472 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004473 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004474 // This setting doesn't require an active ImsService connection, so do not verify. The
4475 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004476 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004477 } catch (ImsException e) {
4478 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004479 } finally {
4480 Binder.restoreCallingIdentity(identity);
4481 }
4482 }
4483
4484 @Override
4485 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4487 "setVoWiFiNonPersistent");
4488 final long identity = Binder.clearCallingIdentity();
4489 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004490 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004491 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004492 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004493 } catch (ImsException e) {
4494 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004495 } finally {
4496 Binder.restoreCallingIdentity(identity);
4497 }
4498 }
4499
shilu366312e2019-12-17 09:28:10 -08004500 /**
4501 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4502 * @param subId The subscription to use to check the configuration.
4503 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004504 @Override
4505 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004506 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004507 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004508 final long identity = Binder.clearCallingIdentity();
4509 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004510 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004511 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004512 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004513 } catch (ImsException e) {
4514 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004515 } finally {
4516 Binder.restoreCallingIdentity(identity);
4517 }
4518 }
4519
4520 @Override
4521 public void setVoWiFiModeSetting(int subId, int mode) {
4522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4523 "setVoWiFiModeSetting");
4524 final long identity = Binder.clearCallingIdentity();
4525 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004526 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004527 // This setting doesn't require an active ImsService connection, so do not verify. The
4528 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004529 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004530 } catch (ImsException e) {
4531 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004532 } finally {
4533 Binder.restoreCallingIdentity(identity);
4534 }
4535 }
4536
4537 @Override
4538 public int getVoWiFiRoamingModeSetting(int subId) {
4539 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4540 final long identity = Binder.clearCallingIdentity();
4541 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004542 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004543 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004544 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004545 } catch (ImsException e) {
4546 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004547 } finally {
4548 Binder.restoreCallingIdentity(identity);
4549 }
4550 }
4551
4552 @Override
4553 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4555 "setVoWiFiRoamingModeSetting");
4556 final long identity = Binder.clearCallingIdentity();
4557 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004558 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004559 // This setting doesn't require an active ImsService connection, so do not verify. The
4560 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004561 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004562 } catch (ImsException e) {
4563 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004564 } finally {
4565 Binder.restoreCallingIdentity(identity);
4566 }
4567 }
4568
4569 @Override
4570 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4572 "setRttCapabilityEnabled");
4573 final long identity = Binder.clearCallingIdentity();
4574 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004575 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004576 // This setting doesn't require an active ImsService connection, so do not verify. The
4577 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004578 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004579 } catch (ImsException e) {
4580 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004581 } finally {
4582 Binder.restoreCallingIdentity(identity);
4583 }
4584 }
4585
shilu366312e2019-12-17 09:28:10 -08004586 /**
4587 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4588 * @param subId The subscription to use to check the configuration.
4589 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004590 @Override
4591 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004592 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004593 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004594 final long identity = Binder.clearCallingIdentity();
4595 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004596 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004597 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004598 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004599 } catch (ImsException e) {
4600 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004601 } finally {
4602 Binder.restoreCallingIdentity(identity);
4603 }
4604 }
4605
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004606 @Override
4607 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4608 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004609
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004610 final long identity = Binder.clearCallingIdentity();
4611 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004612 if (!isImsAvailableOnDevice()) {
4613 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4614 "IMS not available on device.");
4615 }
4616 int slotId = getSlotIndexOrException(subId);
4617 verifyImsMmTelConfiguredOrThrow(slotId);
4618 ImsManager.getInstance(mApp, slotId)
4619 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004620 } catch (ImsException e) {
4621 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004622 } finally {
4623 Binder.restoreCallingIdentity(identity);
4624 }
4625 }
4626
4627 @Override
4628 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4629 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004630
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004631 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004632 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4633 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4634 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004635 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004636 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004637 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004638 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004639 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4640 + "is inactive, ignoring unregister.");
4641 // If the subscription is no longer active, just return, since the callback will already
4642 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004643 } finally {
4644 Binder.restoreCallingIdentity(identity);
4645 }
4646 }
4647
joonhunshincffb7fc2021-11-28 07:32:01 +00004648 @Override
4649 public void registerFeatureProvisioningChangedCallback(int subId,
4650 IFeatureProvisioningCallback callback) {
4651 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4652 mApp, subId, "registerFeatureProvisioningChangedCallback");
4653
4654 final long identity = Binder.clearCallingIdentity();
4655 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4656 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4657 }
4658
joonhunshin91bc1952022-04-29 08:47:15 +00004659 try {
4660 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4661 if (controller == null) {
4662 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4663 "Device does not support IMS");
4664 }
4665 controller.addFeatureProvisioningChangedCallback(subId, callback);
4666 } finally {
4667 Binder.restoreCallingIdentity(identity);
4668 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004669 }
4670
4671 @Override
4672 public void unregisterFeatureProvisioningChangedCallback(int subId,
4673 IFeatureProvisioningCallback callback) {
4674 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4675 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4676
4677 final long identity = Binder.clearCallingIdentity();
4678 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4679 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4680 }
4681
joonhunshin91bc1952022-04-29 08:47:15 +00004682 try {
4683 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4684 if (controller == null) {
4685 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4686 return;
4687 }
4688 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4689 } finally {
4690 Binder.restoreCallingIdentity(identity);
4691 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004692 }
allenwtsu99c623b2020-01-03 18:24:23 +08004693
4694 private void checkModifyPhoneStatePermission(int subId, String message) {
4695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4696 message);
4697 }
4698
allenwtsu99c623b2020-01-03 18:24:23 +08004699 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004700 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004701 boolean isProvisioned) {
4702 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4703
4704 final long identity = Binder.clearCallingIdentity();
4705 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004706 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4707 if (controller == null) {
4708 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4709 return;
4710 }
4711 controller.setRcsProvisioningStatusForCapability(
4712 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004713 } finally {
4714 Binder.restoreCallingIdentity(identity);
4715 }
allenwtsu99c623b2020-01-03 18:24:23 +08004716 }
4717
4718
4719 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004720 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4721 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4722 mApp, subId, "getRcsProvisioningStatusForCapability");
4723
allenwtsu99c623b2020-01-03 18:24:23 +08004724 final long identity = Binder.clearCallingIdentity();
4725 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004726 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4727 if (controller == null) {
4728 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4729
4730 // device does not support IMS, this method will return true always.
4731 return true;
4732 }
4733 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004734 } finally {
4735 Binder.restoreCallingIdentity(identity);
4736 }
4737 }
4738
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004739 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004740 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4741 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004742 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004743
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004744 final long identity = Binder.clearCallingIdentity();
4745 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004746 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4747 if (controller == null) {
4748 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4749 return;
4750 }
4751 controller.setImsProvisioningStatusForCapability(
4752 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004753 } finally {
4754 Binder.restoreCallingIdentity(identity);
4755 }
4756 }
4757
4758 @Override
4759 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004760 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4761 mApp, subId, "getProvisioningStatusForCapability");
4762
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004763 final long identity = Binder.clearCallingIdentity();
4764 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004765 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4766 if (controller == null) {
4767 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004768
joonhunshin91bc1952022-04-29 08:47:15 +00004769 // device does not support IMS, this method will return true always.
4770 return true;
4771 }
4772 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004773 } finally {
4774 Binder.restoreCallingIdentity(identity);
4775 }
4776 }
4777
4778 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004779 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4780 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4781 mApp, subId, "isProvisioningRequiredForCapability");
4782
4783 final long identity = Binder.clearCallingIdentity();
4784 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004785 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4786 if (controller == null) {
4787 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4788
4789 // device does not support IMS, this method will return false
4790 return false;
4791 }
4792 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004793 } finally {
4794 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004795 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004796 }
4797
4798 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004799 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4800 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4801 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004802
joonhunshincffb7fc2021-11-28 07:32:01 +00004803 final long identity = Binder.clearCallingIdentity();
4804 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004805 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4806 if (controller == null) {
4807 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4808
4809 // device does not support IMS, this method will return false
4810 return false;
4811 }
4812 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004813 } finally {
4814 Binder.restoreCallingIdentity(identity);
4815 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004816 }
4817
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004818 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004819 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004820 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4821 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4822 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004823 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4824 mApp, subId, "getImsProvisioningInt");
4825
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004826 final long identity = Binder.clearCallingIdentity();
4827 try {
4828 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004829 int slotId = getSlotIndex(subId);
4830 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4831 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4832 + subId + "' for key:" + key);
4833 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4834 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004835
joonhunshin91bc1952022-04-29 08:47:15 +00004836 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4837 if (controller == null) {
4838 loge("getImsProvisioningInt: Device does not support IMS");
4839
4840 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4841 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4842 }
4843 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004844 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4845 return retVal;
4846 }
4847
calvinpanb5a34062021-02-08 19:59:36 +08004848 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004849 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004850 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4851 + subId + "' for key:" + key);
4852 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004853 } finally {
4854 Binder.restoreCallingIdentity(identity);
4855 }
4856 }
4857
4858 @Override
4859 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004860 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4861 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4862 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004863 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4864 mApp, subId, "getImsProvisioningString");
4865
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004866 final long identity = Binder.clearCallingIdentity();
4867 try {
4868 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004869 int slotId = getSlotIndex(subId);
4870 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4871 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4872 + subId + "' for key:" + key);
4873 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4874 }
calvinpanb5a34062021-02-08 19:59:36 +08004875 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004876 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004877 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4878 + subId + "' for key:" + key);
4879 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004880 } finally {
4881 Binder.restoreCallingIdentity(identity);
4882 }
4883 }
4884
4885 @Override
4886 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004887 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4888 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4889 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4891 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004892
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004893 final long identity = Binder.clearCallingIdentity();
4894 try {
4895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004896 int slotId = getSlotIndex(subId);
4897 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4898 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4899 + subId + "' for key:" + key);
4900 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4901 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004902
joonhunshin91bc1952022-04-29 08:47:15 +00004903 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4904 if (controller == null) {
4905 loge("setImsProvisioningInt: Device does not support IMS");
4906
4907 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
4908 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4909 }
4910 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00004911 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4912 return retVal;
4913 }
4914
calvinpanb5a34062021-02-08 19:59:36 +08004915 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4916 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004918 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004919 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004920 } finally {
4921 Binder.restoreCallingIdentity(identity);
4922 }
4923 }
4924
4925 @Override
4926 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4928 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4929 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004930 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4931 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004935 int slotId = getSlotIndex(subId);
4936 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4937 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4938 + subId + "' for key:" + key);
4939 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4940 }
calvinpanb5a34062021-02-08 19:59:36 +08004941 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4942 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004943 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004944 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004945 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004946 } finally {
4947 Binder.restoreCallingIdentity(identity);
4948 }
4949 }
4950
Brad Ebinger919631e2021-06-02 17:46:35 -07004951 /**
4952 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4953 * for the given slot ID or no ImsResolver instance has been created.
4954 * @param slotId The slot ID that the IMS service is created for.
4955 * @throws ImsException If there is no ImsService configured for this slot.
4956 */
4957 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4958 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4959 ImsFeature.FEATURE_MMTEL)) {
4960 throw new ImsException("This subscription does not support MMTEL over IMS",
4961 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4962 }
4963 }
4964
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004965 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004966 int slotId = SubscriptionManager.getSlotIndex(subId);
4967 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004968 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4969 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004970 }
4971 return slotId;
4972 }
4973
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004974 private int getSlotIndex(int subId) {
4975 int slotId = SubscriptionManager.getSlotIndex(subId);
4976 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4977 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4978 }
4979 return slotId;
4980 }
4981
Wink Saville36469e72014-06-11 15:17:00 -07004982 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004983 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004984 */
4985 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004986 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4987 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004988 try {
4989 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4990 } catch (SecurityException se) {
4991 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4992 throw new SecurityException("Package " + callingPackage + " does not belong to "
4993 + Binder.getCallingUid());
4994 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004995 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004996 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004997 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004998 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004999 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005000 mApp, subId, callingPackage, callingFeatureId,
5001 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005002 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5003 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005 final long identity = Binder.clearCallingIdentity();
5006 try {
5007 final Phone phone = getPhone(subId);
5008 if (phone != null) {
5009 return phone.getServiceState().getDataNetworkType();
5010 } else {
5011 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5012 }
5013 } finally {
5014 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005016 }
5017
5018 /**
5019 * Returns the data network type
5020 */
5021 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005022 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005023 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5024 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005025 }
5026
5027 /**
5028 * Returns the data network type for a subId
5029 */
5030 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005031 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5032 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005033 String functionName = "getDataNetworkTypeForSubscriber";
5034 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5035 mApp, functionName)) {
5036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5037 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5038 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5039 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005040 }
5041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042 final long identity = Binder.clearCallingIdentity();
5043 try {
5044 final Phone phone = getPhone(subId);
5045 if (phone != null) {
5046 return phone.getServiceState().getDataNetworkType();
5047 } else {
5048 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5049 }
5050 } finally {
5051 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005053 }
5054
5055 /**
Wink Saville36469e72014-06-11 15:17:00 -07005056 * Returns the Voice network type for a subId
5057 */
5058 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005059 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5060 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005061 String functionName = "getVoiceNetworkTypeForSubscriber";
5062 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5063 mApp, functionName)) {
5064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5065 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5066 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5067 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005068 }
5069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070 final long identity = Binder.clearCallingIdentity();
5071 try {
5072 final Phone phone = getPhone(subId);
5073 if (phone != null) {
5074 return phone.getServiceState().getVoiceNetworkType();
5075 } else {
5076 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5077 }
5078 } finally {
5079 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005081 }
5082
5083 /**
5084 * @return true if a ICC card is present
5085 */
5086 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005087 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005088 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5089 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005090 }
5091
5092 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005093 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005094 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005095 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005096 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097 final long identity = Binder.clearCallingIdentity();
5098 try {
5099 final Phone phone = PhoneFactory.getPhone(slotIndex);
5100 if (phone != null) {
5101 return phone.getIccCard().hasIccCard();
5102 } else {
5103 return false;
5104 }
5105 } finally {
5106 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005108 }
5109
5110 /**
5111 * Return if the current radio is LTE on CDMA. This
5112 * is a tri-state return value as for a period of time
5113 * the mode may be unknown.
5114 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005115 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005116 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005117 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005118 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005119 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005120 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5121 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5122 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005123 }
5124
Sanket Padawe356d7632015-06-22 14:03:32 -07005125 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005126 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5127 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005128 try {
5129 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5130 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005131 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5132 }
5133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 final long identity = Binder.clearCallingIdentity();
5135 try {
5136 final Phone phone = getPhone(subId);
5137 if (phone == null) {
5138 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5139 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005140 return TelephonyProperties.lte_on_cdma_device()
5141 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005142 }
5143 } finally {
5144 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005145 }
Wink Saville36469e72014-06-11 15:17:00 -07005146 }
5147
Wink Saville36469e72014-06-11 15:17:00 -07005148 /**
5149 * {@hide}
5150 * Returns Default subId, 0 in the case of single standby.
5151 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005152 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005153 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005154 }
5155
Shishir Agrawala9f32182016-04-12 12:00:16 -07005156 private int getSlotForDefaultSubscription() {
5157 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5158 }
5159
Wink Savilleb564aae2014-10-23 10:18:09 -07005160 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005161 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005162 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005163
Pengquan Menge92a50d2018-09-21 15:54:48 -07005164 private boolean isActiveSubscription(int subId) {
5165 return mSubscriptionController.isActiveSubId(subId);
5166 }
5167
Ihab Awadf2177b72013-11-25 13:33:23 -08005168 /**
5169 * @see android.telephony.TelephonyManager.WifiCallingChoices
5170 */
5171 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 final long identity = Binder.clearCallingIdentity();
5173 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005174 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005175 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5176 getWhenToMakeWifiCallsDefaultPreference());
5177 } finally {
5178 Binder.restoreCallingIdentity(identity);
5179 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005180 }
5181
5182 /**
5183 * @see android.telephony.TelephonyManager.WifiCallingChoices
5184 */
5185 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005186 final long identity = Binder.clearCallingIdentity();
5187 try {
5188 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005189 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5191 } finally {
5192 Binder.restoreCallingIdentity(identity);
5193 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005194 }
5195
Sailesh Nepald1e68152013-12-12 19:08:02 -08005196 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005197 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005198 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005199 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005200
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005201 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5202 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5203 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005204 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005205 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5206 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005207 }
5208 return PhoneFactory.getPhone(phoneId);
5209 }
5210
Shishir Agrawal566b7612013-10-28 14:41:00 -07005211 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005212 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005213 @NonNull IccLogicalChannelRequest request) {
5214 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5215 /*message=*/ "iccOpenLogicalChannel");
5216
5217 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5218 // Verify that the callingPackage in the request belongs to the calling UID
5219 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5220
5221 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005222 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005223
Rambo Wanga1782702021-11-10 20:15:19 -08005224 private Phone getPhoneFromValidIccLogicalChannelRequest(
5225 @NonNull IccLogicalChannelRequest request, String message) {
5226 Phone phone;
5227 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5229 mApp, request.subId, message);
5230 phone = getPhoneFromSubId(request.subId);
5231 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5232 enforceModifyPermission();
5233 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5234 } else {
5235 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005236 }
Rambo Wanga1782702021-11-10 20:15:19 -08005237 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005238 }
5239
5240 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005241 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 final long identity = Binder.clearCallingIdentity();
5243 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005244 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005246 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5247 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005248 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5249 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 loge("The calling package is not allowed to access ISD-R.");
5251 throw new SecurityException(
5252 "The calling package is not allowed to access ISD-R.");
5253 }
Derek Tan740e1672017-06-27 14:56:27 -07005254 }
Derek Tan740e1672017-06-27 14:56:27 -07005255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005256 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005257 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5258 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005259 return response;
5260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005263 }
5264
5265 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005266 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5267 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5268 /*message=*/"iccCloseLogicalChannel");
5269
5270 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5271
5272 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005273 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005274
Rambo Wanga1782702021-11-10 20:15:19 -08005275 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5276 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005277 // before this feature is enabled, this API should only return false if
5278 // the operation fails instead of throwing runtime exception for
5279 // backward-compatibility.
5280 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5281 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 final long identity = Binder.clearCallingIdentity();
5283 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005284 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005285 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 }
Chen Xue9d737e2022-01-01 23:41:31 -08005287 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005288 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005289 Boolean success = false;
5290 if (result instanceof RuntimeException) {
5291 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005292 if (shouldThrowExceptionOnFailure) {
5293 throw (RuntimeException) result;
5294 } else {
5295 return false;
5296 }
Chen Xue9d737e2022-01-01 23:41:31 -08005297 } else if (result instanceof Boolean) {
5298 success = (Boolean) result;
5299 } else {
5300 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5301 }
Rambo Wanga1782702021-11-10 20:15:19 -08005302 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005303 return success;
5304 } finally {
5305 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005306 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005307 }
5308
5309 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005310 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005311 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5313 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005314 if (DBG) {
5315 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5316 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5317 + p3 + " data=" + data);
5318 }
5319 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5320 command, p1, p2, p3, data);
5321 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005322
Jordan Liu4c733742019-02-28 12:03:40 -08005323 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005324 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5325 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005326 enforceModifyPermission();
5327 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005328 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5329 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5330 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005331 }
5332 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005333 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5334 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005335 }
5336
5337 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5338 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005339 final long identity = Binder.clearCallingIdentity();
5340 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005341 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005342 return "";
5343 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005346 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5347 null /* workSource */);
5348 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350 // Append the returned status code to the end of the response payload.
5351 String s = Integer.toHexString(
5352 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5353 if (response.payload != null) {
5354 s = IccUtils.bytesToHexString(response.payload) + s;
5355 }
5356 return s;
5357 } finally {
5358 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005359 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005360 }
Jake Hambye994d462014-02-03 13:10:13 -08005361
Evan Charltonc66da362014-05-16 14:06:40 -07005362 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005363 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5364 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5366 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005367 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005368 if (DBG) {
5369 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5370 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5371 }
5372 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5373 cla, command, p1, p2, p3, data);
5374 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005375
Jordan Liu4c733742019-02-28 12:03:40 -08005376 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005377 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5378 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005379 enforceModifyPermission();
5380 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5381 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005382 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5383 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5384 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005385 }
5386
5387 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005388 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5389 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005390 }
5391
5392 // open APDU basic channel assuming the caller has sufficient permissions
5393 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5394 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 final long identity = Binder.clearCallingIdentity();
5396 try {
5397 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5398 && TextUtils.equals(ISDR_AID, data)) {
5399 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005400 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5401 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402 if (bestComponent == null
5403 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5404 loge("The calling package is not allowed to select ISD-R.");
5405 throw new SecurityException(
5406 "The calling package is not allowed to select ISD-R.");
5407 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005408 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005409
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005411 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5412 null /* workSource */);
5413 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415 // Append the returned status code to the end of the response payload.
5416 String s = Integer.toHexString(
5417 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5418 if (response.payload != null) {
5419 s = IccUtils.bytesToHexString(response.payload) + s;
5420 }
5421 return s;
5422 } finally {
5423 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005424 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005425 }
5426
5427 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005428 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005429 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5431 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005432
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433 final long identity = Binder.clearCallingIdentity();
5434 try {
5435 if (DBG) {
5436 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5437 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5438 }
5439
5440 IccIoResult response =
5441 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5442 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5443 subId);
5444
5445 if (DBG) {
5446 log("Exchange SIM_IO [R]" + response);
5447 }
5448
5449 byte[] result = null;
5450 int length = 2;
5451 if (response.payload != null) {
5452 length = 2 + response.payload.length;
5453 result = new byte[length];
5454 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5455 } else {
5456 result = new byte[length];
5457 }
5458
5459 result[length - 1] = (byte) response.sw2;
5460 result[length - 2] = (byte) response.sw1;
5461 return result;
5462 } finally {
5463 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005464 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005465 }
5466
Nathan Haroldb3014052017-01-25 15:57:32 -08005467 /**
5468 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5469 * on a particular subscription
5470 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005471 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5472 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005474 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005475 return null;
5476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477
5478 final long identity = Binder.clearCallingIdentity();
5479 try {
5480 if (appType != TelephonyManager.APPTYPE_USIM
5481 && appType != TelephonyManager.APPTYPE_SIM) {
5482 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5483 return null;
5484 }
5485 Object response = sendRequest(
5486 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5487 if (response instanceof String[]) {
5488 return (String[]) response;
5489 }
yincheng zhao2737e882019-09-06 17:06:54 -07005490 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005492 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493 } finally {
5494 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005495 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005496 }
5497
yincheng zhao2737e882019-09-06 17:06:54 -07005498 /**
5499 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5500 * subscription.
5501 *
5502 * @param subId the id of the subscription.
5503 * @param appType the uicc app type, must be USIM or SIM.
5504 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5505 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005506 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005507 * @return number of fplmns that is successfully written to the SIM.
5508 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005509 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5510 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5512 mApp, subId, "setForbiddenPlmns");
5513
yincheng zhao2737e882019-09-06 17:06:54 -07005514 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5515 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5516 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5517 }
5518 if (fplmns == null) {
5519 throw new IllegalArgumentException("Fplmn List provided is null");
5520 }
5521 for (String fplmn : fplmns) {
5522 if (!CellIdentity.isValidPlmn(fplmn)) {
5523 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5524 }
5525 }
5526 final long identity = Binder.clearCallingIdentity();
5527 try {
5528 Object response = sendRequest(
5529 CMD_SET_FORBIDDEN_PLMNS,
5530 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5531 subId);
5532 return (int) response;
5533 } finally {
5534 Binder.restoreCallingIdentity(identity);
5535 }
5536 }
5537
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005538 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005539 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5541 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005542
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 final long identity = Binder.clearCallingIdentity();
5544 try {
5545 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5546 if (response.payload == null) {
5547 return "";
5548 }
Evan Charltonc66da362014-05-16 14:06:40 -07005549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005550 // Append the returned status code to the end of the response payload.
5551 String s = Integer.toHexString(
5552 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5553 s = IccUtils.bytesToHexString(response.payload) + s;
5554 return s;
5555 } finally {
5556 Binder.restoreCallingIdentity(identity);
5557 }
Evan Charltonc66da362014-05-16 14:06:40 -07005558 }
5559
Jake Hambye994d462014-02-03 13:10:13 -08005560 /**
5561 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5562 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5563 *
5564 * @param itemID the ID of the item to read
5565 * @return the NV item as a String, or null on error.
5566 */
5567 @Override
5568 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005569 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5571 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005572
5573 final long identity = Binder.clearCallingIdentity();
5574 try {
5575 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005576 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5578 return value;
5579 } finally {
5580 Binder.restoreCallingIdentity(identity);
5581 }
Jake Hambye994d462014-02-03 13:10:13 -08005582 }
5583
5584 /**
5585 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5586 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5587 *
5588 * @param itemID the ID of the item to read
5589 * @param itemValue the value to write, as a String
5590 * @return true on success; false on any failure
5591 */
5592 @Override
5593 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005594 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5596 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005597
5598 final long identity = Binder.clearCallingIdentity();
5599 try {
5600 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5601 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005602 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5604 return success;
5605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
Jake Hambye994d462014-02-03 13:10:13 -08005608 }
5609
5610 /**
5611 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5612 * Used for device configuration by some CDMA operators.
5613 *
5614 * @param preferredRoamingList byte array containing the new PRL
5615 * @return true on success; false on any failure
5616 */
5617 @Override
5618 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5620 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621
5622 final long identity = Binder.clearCallingIdentity();
5623 try {
5624 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5625 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5626 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5627 return success;
5628 } finally {
5629 Binder.restoreCallingIdentity(identity);
5630 }
Jake Hambye994d462014-02-03 13:10:13 -08005631 }
5632
5633 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005634 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005635 * Used for device configuration by some CDMA operators.
5636 *
chen xu6dac5ab2018-10-26 17:39:23 -07005637 * @param slotIndex - device slot.
5638 *
Jake Hambye994d462014-02-03 13:10:13 -08005639 * @return true on success; false on any failure
5640 */
5641 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005642 public boolean resetModemConfig(int slotIndex) {
5643 Phone phone = PhoneFactory.getPhone(slotIndex);
5644 if (phone != null) {
5645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5646 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005647
chen xu6dac5ab2018-10-26 17:39:23 -07005648 final long identity = Binder.clearCallingIdentity();
5649 try {
5650 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5651 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5652 return success;
5653 } finally {
5654 Binder.restoreCallingIdentity(identity);
5655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656 }
chen xu6dac5ab2018-10-26 17:39:23 -07005657 return false;
5658 }
5659
5660 /**
5661 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5662 *
5663 * @param slotIndex - device slot.
5664 *
5665 * @return true on success; false on any failure
5666 */
5667 @Override
5668 public boolean rebootModem(int slotIndex) {
5669 Phone phone = PhoneFactory.getPhone(slotIndex);
5670 if (phone != null) {
5671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5672 mApp, phone.getSubId(), "rebootModem");
5673
5674 final long identity = Binder.clearCallingIdentity();
5675 try {
5676 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5677 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5678 return success;
5679 } finally {
5680 Binder.restoreCallingIdentity(identity);
5681 }
5682 }
5683 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005684 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005685
Brad Ebinger51f743a2017-01-23 13:50:20 -08005686 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005687 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5688 * {@link #disableIms(int)}.
5689 * @param slotIndex device slot.
5690 */
5691 public void resetIms(int slotIndex) {
5692 enforceModifyPermission();
5693
5694 final long identity = Binder.clearCallingIdentity();
5695 try {
5696 if (mImsResolver == null) {
5697 // may happen if the does not support IMS.
5698 return;
5699 }
5700 mImsResolver.disableIms(slotIndex);
5701 mImsResolver.enableIms(slotIndex);
5702 } finally {
5703 Binder.restoreCallingIdentity(identity);
5704 }
5705 }
5706
5707 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005708 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5709 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005710 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005711 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005712 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713
5714 final long identity = Binder.clearCallingIdentity();
5715 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005716 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005717 // may happen if the device does not support IMS.
5718 return;
5719 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005720 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005721 } finally {
5722 Binder.restoreCallingIdentity(identity);
5723 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005724 }
5725
5726 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005727 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5728 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005729 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005730 public void disableIms(int slotId) {
5731 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732
5733 final long identity = Binder.clearCallingIdentity();
5734 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005735 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005736 // may happen if the device does not support IMS.
5737 return;
5738 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005739 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740 } finally {
5741 Binder.restoreCallingIdentity(identity);
5742 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005743 }
5744
5745 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005746 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5747 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005748 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005749 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005750 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005751 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752
5753 final long identity = Binder.clearCallingIdentity();
5754 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005755 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005756 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5757 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005758 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005759 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760 } finally {
5761 Binder.restoreCallingIdentity(identity);
5762 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005763 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005764 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005765 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5766 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005767 @Override
5768 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005769 enforceModifyPermission();
5770
5771 final long identity = Binder.clearCallingIdentity();
5772 try {
5773 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005774 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
5778 }
5779
5780 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005781 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005782 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005783 */
5784 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5785 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786
5787 final long identity = Binder.clearCallingIdentity();
5788 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005789 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005790 // may happen if the device does not support IMS.
5791 return null;
5792 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005793 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 } finally {
5795 Binder.restoreCallingIdentity(identity);
5796 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005797 }
5798
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005799 /**
5800 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005801 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005802 */
5803 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5804 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805
5806 final long identity = Binder.clearCallingIdentity();
5807 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005808 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005809 // may happen if the device does not support IMS.
5810 return null;
5811 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005812 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813 } finally {
5814 Binder.restoreCallingIdentity(identity);
5815 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005816 }
5817
Brad Ebinger884c07b2018-02-15 16:17:40 -08005818 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005819 * Sets the ImsService Package Name that Telephony will bind to.
5820 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005821 * @param slotIndex the slot ID that the ImsService should bind for.
5822 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005823 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005824 * @param featureTypes An integer array of feature types associated with a packageName.
5825 * @param packageName The name of the package that the current configuration will be replaced
5826 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005827 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005828 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005829 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5830 int[] featureTypes, String packageName) {
5831 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5832 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5834 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005835 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005836
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005837 final long identity = Binder.clearCallingIdentity();
5838 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005839 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005840 // may happen if the device does not support IMS.
5841 return false;
5842 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005843 Map<Integer, String> featureConfig = new HashMap<>();
5844 for (int featureType : featureTypes) {
5845 featureConfig.put(featureType, packageName);
5846 }
5847 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5848 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005849 } finally {
5850 Binder.restoreCallingIdentity(identity);
5851 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005852 }
5853
5854 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005855 * Clears any carrier ImsService overrides for the slot index specified that were previously
5856 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5857 *
5858 * This should only be used for testing.
5859 *
5860 * @param slotIndex the slot ID that the ImsService should bind for.
5861 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5862 */
5863 @Override
5864 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5865 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5866 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5867 "clearCarrierImsServiceOverride");
5868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5869 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5870 "clearCarrierImsServiceOverride");
5871
5872 final long identity = Binder.clearCallingIdentity();
5873 try {
5874 if (mImsResolver == null) {
5875 // may happen if the device does not support IMS.
5876 return false;
5877 }
5878 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5879 } finally {
5880 Binder.restoreCallingIdentity(identity);
5881 }
5882 }
5883
5884 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005885 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005886 *
5887 * @param slotId The slot that the ImsService is associated with.
5888 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5889 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005890 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005891 * @return the package name of the ImsService configuration.
5892 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005893 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5894 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005895 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005896 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005897 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005898 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5899 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901 final long identity = Binder.clearCallingIdentity();
5902 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005903 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005904 // may happen if the device does not support IMS.
5905 return "";
5906 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005907 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005908 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5909 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005910 } finally {
5911 Binder.restoreCallingIdentity(identity);
5912 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005913 }
5914
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005915 /**
5916 * Get the MmTelFeature state associated with the requested subscription id.
5917 * @param subId The subscription that the MmTelFeature is associated with.
5918 * @param callback A callback with an integer containing the
5919 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5920 */
5921 @Override
5922 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5923 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005924 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5925 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5926 "IMS not available on device.");
5927 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005928 final long token = Binder.clearCallingIdentity();
5929 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005930 int slotId = getSlotIndex(subId);
5931 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5932 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5933 + subId + "'");
5934 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5935 }
5936 verifyImsMmTelConfiguredOrThrow(slotId);
5937 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5938 try {
5939 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5940 } catch (RemoteException e) {
5941 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5942 + "Ignore");
5943 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005944 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005945 } catch (ImsException e) {
5946 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005947 } finally {
5948 Binder.restoreCallingIdentity(token);
5949 }
5950 }
5951
Daniel Brightbb5840b2021-01-12 15:48:18 -08005952 /**
5953 * Sets the ims registration state on all valid {@link Phone}s.
5954 */
5955 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005956 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957
5958 final long identity = Binder.clearCallingIdentity();
5959 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005960 // NOTE: Before S, this method only set the default phone.
5961 for (final Phone phone : PhoneFactory.getPhones()) {
5962 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5963 phone.setImsRegistrationState(registered);
5964 }
5965 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966 } finally {
5967 Binder.restoreCallingIdentity(identity);
5968 }
Wink Saville36469e72014-06-11 15:17:00 -07005969 }
5970
5971 /**
Stuart Scott54788802015-03-30 13:18:01 -07005972 * Set the network selection mode to automatic.
5973 *
5974 */
5975 @Override
5976 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5978 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979
5980 final long identity = Binder.clearCallingIdentity();
5981 try {
shilufc958392020-01-20 11:36:01 -08005982 if (!isActiveSubscription(subId)) {
5983 return;
5984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005986 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5987 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 } finally {
5989 Binder.restoreCallingIdentity(identity);
5990 }
Stuart Scott54788802015-03-30 13:18:01 -07005991 }
5992
Jack Yud10cdd42020-09-28 20:28:01 -07005993 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005994 * Ask the radio to connect to the input network and change selection mode to manual.
5995 *
5996 * @param subId the id of the subscription.
5997 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5998 * the operator to attach to.
5999 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6000 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6001 * normal network selection next time.
6002 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006003 */
6004 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006005 public boolean setNetworkSelectionModeManual(
6006 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6008 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006009
6010 if (!isActiveSubscription(subId)) {
6011 return false;
6012 }
6013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 final long identity = Binder.clearCallingIdentity();
6015 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006016 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006018 if (DBG) {
6019 log("setNetworkSelectionModeManual: subId: " + subId
6020 + " operator: " + operatorInfo);
6021 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6023 } finally {
6024 Binder.restoreCallingIdentity(identity);
6025 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006026 }
shilu84f6e8b2019-12-19 13:58:01 -08006027 /**
6028 * Get the manual network selection
6029 *
6030 * @param subId the id of the subscription.
6031 *
6032 * @return the previously saved user selected PLMN
6033 */
6034 @Override
6035 public String getManualNetworkSelectionPlmn(int subId) {
6036 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006037 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006038 mApp, subId, "getManualNetworkSelectionPlmn");
6039
6040 final long identity = Binder.clearCallingIdentity();
6041 try {
6042 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006043 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006044 }
6045
6046 final Phone phone = getPhone(subId);
6047 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006048 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006049 }
6050 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6051 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6052 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6053 } finally {
6054 Binder.restoreCallingIdentity(identity);
6055 }
6056 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006057
6058 /**
6059 * Scans for available networks.
6060 */
6061 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006062 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6063 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6065 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006066 LocationAccessPolicy.LocationPermissionResult locationResult =
6067 LocationAccessPolicy.checkLocationPermission(mApp,
6068 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6069 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006070 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006071 .setCallingPid(Binder.getCallingPid())
6072 .setCallingUid(Binder.getCallingUid())
6073 .setMethod("getCellNetworkScanResults")
6074 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006075 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6076 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006077 .build());
6078 switch (locationResult) {
6079 case DENIED_HARD:
6080 throw new SecurityException("Not allowed to access scan results -- location");
6081 case DENIED_SOFT:
6082 return null;
6083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084
Pengquan Menga1bb6272018-09-06 09:59:22 -07006085 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086 try {
6087 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006088 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090 } finally {
6091 Binder.restoreCallingIdentity(identity);
6092 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006093 }
6094
6095 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006096 * Get the call forwarding info, given the call forwarding reason.
6097 */
6098 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006099 public void getCallForwarding(int subId, int callForwardingReason,
6100 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006101 enforceReadPrivilegedPermission("getCallForwarding");
6102 long identity = Binder.clearCallingIdentity();
6103 try {
6104 if (DBG) {
6105 log("getCallForwarding: subId " + subId
6106 + " callForwardingReason" + callForwardingReason);
6107 }
Hall Liu27d24262020-09-18 19:04:59 -07006108
6109 Phone phone = getPhone(subId);
6110 if (phone == null) {
6111 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006112 callback.onError(
6113 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006114 } catch (RemoteException e) {
6115 // ignore
6116 }
6117 return;
6118 }
6119
6120 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6121 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6122 @Override
6123 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6124 try {
6125 callback.onCallForwardingInfoAvailable(info);
6126 } catch (RemoteException e) {
6127 // ignore
6128 }
6129 }
6130
6131 @Override
6132 public void onError(int error) {
6133 try {
6134 callback.onError(error);
6135 } catch (RemoteException e) {
6136 // ignore
6137 }
6138 }
6139 });
6140 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006141 } finally {
6142 Binder.restoreCallingIdentity(identity);
6143 }
6144 }
6145
6146 /**
6147 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6148 * reason, the number to forward, and the timeout before the forwarding is attempted.
6149 */
6150 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006151 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6152 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006153 enforceModifyPermission();
6154 long identity = Binder.clearCallingIdentity();
6155 try {
6156 if (DBG) {
6157 log("setCallForwarding: subId " + subId
6158 + " callForwardingInfo" + callForwardingInfo);
6159 }
Hall Liu27d24262020-09-18 19:04:59 -07006160
6161 Phone phone = getPhone(subId);
6162 if (phone == null) {
6163 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006164 callback.accept(
6165 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006166 } catch (RemoteException e) {
6167 // ignore
6168 }
6169 return;
6170 }
6171
6172 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6173 FunctionalUtils.ignoreRemoteException(callback::accept));
6174
6175 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006176 } finally {
6177 Binder.restoreCallingIdentity(identity);
6178 }
6179 }
6180
6181 /**
Hall Liu27d24262020-09-18 19:04:59 -07006182 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006183 */
6184 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006185 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006186 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006187 long identity = Binder.clearCallingIdentity();
6188 try {
Hall Liu27d24262020-09-18 19:04:59 -07006189 Phone phone = getPhone(subId);
6190 if (phone == null) {
6191 try {
6192 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6193 } catch (RemoteException e) {
6194 // ignore
6195 }
6196 return;
6197 }
SongFerngWang0e767992021-03-31 22:08:45 +08006198 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6199 PersistableBundle c = configManager.getConfigForSubId(subId);
6200 boolean requireUssd = c.getBoolean(
6201 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006202
Shuo Qian4a594052020-01-23 11:59:30 -08006203 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006204 if (requireUssd) {
6205 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6206 getSubscriptionCarrierId(subId));
6207 String newUssdCommand = "";
6208 try {
6209 newUssdCommand = carrierXmlParser.getFeature(
6210 CarrierXmlParser.FEATURE_CALL_WAITING)
6211 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6212 } catch (NullPointerException e) {
6213 loge("Failed to generate USSD number" + e);
6214 }
6215 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6216 mMainThreadHandler, callback, carrierXmlParser,
6217 CarrierXmlParser.SsEntry.SSAction.QUERY);
6218 final String ussdCommand = newUssdCommand;
6219 Executors.newSingleThreadExecutor().execute(() -> {
6220 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6221 });
6222 } else {
6223 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6224 callback::accept);
6225 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6226 }
Shuo Qian4a594052020-01-23 11:59:30 -08006227 } finally {
6228 Binder.restoreCallingIdentity(identity);
6229 }
6230 }
6231
6232 /**
Hall Liu27d24262020-09-18 19:04:59 -07006233 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006234 */
6235 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006236 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006237 enforceModifyPermission();
6238 long identity = Binder.clearCallingIdentity();
6239 try {
Hall Liu27d24262020-09-18 19:04:59 -07006240 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6241
6242 Phone phone = getPhone(subId);
6243 if (phone == null) {
6244 try {
6245 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6246 } catch (RemoteException e) {
6247 // ignore
6248 }
6249 return;
6250 }
6251
SongFerngWang0e767992021-03-31 22:08:45 +08006252 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6253 PersistableBundle c = configManager.getConfigForSubId(subId);
6254 boolean requireUssd = c.getBoolean(
6255 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006256
SongFerngWang0e767992021-03-31 22:08:45 +08006257 if (DBG) log("getCallWaitingStatus: subId " + subId);
6258 if (requireUssd) {
6259 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6260 getSubscriptionCarrierId(subId));
6261 CarrierXmlParser.SsEntry.SSAction ssAction =
6262 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6263 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6264 String newUssdCommand = "";
6265 try {
6266 newUssdCommand = carrierXmlParser.getFeature(
6267 CarrierXmlParser.FEATURE_CALL_WAITING)
6268 .makeCommand(ssAction, null);
6269 } catch (NullPointerException e) {
6270 loge("Failed to generate USSD number" + e);
6271 }
6272 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6273 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6274 final String ussdCommand = newUssdCommand;
6275 Executors.newSingleThreadExecutor().execute(() -> {
6276 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6277 });
6278 } else {
6279 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6280 FunctionalUtils.ignoreRemoteException(callback::accept));
6281
6282 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6283 }
Shuo Qian4a594052020-01-23 11:59:30 -08006284 } finally {
6285 Binder.restoreCallingIdentity(identity);
6286 }
6287 }
6288
6289 /**
yinxub1bed742017-04-17 11:45:04 -07006290 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006291 *
yinxub1bed742017-04-17 11:45:04 -07006292 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006293 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6294 * location related information which will be sent if the caller already possess
6295 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006296 * @param request contains the radio access networks with bands/channels to scan
6297 * @param messenger callback messenger for scan results or errors
6298 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006299 * @return the id of the requested scan which can be used to stop the scan.
6300 */
6301 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006302 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6303 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006304 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6306 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006307 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006308 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6309 if (!renounceFineLocationAccess) {
6310 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6311 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6312 .setCallingPackage(callingPackage)
6313 .setCallingFeatureId(callingFeatureId)
6314 .setCallingPid(Binder.getCallingPid())
6315 .setCallingUid(Binder.getCallingUid())
6316 .setMethod("requestNetworkScan")
6317 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6318 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6319 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6320 .build());
6321 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006322 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006323 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6324 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006325 if (e != null) {
6326 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6327 throw e;
6328 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006329 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006330 return TelephonyScanManager.INVALID_SCAN_ID;
6331 }
6332 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333 }
Hall Liu912dfd32019-04-25 14:02:26 -07006334 int callingUid = Binder.getCallingUid();
6335 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006336 final long identity = Binder.clearCallingIdentity();
6337 try {
6338 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006339 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006340 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006341 } finally {
6342 Binder.restoreCallingIdentity(identity);
6343 }
yinxu504e1392017-04-12 16:03:22 -07006344 }
6345
Hall Liub2ac8ef2019-02-28 15:56:23 -08006346 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006347 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wangaccdabf2022-10-20 16:52:29 +00006348 boolean hasCarrierPriv;
6349 final long identity = Binder.clearCallingIdentity();
6350 try {
6351 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6352 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6353 } finally {
6354 Binder.restoreCallingIdentity(identity);
6355 }
Hall Liu558027f2019-05-15 19:14:05 -07006356 boolean hasNetworkScanPermission =
6357 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6358 == PERMISSION_GRANTED;
6359
6360 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6361 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6362 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006363 }
6364
6365 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6366 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006367 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6368 return new SecurityException("Specific channels must not be"
6369 + " scanned without location access.");
6370 }
6371 }
6372 }
6373
Hall Liub2ac8ef2019-02-28 15:56:23 -08006374 return null;
6375 }
6376
yinxu504e1392017-04-12 16:03:22 -07006377 /**
6378 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006379 *
6380 * @param subId id of the subscription
6381 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006382 */
6383 @Override
6384 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6386 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387
Hall Liu912dfd32019-04-25 14:02:26 -07006388 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389 final long identity = Binder.clearCallingIdentity();
6390 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006391 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006392 } finally {
6393 Binder.restoreCallingIdentity(identity);
6394 }
yinxu504e1392017-04-12 16:03:22 -07006395 }
6396
6397 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006398 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006399 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006400 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006401 */
6402 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006403 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006404 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006405 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006406 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407
6408 final long identity = Binder.clearCallingIdentity();
6409 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006410 if (DBG) log("getAllowedNetworkTypesBitmask");
6411 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6412 int networkTypesBitmask = (result != null ? result[0] : -1);
6413 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6414 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415 } finally {
6416 Binder.restoreCallingIdentity(identity);
6417 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006418 }
6419
6420 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006421 * Get the allowed network types for certain reason.
6422 *
6423 * @param subId the id of the subscription.
6424 * @param reason the reason the allowed network type change is taking place
6425 * @return the allowed network types.
6426 */
6427 @Override
6428 public long getAllowedNetworkTypesForReason(int subId,
6429 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006430 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006431 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006432 final long identity = Binder.clearCallingIdentity();
6433 try {
6434 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6435 } finally {
6436 Binder.restoreCallingIdentity(identity);
6437 }
6438 }
6439
6440 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006441 * Enable/Disable E-UTRA-NR Dual Connectivity
6442 * @param subId subscription id of the sim card
6443 * @param nrDualConnectivityState expected NR dual connectivity state
6444 * This can be passed following states
6445 * <ol>
6446 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6447 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6448 * <li>Disable NR dual connectivity and force secondary cell to be released
6449 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6450 * </ol>
6451 * @return operation result.
6452 */
6453 @Override
6454 public int setNrDualConnectivityState(int subId,
6455 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6457 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006458 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006459 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6460 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6461 }
6462
Sooraj Sasindran37444802020-08-11 10:40:43 -07006463 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6464 final long identity = Binder.clearCallingIdentity();
6465 try {
6466 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6467 nrDualConnectivityState, subId,
6468 workSource);
6469 if (DBG) log("enableNRDualConnectivity result: " + result);
6470 return result;
6471 } finally {
6472 Binder.restoreCallingIdentity(identity);
6473 }
6474 }
6475
6476 /**
6477 * Is E-UTRA-NR Dual Connectivity enabled
6478 * @return true if dual connectivity is enabled else false
6479 */
6480 @Override
6481 public boolean isNrDualConnectivityEnabled(int subId) {
6482 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006483 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006484 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006485 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006486 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6487 return false;
6488 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006489 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6490 final long identity = Binder.clearCallingIdentity();
6491 try {
6492 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6493 null, subId, workSource);
6494 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6495 return isEnabled;
6496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
6499 }
6500
6501 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006502 * Set the allowed network types of the device and
6503 * provide the reason triggering the allowed network change.
6504 *
6505 * @param subId the id of the subscription.
6506 * @param reason the reason the allowed network type change is taking place
6507 * @param allowedNetworkTypes the allowed network types.
6508 * @return true on success; false on any failure.
6509 */
6510 @Override
6511 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006512 @TelephonyManager.AllowedNetworkTypesReason int reason,
6513 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6515 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006516 // If the caller only has carrier privileges, then they should not be able to override
6517 // any network types which were set for security reasons.
6518 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6519 != PERMISSION_GRANTED
6520 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6521 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6522 throw new SecurityException(
6523 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6524 + " reason "
6525 + reason);
6526 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006527 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006528 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6529 return false;
6530 }
6531 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6532 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006533 return false;
6534 }
6535
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006536 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6537 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6538
6539
6540 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6541 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6542 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006543 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006544
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006545 final long identity = Binder.clearCallingIdentity();
6546 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006547 Boolean success = (Boolean) sendRequest(
6548 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6549 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6550
6551 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6552 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006553 } finally {
6554 Binder.restoreCallingIdentity(identity);
6555 }
6556 }
6557
6558 /**
Miaoa84611c2019-03-15 09:21:10 +08006559 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006560 *
Miaoa84611c2019-03-15 09:21:10 +08006561 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006562 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006563 * @hide
6564 */
6565 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006566 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006569 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570 try {
Miaoa84611c2019-03-15 09:21:10 +08006571 if (phone != null) {
6572 return phone.hasMatchedTetherApnSetting();
6573 } else {
6574 return false;
6575 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006576 } finally {
6577 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006578 }
Junda Liu475951f2014-11-07 16:45:03 -08006579 }
6580
6581 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006582 * Get the user enabled state of Mobile Data.
6583 *
6584 * TODO: remove and use isUserDataEnabled.
6585 * This can't be removed now because some vendor codes
6586 * calls through ITelephony directly while they should
6587 * use TelephonyManager.
6588 *
6589 * @return true on enabled
6590 */
6591 @Override
6592 public boolean getDataEnabled(int subId) {
6593 return isUserDataEnabled(subId);
6594 }
6595
6596 /**
6597 * Get whether mobile data is enabled per user setting.
6598 *
6599 * There are other factors deciding whether mobile data is actually enabled, but they are
6600 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006601 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006602 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6603 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006604 *
6605 * @return {@code true} if data is enabled else {@code false}
6606 */
6607 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006608 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006609 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006610 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006611 try {
6612 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6613 functionName);
6614 } catch (Exception e) {
6615 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6616 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006617 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006619 mApp, subId, functionName);
6620
Robert Greenwalt646120a2014-05-23 11:54:03 -07006621 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622
6623 final long identity = Binder.clearCallingIdentity();
6624 try {
6625 int phoneId = mSubscriptionController.getPhoneId(subId);
6626 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6627 Phone phone = PhoneFactory.getPhone(phoneId);
6628 if (phone != null) {
6629 boolean retVal = phone.isUserDataEnabled();
6630 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6631 return retVal;
6632 } else {
6633 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6634 return false;
6635 }
6636 } finally {
6637 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006638 }
6639 }
6640
6641 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006642 * Checks if the device is capable of mobile data by considering whether whether the
6643 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6644 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006645 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006646 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006647 */
6648 @Override
6649 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006650 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006651 try {
6652 try {
6653 mApp.enforceCallingOrSelfPermission(
6654 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006655 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006656 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006657 try {
6658 mApp.enforceCallingOrSelfPermission(
6659 android.Manifest.permission.READ_PHONE_STATE,
6660 functionName);
6661 } catch (Exception e2) {
6662 mApp.enforceCallingOrSelfPermission(
6663 permission.READ_BASIC_PHONE_STATE, functionName);
6664 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006665 }
6666 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006667 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006668 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669
6670 final long identity = Binder.clearCallingIdentity();
6671 try {
6672 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006673 Phone phone = PhoneFactory.getPhone(phoneId);
6674 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006675 boolean retVal;
6676 if (phone.isUsingNewDataStack()) {
Sarah Chin2c094c52022-03-09 13:57:52 -08006677 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006678 } else {
6679 retVal = phone.getDataEnabledSettings().isDataEnabled();
6680 }
6681 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006682 return retVal;
6683 } else {
6684 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6685 return false;
6686 }
6687 } finally {
6688 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006689 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006690 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006691
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006692 /**
6693 * Check if data is enabled for a specific reason
6694 * @param subId Subscription index
6695 * @param reason the reason the data enable change is taking place
6696 * @return {@code true} if the overall data is enabled; {@code false} if not.
6697 */
6698 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006699 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006700 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006701 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006702 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006703 try {
6704 mApp.enforceCallingOrSelfPermission(
6705 android.Manifest.permission.ACCESS_NETWORK_STATE,
6706 functionName);
6707 } catch (Exception e) {
6708 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6709 functionName);
6710 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006711 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006712 try {
6713 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006714 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006715 } catch (Exception e2) {
6716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006717 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006718 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006719 }
6720
6721
6722 final long identity = Binder.clearCallingIdentity();
6723 try {
6724 int phoneId = mSubscriptionController.getPhoneId(subId);
6725 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006726 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006727 + " reason=" + reason);
6728 }
6729 Phone phone = PhoneFactory.getPhone(phoneId);
6730 if (phone != null) {
6731 boolean retVal;
Jack Yu99e87332021-12-17 23:14:15 -08006732 if (phone.isUsingNewDataStack()) {
6733 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006734 } else {
Jack Yu99e87332021-12-17 23:14:15 -08006735 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6736 retVal = phone.isUserDataEnabled();
6737 } else {
6738 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6739 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006740 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006741 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006742 return retVal;
6743 } else {
6744 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006745 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006746 + subId + " retVal=false");
6747 }
6748 return false;
6749 }
6750 } finally {
6751 Binder.restoreCallingIdentity(identity);
6752 }
6753 }
6754
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006755 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006756 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006757 // No permission needed; this only lets the caller inspect their own status.
6758 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006759 }
Junda Liu29340342014-07-10 15:23:27 -07006760
6761 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006762 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006763 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006764 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6765 }
6766
6767 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6768 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006769 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006770 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006771 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6772 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006773 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6774 if (cpt == null) {
6775 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006776 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6777 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006778 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006779 }
6780
6781 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006782 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006783 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006784 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006785 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006786 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006787 Phone phone = getPhone(subId);
6788 if (phone == null) {
6789 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6790 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6791 }
6792 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6793 if (cpt == null) {
6794 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006795 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6796 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006797 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006798 }
6799
6800 @Override
6801 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006802 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006803 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6804 }
6805
6806 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006807 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006808 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006809 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006810 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006811 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6812 Phone phone = PhoneFactory.getPhone(phoneId);
6813 if (phone == null) {
6814 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006815 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006816 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6817 if (cpt == null) {
6818 continue;
6819 }
6820 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006821 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6822 break;
6823 }
6824 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006825 return result;
Junda Liu29340342014-07-10 15:23:27 -07006826 }
Derek Tan89e89d42014-07-08 17:00:10 -07006827
6828 @Override
Junda Liue64de782015-04-16 17:19:16 -07006829 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006830 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006831 Phone phone = PhoneFactory.getPhone(phoneId);
6832 if (phone == null) {
6833 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006834 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006835 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6836 if (cpt == null) {
6837 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006838 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006839 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006840 }
6841
Amith Yamasani6e118872016-02-19 12:53:51 -08006842 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006843 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006844 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006845 Phone phone = PhoneFactory.getPhone(phoneId);
6846 if (phone == null) {
6847 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006848 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006849 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6850 if (cpt == null) {
6851 return Collections.emptyList();
6852 }
6853 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006854 }
6855
chen xuf7e9fe82019-05-09 19:31:02 -07006856 @Override
6857 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006858 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006859 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006860 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006861 try {
6862 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6863 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6864 }
6865 } finally {
6866 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006867 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006868 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006869 }
6870
Rambo Wang6812ffb2022-03-15 16:54:17 -07006871 @Override
6872 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6873 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6874
6875 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6876 if (phone == null) {
6877 return null;
6878 }
6879 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6880 if (cpt == null) {
6881 return null;
6882 }
6883 return cpt.getCarrierServicePackageName();
6884 }
6885
Wink Savilleb564aae2014-10-23 10:18:09 -07006886 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006887 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006888 UiccPort port = phone == null ? null : phone.getUiccPort();
6889 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006890 return null;
6891 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006892 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006893 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006894 return null;
6895 }
6896 return iccId;
6897 }
6898
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006899 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006900 public void setCallComposerStatus(int subId, int status) {
6901 enforceModifyPermission();
6902
6903 final long identity = Binder.clearCallingIdentity();
6904 try {
6905 Phone phone = getPhone(subId);
6906 if (phone != null) {
6907 Phone defaultPhone = phone.getImsPhone();
6908 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6909 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6910 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006911 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6912 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006913 }
6914 }
Shuo Qian284ae752020-12-22 19:10:14 -08006915 } catch (ImsException e) {
6916 throw new ServiceSpecificException(e.getCode());
6917 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006918 Binder.restoreCallingIdentity(identity);
6919 }
6920 }
6921
6922 @Override
6923 public int getCallComposerStatus(int subId) {
6924 enforceReadPrivilegedPermission("getCallComposerStatus");
6925
6926 final long identity = Binder.clearCallingIdentity();
6927 try {
6928 Phone phone = getPhone(subId);
6929 if (phone != null) {
6930 Phone defaultPhone = phone.getImsPhone();
6931 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6932 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6933 return imsPhone.getCallComposerStatus();
6934 }
6935 }
6936 } finally {
6937 Binder.restoreCallingIdentity(identity);
6938 }
6939 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6940 }
6941
6942 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006943 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6944 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006945 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006946 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006948 final long identity = Binder.clearCallingIdentity();
6949 try {
6950 final String iccId = getIccId(subId);
6951 final Phone phone = getPhone(subId);
6952 if (phone == null) {
6953 return false;
6954 }
6955 final String subscriberId = phone.getSubscriberId();
6956
6957 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006958 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006959 + subscriberId + " to " + number);
6960 }
6961
6962 if (TextUtils.isEmpty(iccId)) {
6963 return false;
6964 }
6965
6966 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6967
6968 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6969 if (alphaTag == null) {
6970 editor.remove(alphaTagPrefKey);
6971 } else {
6972 editor.putString(alphaTagPrefKey, alphaTag);
6973 }
6974
6975 // Record both the line number and IMSI for this ICCID, since we need to
6976 // track all merged IMSIs based on line number
6977 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6978 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6979 if (number == null) {
6980 editor.remove(numberPrefKey);
6981 editor.remove(subscriberPrefKey);
6982 } else {
6983 editor.putString(numberPrefKey, number);
6984 editor.putString(subscriberPrefKey, subscriberId);
6985 }
6986
6987 editor.commit();
6988 return true;
6989 } finally {
6990 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006991 }
Derek Tan7226c842014-07-02 17:42:23 -07006992 }
6993
6994 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006995 public String getLine1NumberForDisplay(int subId, String callingPackage,
6996 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006997 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006998 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006999 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007000 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007001 return null;
7002 }
Derek Tan97ebb422014-09-05 16:55:38 -07007003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004 final long identity = Binder.clearCallingIdentity();
7005 try {
7006 String iccId = getIccId(subId);
7007 if (iccId != null) {
7008 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7009 if (DBG_MERGE) {
7010 log("getLine1NumberForDisplay returning "
7011 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7012 }
7013 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007014 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007015 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7016 return null;
7017 } finally {
7018 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007019 }
Derek Tan7226c842014-07-02 17:42:23 -07007020 }
7021
7022 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007023 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7024 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007025 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007026 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007027 return null;
7028 }
Derek Tan97ebb422014-09-05 16:55:38 -07007029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007030 final long identity = Binder.clearCallingIdentity();
7031 try {
7032 String iccId = getIccId(subId);
7033 if (iccId != null) {
7034 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7035 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7036 }
7037 return null;
7038 } finally {
7039 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007040 }
Derek Tan7226c842014-07-02 17:42:23 -07007041 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007042
7043 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007044 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7045 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007046 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7047 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007048 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007049 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007050 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007051 return null;
7052 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007053
Jordan Liub49b04b2019-05-06 14:45:15 -07007054 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7055 // the process, where TelephonyManager was instantiated.
7056 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007057 final long identity = Binder.clearCallingIdentity();
7058 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007059 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007060 final TelephonyManager tele = TelephonyManager.from(context);
7061 final SubscriptionManager sub = SubscriptionManager.from(context);
7062
7063 // Figure out what subscribers are currently active
7064 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007065
Jordan Liub49b04b2019-05-06 14:45:15 -07007066 // Only consider subs which match the current subId
7067 // This logic can be simplified. See b/131189269 for progress.
7068 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007069 activeSubscriberIds.add(tele.getSubscriberId(subId));
7070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071
7072 // First pass, find a number override for an active subscriber
7073 String mergeNumber = null;
7074 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7075 for (String key : prefs.keySet()) {
7076 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7077 final String subscriberId = (String) prefs.get(key);
7078 if (activeSubscriberIds.contains(subscriberId)) {
7079 final String iccId = key.substring(
7080 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7081 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7082 mergeNumber = (String) prefs.get(numberKey);
7083 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007084 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007085 + " for active subscriber " + subscriberId);
7086 }
7087 if (!TextUtils.isEmpty(mergeNumber)) {
7088 break;
7089 }
7090 }
7091 }
7092 }
7093
7094 // Shortcut when no active merged subscribers
7095 if (TextUtils.isEmpty(mergeNumber)) {
7096 return null;
7097 }
7098
7099 // Second pass, find all subscribers under that line override
7100 final ArraySet<String> result = new ArraySet<>();
7101 for (String key : prefs.keySet()) {
7102 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7103 final String number = (String) prefs.get(key);
7104 if (mergeNumber.equals(number)) {
7105 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7106 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7107 final String subscriberId = (String) prefs.get(subscriberKey);
7108 if (!TextUtils.isEmpty(subscriberId)) {
7109 result.add(subscriberId);
7110 }
7111 }
7112 }
7113 }
7114
7115 final String[] resultArray = result.toArray(new String[result.size()]);
7116 Arrays.sort(resultArray);
7117 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007118 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7120 }
7121 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007122 } finally {
7123 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007124 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007125 }
7126
7127 @Override
zoey chen38003472019-12-13 17:16:31 +08007128 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7129 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007130
7131 final long identity = Binder.clearCallingIdentity();
7132 try {
7133 final TelephonyManager telephonyManager = mApp.getSystemService(
7134 TelephonyManager.class);
7135 String subscriberId = telephonyManager.getSubscriberId(subId);
7136 if (subscriberId == null) {
7137 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007138 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007139 + subId);
7140 }
7141 return null;
7142 }
7143
7144 final SubscriptionInfo info = SubscriptionController.getInstance()
7145 .getSubscriptionInfo(subId);
7146 final ParcelUuid groupUuid = info.getGroupUuid();
7147 // If it doesn't belong to any group, return just subscriberId of itself.
7148 if (groupUuid == null) {
7149 return new String[]{subscriberId};
7150 }
7151
7152 // Get all subscriberIds from the group.
7153 final List<String> mergedSubscriberIds = new ArrayList<>();
7154 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007155 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007156 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007157 for (SubscriptionInfo subInfo : groupInfos) {
7158 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7159 if (subscriberId != null) {
7160 mergedSubscriberIds.add(subscriberId);
7161 }
7162 }
7163
7164 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7165 } finally {
7166 Binder.restoreCallingIdentity(identity);
7167
7168 }
7169 }
7170
7171 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007172 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007173 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007174 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007175
7176 final long identity = Binder.clearCallingIdentity();
7177 try {
7178 final Phone phone = getPhone(subId);
7179 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
7182 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007183 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007184
7185 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007186 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007187 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7188 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007189 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7190 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191
7192 final long identity = Binder.clearCallingIdentity();
7193 try {
7194 final Phone phone = getPhone(subId);
7195 if (phone == null) {
7196 return false;
7197 }
7198 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7199 cdmaNonRoamingList);
7200 } finally {
7201 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007202 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007203 }
7204
7205 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007206 @Deprecated
7207 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7208 enforceModifyPermission();
7209
7210 int returnValue = 0;
7211 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007212 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007213 if(result.exception == null) {
7214 if (result.result != null) {
7215 byte[] responseData = (byte[])(result.result);
7216 if(responseData.length > oemResp.length) {
7217 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7218 responseData.length + "bytes. Buffer Size is " +
7219 oemResp.length + "bytes.");
7220 }
7221 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7222 returnValue = responseData.length;
7223 }
7224 } else {
7225 CommandException ex = (CommandException) result.exception;
7226 returnValue = ex.getCommandError().ordinal();
7227 if(returnValue > 0) returnValue *= -1;
7228 }
7229 } catch (RuntimeException e) {
7230 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7231 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7232 if(returnValue > 0) returnValue *= -1;
7233 }
7234
7235 return returnValue;
7236 }
7237
7238 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007239 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007240 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007241 try {
7242 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007243 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007244 mApp, phone.getSubId(), "getRadioAccessFamily");
7245 } catch (SecurityException e) {
7246 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7247 throw e;
7248 }
chen xub97461a2018-10-26 14:17:57 -07007249 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007250 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007251 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007252 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253 final long identity = Binder.clearCallingIdentity();
7254 try {
chen xub97461a2018-10-26 14:17:57 -07007255 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007256 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007257 mApp, phone.getSubId(), "getRadioAccessFamily");
7258 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259 } finally {
7260 Binder.restoreCallingIdentity(identity);
7261 }
chen xub97461a2018-10-26 14:17:57 -07007262 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007263 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007264
7265 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007266 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007267 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007268 try {
7269 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7270 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007271 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007272 }
7273 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007274 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007275 }
7276 RoleManager rm = mApp.getSystemService(RoleManager.class);
7277 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7278 if (!dialerRoleHolders.contains(callingPackage)) {
7279 throw new SecurityException("App must be the dialer role holder to"
7280 + " upload a call composer pic");
7281 }
7282
7283 Executors.newSingleThreadExecutor().execute(() -> {
7284 ByteArrayOutputStream output = new ByteArrayOutputStream(
7285 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7286 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7287 boolean readUntilEnd = false;
7288 int totalBytesRead = 0;
7289 byte[] buffer = new byte[16 * 1024];
7290 while (true) {
7291 int numRead;
7292 try {
7293 numRead = input.read(buffer);
7294 } catch (IOException e) {
7295 try {
7296 fd.checkError();
7297 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7298 null);
7299 } catch (IOException e1) {
7300 // This means that the other side closed explicitly with an error. If this
7301 // happens, log and ignore.
7302 loge("Remote end of call composer picture pipe closed: " + e1);
7303 }
7304 break;
7305 }
7306 if (numRead == -1) {
7307 readUntilEnd = true;
7308 break;
7309 }
7310 totalBytesRead += numRead;
7311 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7312 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7313 try {
7314 input.close();
7315 } catch (IOException e) {
7316 // ignore
7317 }
7318 break;
7319 }
7320 output.write(buffer, 0, numRead);
7321 }
7322 // Generally, the remote end will close the file descriptors. The only case where we
7323 // close is above, where the picture size is too big.
7324
7325 try {
7326 fd.checkError();
7327 } catch (IOException e) {
7328 loge("Remote end for call composer closed with an error: " + e);
7329 return;
7330 }
7331
Hall Liuaa4211e2021-01-20 15:43:39 -08007332 if (!readUntilEnd) {
7333 loge("Did not finish reading entire image; aborting");
7334 return;
7335 }
Hall Liu82694d52020-12-11 18:22:04 -08007336
Hall Liuaa4211e2021-01-20 15:43:39 -08007337 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7338 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7339 new CallComposerPictureTransfer.Factory() {},
7340 imageData,
7341 (result) -> {
7342 if (result.first != null) {
7343 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7344 Bundle outputResult = new Bundle();
7345 outputResult.putParcelable(
7346 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7347 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7348 outputResult);
7349 } else {
7350 callback.send(result.second, null);
7351 }
7352 }
7353 );
Hall Liu82694d52020-12-11 18:22:04 -08007354 });
7355 }
7356
7357 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007358 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007359 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007360 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007361
7362 final long identity = Binder.clearCallingIdentity();
7363 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007364 ImsManager.getInstance(defaultPhone.getContext(),
7365 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 } finally {
7367 Binder.restoreCallingIdentity(identity);
7368 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007369 }
7370
7371 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007372 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007373 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7375 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007376 return false;
7377 }
Svet Ganovb320e182015-04-16 12:30:10 -07007378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379 final long identity = Binder.clearCallingIdentity();
7380 try {
7381 // Check the user preference and the system-level IMS setting. Even if the user has
7382 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7383 // In the long run, we may instead need to check if there exists a connection service
7384 // which can support video calling.
7385 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007386 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387 return imsManager.isVtEnabledByPlatform()
7388 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7389 && imsManager.isVtEnabledByUser();
7390 } finally {
7391 Binder.restoreCallingIdentity(identity);
7392 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007393 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007394
Andrew Leea1239f22015-03-02 17:44:07 -08007395 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007396 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7397 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007399 mApp, subId, callingPackage, callingFeatureId,
7400 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007401 return false;
7402 }
7403
7404 final long identity = Binder.clearCallingIdentity();
7405 try {
7406 CarrierConfigManager configManager =
7407 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007408 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007409 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7410 } finally {
7411 Binder.restoreCallingIdentity(identity);
7412 }
Andrew Leea1239f22015-03-02 17:44:07 -08007413 }
7414
7415 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007416 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007418 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419 return false;
7420 }
7421
7422 final long identity = Binder.clearCallingIdentity();
7423 try {
7424 CarrierConfigManager configManager =
7425 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007426 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7428 } finally {
7429 Binder.restoreCallingIdentity(identity);
7430 }
Andrew Leea1239f22015-03-02 17:44:07 -08007431 }
7432
Andrew Lee9431b832015-03-09 18:46:45 -07007433 @Override
7434 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007435 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007436 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007437 }
7438
7439 @Override
7440 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 final long identity = Binder.clearCallingIdentity();
7442 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007443 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 } finally {
7445 Binder.restoreCallingIdentity(identity);
7446 }
Andrew Lee9431b832015-03-09 18:46:45 -07007447 }
7448
Hall Liuf6668912018-10-31 17:05:23 -07007449 /**
7450 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7451 * support for the feature and device firmware support.
7452 *
7453 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7454 */
7455 @Override
7456 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007457 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007458 final Phone phone = getPhone(subscriptionId);
7459 if (phone == null) {
7460 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7461 return false;
7462 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007464 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7466 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007467 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 return isCarrierSupported && isDeviceSupported;
7469 } finally {
7470 Binder.restoreCallingIdentity(identity);
7471 }
Hall Liu98187582018-01-22 19:15:32 -08007472 }
7473
Hall Liuf6668912018-10-31 17:05:23 -07007474 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007475 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7476 * RTT setting, will return true if the device and carrier both support RTT.
7477 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007478 */
7479 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 final long identity = Binder.clearCallingIdentity();
7481 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007482 boolean isRttSupported = isRttSupported(subscriptionId);
7483 boolean isUserRttSettingOn = Settings.Secure.getInt(
7484 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7485 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7486 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7487 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 } finally {
7489 Binder.restoreCallingIdentity(identity);
7490 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007491 }
7492
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007493 @Deprecated
7494 @Override
7495 public String getDeviceId(String callingPackage) {
7496 return getDeviceIdWithFeature(callingPackage, null);
7497 }
7498
Sanket Padawe7310cc72015-01-14 09:53:20 -08007499 /**
7500 * Returns the unique device ID of phone, for example, the IMEI for
7501 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7502 *
7503 * <p>Requires Permission:
7504 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7505 */
7506 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007507 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007508 try {
7509 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7510 } catch (SecurityException se) {
7511 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7512 throw new SecurityException("Package " + callingPackage + " does not belong to "
7513 + Binder.getCallingUid());
7514 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007515 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007516 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007517 return null;
7518 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007519 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007520 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007521 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007522 return null;
7523 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524
7525 final long identity = Binder.clearCallingIdentity();
7526 try {
7527 return phone.getDeviceId();
7528 } finally {
7529 Binder.restoreCallingIdentity(identity);
7530 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007531 }
7532
Ping Sunc67b7c22016-03-02 19:16:45 +08007533 /**
7534 * {@hide}
7535 * Returns the IMS Registration Status on a particular subid
7536 *
7537 * @param subId
7538 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007539 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007540 Phone phone = getPhone(subId);
7541 if (phone != null) {
7542 return phone.isImsRegistered();
7543 } else {
7544 return false;
7545 }
7546 }
7547
Santos Cordon7a1885b2015-02-03 11:15:19 -08007548 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007549 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007550 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007551 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007552 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007553 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7554 }
7555 final long identity = Binder.clearCallingIdentity();
7556 try {
7557 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7558 } finally {
7559 Binder.restoreCallingIdentity(identity);
7560 }
7561 }
7562
7563 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007564 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007565 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007566 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007567 mApp,
7568 subscriptionId,
7569 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007570 final long identity = Binder.clearCallingIdentity();
7571 try {
7572 Phone phone = getPhone(subscriptionId);
7573 if (phone == null) {
7574 return null;
7575 }
7576 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7577 } finally {
7578 Binder.restoreCallingIdentity(identity);
7579 }
7580 }
7581
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007582 /**
7583 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007584 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007585 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007586 final long identity = Binder.clearCallingIdentity();
7587 try {
7588 Phone phone = getPhone(subId);
7589 if (phone != null) {
7590 return phone.isWifiCallingEnabled();
7591 } else {
7592 return false;
7593 }
7594 } finally {
7595 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007596 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007597 }
7598
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007599 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007600 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007601 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007602 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007603 final long identity = Binder.clearCallingIdentity();
7604 try {
7605 Phone phone = getPhone(subId);
7606 if (phone != null) {
7607 return phone.isVideoEnabled();
7608 } else {
7609 return false;
7610 }
7611 } finally {
7612 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007613 }
7614 }
7615
7616 /**
7617 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7618 * defined in {@link ImsRegistrationImplBase}.
7619 */
7620 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007621 final long identity = Binder.clearCallingIdentity();
7622 try {
7623 Phone phone = getPhone(subId);
7624 if (phone != null) {
7625 return phone.getImsRegistrationTech();
7626 } else {
7627 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7628 }
7629 } finally {
7630 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007631 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007632 }
7633
Stuart Scott8eef64f2015-04-08 15:13:54 -07007634 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007635 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007636 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007637 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7638 return;
7639 }
Kai Shif70f46f2021-03-03 13:59:46 -08007640 Phone defaultPhone = getDefaultPhone();
7641 if (defaultPhone != null) {
7642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7643 mApp, getDefaultPhone().getSubId(), "factoryReset");
7644 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007645 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007646
Svet Ganovcc087f82015-05-12 20:35:54 -07007647 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007648 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7649 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007650 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007651 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007652 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007653 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007654 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007655 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007656 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007657 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007658 // There has been issues when Sms raw table somehow stores orphan
7659 // fragments. They lead to garbled message when new fragments come
7660 // in and combined with those stale ones. In case this happens again,
7661 // user can reset all network settings which will clean up this table.
7662 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007663 // Clean up IMS settings as well here.
7664 int slotId = getSlotIndex(subId);
7665 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7666 ImsManager.getInstance(mApp, slotId).factoryReset();
7667 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007668
Kai Shif70f46f2021-03-03 13:59:46 -08007669 if (defaultPhone == null) {
7670 return;
7671 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007672 // Erase modem config if erase modem on network setting is enabled.
7673 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7674 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7675 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007676 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007677 }
Kai Shif70f46f2021-03-03 13:59:46 -08007678
7679 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007680 } finally {
7681 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007682 }
7683 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007684
SongFerngWangfd89b102021-05-27 22:44:54 +08007685 @VisibleForTesting
7686 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7687 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7688 return;
7689 }
7690 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7691 RILConstants.PREFERRED_NETWORK_MODE);
7692 SubscriptionManager.setSubscriptionProperty(subId,
7693 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7694 "user=" + defaultNetworkType);
7695 phone.loadAllowedNetworksFromSubscriptionDatabase();
7696 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7697 defaultNetworkType, null);
7698 }
7699
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007700 private void cleanUpSmsRawTable(Context context) {
7701 ContentResolver resolver = context.getContentResolver();
7702 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7703 resolver.delete(uri, null, null);
7704 }
7705
Narayan Kamath1c496c22015-04-16 14:40:19 +01007706 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007707 public String getSimLocaleForSubscriber(int subId) {
7708 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7709 final Phone phone = getPhone(subId);
7710 if (phone == null) {
7711 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007712 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007713 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007714 final long identity = Binder.clearCallingIdentity();
7715 try {
chen xu5d3637b2019-01-21 23:31:38 -08007716 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007717 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007718 if (info == null) {
7719 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7720 return null;
7721 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 // Try and fetch the locale from the carrier properties or from the SIM language
7723 // preferences (EF-PL and EF-LI)...
7724 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007725 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007726 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7727 if (localeFromDefaultSim != null) {
7728 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7729 if (DBG) log("Using locale from subId: " + subId + " locale: "
7730 + localeFromDefaultSim);
tom hsu0b59d292022-09-29 23:49:21 +08007731 return matchLocaleFromSupportedLocaleList(localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007732 } else {
7733 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 }
7735 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007736
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007737 // The SIM language preferences only store a language (e.g. fr = French), not an
7738 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7739 // the SIM and carrier preferences does not include a country we add the country
7740 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007741 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007742 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007743 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu0b59d292022-09-29 23:49:21 +08007744 return matchLocaleFromSupportedLocaleList(mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007745 }
7746
7747 if (DBG) log("No locale found - returning null");
7748 return null;
7749 } finally {
7750 Binder.restoreCallingIdentity(identity);
7751 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007752 }
7753
tom hsu0b59d292022-09-29 23:49:21 +08007754 @VisibleForTesting
7755 String matchLocaleFromSupportedLocaleList(@NonNull Locale inputLocale) {
7756 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
7757 getDefaultPhone().getContext());
7758 for (String localeTag : supportedLocale) {
7759 if (LocaleList.matchesLanguageAndScript(
7760 inputLocale, Locale.forLanguageTag(localeTag))
7761 && inputLocale.getCountry().equals(
7762 Locale.forLanguageTag(localeTag).getCountry())) {
7763 return localeTag;
7764 }
7765 }
7766 return inputLocale.toLanguageTag();
7767 }
7768
Narayan Kamath1c496c22015-04-16 14:40:19 +01007769 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007770 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007771 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007772 }
7773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007774 /**
7775 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7776 */
7777 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007778 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007779 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007780 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007781
Gary Jian3aa9a762022-01-24 16:41:19 +08007782 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7783 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007784
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007785 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007786 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7787 * representing the state of the modem.
7788 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007789 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7790 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007791 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007792 */
7793 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007794 public void requestModemActivityInfo(ResultReceiver result) {
7795 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007796 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797
7798 final long identity = Binder.clearCallingIdentity();
7799 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007800 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 } finally {
7802 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007803 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007804 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007805
Siddharth Rayb8114062018-06-17 15:02:38 -07007806 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7807 // less than total activity duration.
7808 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7809 if (info == null) {
7810 return false;
7811 }
7812 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007813 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7814 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7815
Siddharth Rayb8114062018-06-17 15:02:38 -07007816 return (info.isValid()
7817 && (info.getSleepTimeMillis() <= activityDurationMs)
7818 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007819 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007820 && (totalTxTimeMs <= activityDurationMs));
7821 }
7822
Gary Jian3aa9a762022-01-24 16:41:19 +08007823 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7824 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7825 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7826 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7827
7828 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7829 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7830 }
7831
7832 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7833 mLastModemActivityInfo.setReceiveTimeMillis(
7834 rat,
7835 freq,
7836 info.getReceiveTimeMillis(rat, freq)
7837 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7838 }
7839
7840 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7841 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7842 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7843 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7844
7845 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7846 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7847 }
7848 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7849 mLastModemActivityInfo.setReceiveTimeMillis(
7850 rat,
7851 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7852 }
7853
7854 /**
7855 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7856 * @param info recent ModemActivityInfo
7857 */
7858 private void mergeModemActivityInfo(ModemActivityInfo info) {
7859 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08007860 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08007861 boolean matched;
7862 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7863 matched = false;
7864 int rat = info.getSpecificInfoRat(i);
7865 int freq = info.getSpecificInfoFrequencyRange(i);
7866 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7867 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7868 //if it already exists
7869 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7870 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7871 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7872 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7873 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7874 updateLastModemActivityInfo(info, rat, freq);
7875 matched = true;
7876 }
7877 } else {
7878 updateLastModemActivityInfo(info, rat);
7879 matched = true;
7880 }
7881 }
7882 }
7883
7884 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08007885 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08007886 new ActivityStatsTechSpecificInfo(
7887 rat,
7888 freq,
7889 info.getTransmitTimeMillis(rat, freq),
7890 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08007891 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08007892 }
7893 }
7894 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7895 mLastModemActivitySpecificInfo =
7896 new ActivityStatsTechSpecificInfo[merged.size()];
7897 merged.toArray(mLastModemActivitySpecificInfo);
7898
7899 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7900 mLastModemActivityInfo.setSleepTimeMillis(
7901 info.getSleepTimeMillis()
7902 + mLastModemActivityInfo.getSleepTimeMillis());
7903 mLastModemActivityInfo.setIdleTimeMillis(
7904 info.getIdleTimeMillis()
7905 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08007906
7907 mLastModemActivityInfo =
7908 new ModemActivityInfo(
7909 mLastModemActivityInfo.getTimestampMillis(),
7910 mLastModemActivityInfo.getSleepTimeMillis(),
7911 mLastModemActivityInfo.getIdleTimeMillis(),
7912 mLastModemActivitySpecificInfo);
7913 }
7914
7915 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
7916 ActivityStatsTechSpecificInfo[] info) {
7917 int infoSize = info.length;
7918 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
7919 for (int i = 0; i < infoSize; i++) {
7920 ret[i] = new ActivityStatsTechSpecificInfo(
7921 info[i].getRat(), info[i].getFrequencyRange(),
7922 info[i].getTransmitTimeMillis(),
7923 (int) info[i].getReceiveTimeMillis());
7924 }
7925 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08007926 }
7927
Jack Yu85bd38a2015-11-09 11:34:32 -08007928 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007929 * Returns the service state information on specified subscription.
7930 */
7931 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007932 public ServiceState getServiceStateForSubscriber(int subId,
7933 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7934 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007936 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007937 return null;
7938 }
7939
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007940 boolean hasFinePermission = false;
7941 boolean hasCoarsePermission = false;
7942 if (!renounceFineLocationAccess) {
7943 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7944 LocationAccessPolicy.checkLocationPermission(mApp,
7945 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7946 .setCallingPackage(callingPackage)
7947 .setCallingFeatureId(callingFeatureId)
7948 .setCallingPid(Binder.getCallingPid())
7949 .setCallingUid(Binder.getCallingUid())
7950 .setMethod("getServiceStateForSubscriber")
7951 .setLogAsInfo(true)
7952 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7953 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7954 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7955 .build());
7956 hasFinePermission =
7957 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7958 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007959
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007960 if (!renounceCoarseLocationAccess) {
7961 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7962 LocationAccessPolicy.checkLocationPermission(mApp,
7963 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7964 .setCallingPackage(callingPackage)
7965 .setCallingFeatureId(callingFeatureId)
7966 .setCallingPid(Binder.getCallingPid())
7967 .setCallingUid(Binder.getCallingUid())
7968 .setMethod("getServiceStateForSubscriber")
7969 .setLogAsInfo(true)
7970 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7971 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7972 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7973 .build());
7974 hasCoarsePermission =
7975 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7976 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007977
Jack Yu479f40e2020-10-27 21:29:25 -07007978 final Phone phone = getPhone(subId);
7979 if (phone == null) {
7980 return null;
7981 }
7982
Jordan Liu0f2bc442020-11-18 16:47:37 -08007983 final long identity = Binder.clearCallingIdentity();
7984
Jack Yu479f40e2020-10-27 21:29:25 -07007985 boolean isCallingPackageDataService = phone.getDataServicePackages()
7986 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007988 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7989 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7990 Rlog.d(LOG_TAG,
7991 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7992 return null;
7993 }
7994
Hall Liuf19c44f2018-11-27 14:38:17 -08007995 ServiceState ss = phone.getServiceState();
7996
7997 // Scrub out the location info in ServiceState depending on what level of access
7998 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007999 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008000 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8001 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008002 } finally {
8003 Binder.restoreCallingIdentity(identity);
8004 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008005 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008006
8007 /**
8008 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8009 *
8010 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8011 * voicemail ringtone.
8012 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8013 * PhoneAccount.
8014 */
8015 @Override
8016 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008017 final long identity = Binder.clearCallingIdentity();
8018 try {
8019 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8020 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008021 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008022 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8025 } finally {
8026 Binder.restoreCallingIdentity(identity);
8027 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008028 }
8029
8030 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008031 * Sets the per-account voicemail ringtone.
8032 *
8033 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8034 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8035 *
8036 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8037 * voicemail ringtone.
8038 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8039 * PhoneAccount.
8040 */
8041 @Override
8042 public void setVoicemailRingtoneUri(String callingPackage,
8043 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008044 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008045 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008046 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8047 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8049 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8050 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008051 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008052
8053 final long identity = Binder.clearCallingIdentity();
8054 try {
8055 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8056 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008057 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008058 }
8059 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8060 } finally {
8061 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008062 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008063 }
8064
8065 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008066 * Returns whether vibration is set for voicemail notification in Phone settings.
8067 *
8068 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8069 * voicemail vibration setting.
8070 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8071 */
8072 @Override
8073 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008074 final long identity = Binder.clearCallingIdentity();
8075 try {
8076 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8077 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008078 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008079 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8082 } finally {
8083 Binder.restoreCallingIdentity(identity);
8084 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008085 }
8086
Youhan Wange64578a2016-05-02 15:32:42 -07008087 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008088 * Sets the per-account voicemail vibration.
8089 *
8090 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8091 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8092 *
8093 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8094 * voicemail vibration setting.
8095 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8096 * specific PhoneAccount.
8097 */
8098 @Override
8099 public void setVoicemailVibrationEnabled(String callingPackage,
8100 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008101 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008102 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008103 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8104 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8106 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8107 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008108 }
8109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008110 final long identity = Binder.clearCallingIdentity();
8111 try {
8112 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8113 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008114 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008115 }
8116 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8117 } finally {
8118 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008119 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008120 }
8121
8122 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008123 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8124 *
8125 * @throws SecurityException if the caller does not have the required permission
8126 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008127 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008128 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008129 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008130 }
8131
8132 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008133 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8134 * permission.
8135 *
8136 * @throws SecurityException if the caller does not have the required permission
8137 */
8138 private void enforceSendSmsPermission() {
8139 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8140 }
8141
8142 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008143 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008144 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008145 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008146 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008147 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008148 final long identity = Binder.clearCallingIdentity();
8149 try {
8150 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008151 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008152 if (componentName == null) {
8153 throw new SecurityException(
8154 "Caller not current active visual voicemail package[null]");
8155 }
8156 String vvmPackage = componentName.getPackageName();
8157 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008158 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008159 }
8160 } finally {
8161 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008162 }
8163 }
8164
8165 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008166 * Return the application ID for the app type.
8167 *
8168 * @param subId the subscription ID that this request applies to.
8169 * @param appType the uicc app type.
8170 * @return Application ID for specificied app type, or null if no uicc.
8171 */
8172 @Override
8173 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008174 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008175 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008176
8177 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008178 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008179 if (phone == null) {
8180 return null;
8181 }
8182 String aid = null;
8183 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008184 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008185 .getApplicationByType(appType).getAid();
8186 } catch (Exception e) {
8187 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8188 }
8189 return aid;
8190 } finally {
8191 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008192 }
Youhan Wange64578a2016-05-02 15:32:42 -07008193 }
8194
Youhan Wang4001d252016-05-11 10:29:41 -07008195 /**
8196 * Return the Electronic Serial Number.
8197 *
8198 * @param subId the subscription ID that this request applies to.
8199 * @return ESN or null if error.
8200 */
8201 @Override
8202 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008203 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008204 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008205
8206 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008207 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008208 if (phone == null) {
8209 return null;
8210 }
8211 String esn = null;
8212 try {
8213 esn = phone.getEsn();
8214 } catch (Exception e) {
8215 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8216 }
8217 return esn;
8218 } finally {
8219 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008220 }
Youhan Wang4001d252016-05-11 10:29:41 -07008221 }
8222
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008223 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008224 * Return the Preferred Roaming List Version.
8225 *
8226 * @param subId the subscription ID that this request applies to.
8227 * @return PRLVersion or null if error.
8228 */
8229 @Override
8230 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008231 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008232 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233
8234 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008235 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236 if (phone == null) {
8237 return null;
8238 }
8239 String cdmaPrlVersion = null;
8240 try {
8241 cdmaPrlVersion = phone.getCdmaPrlVersion();
8242 } catch (Exception e) {
8243 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8244 }
8245 return cdmaPrlVersion;
8246 } finally {
8247 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008248 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008249 }
8250
8251 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008252 * Get snapshot of Telephony histograms
8253 * @return List of Telephony histograms
8254 * @hide
8255 */
8256 @Override
8257 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8259 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008260
8261 final long identity = Binder.clearCallingIdentity();
8262 try {
8263 return RIL.getTelephonyRILTimingHistograms();
8264 } finally {
8265 Binder.restoreCallingIdentity(identity);
8266 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008267 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008268
8269 /**
8270 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008271 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8272 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008273 * Require system privileges. In the future we may add this to carrier APIs.
8274 *
Michele Berionne482f8202018-11-27 18:57:59 -08008275 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008276 */
8277 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008278 @TelephonyManager.SetCarrierRestrictionResult
8279 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008280 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008281 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008282
Michele Berionne482f8202018-11-27 18:57:59 -08008283 if (carrierRestrictionRules == null) {
8284 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008285 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008286
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008287 final long identity = Binder.clearCallingIdentity();
8288 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008289 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008290 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008291 } finally {
8292 Binder.restoreCallingIdentity(identity);
8293 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008294 }
8295
8296 /**
8297 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008298 * Get the allowed carrier list and the excluded carrier list, including the priority between
8299 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008300 * Require system privileges. In the future we may add this to carrier APIs.
8301 *
Michele Berionne482f8202018-11-27 18:57:59 -08008302 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008303 */
8304 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008305 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008306 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008307 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008308
8309 final long identity = Binder.clearCallingIdentity();
8310 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008311 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8312 if (response instanceof CarrierRestrictionRules) {
8313 return (CarrierRestrictionRules) response;
8314 }
8315 // Response is an Exception of some kind,
8316 // which is signalled to the user as a NULL retval
8317 return null;
8318 } catch (Exception e) {
8319 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8320 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008321 } finally {
8322 Binder.restoreCallingIdentity(identity);
8323 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008324 }
8325
fionaxu59545b42016-05-25 15:53:37 -07008326 /**
fionaxu59545b42016-05-25 15:53:37 -07008327 * Action set from carrier signalling broadcast receivers to enable/disable radio
8328 * @param subId the subscription ID that this action applies to.
8329 * @param enabled control enable or disable radio.
8330 * {@hide}
8331 */
8332 @Override
8333 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8334 enforceModifyPermission();
8335 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336
8337 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008338 if (phone == null) {
8339 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8340 return;
8341 }
8342 try {
8343 phone.carrierActionSetRadioEnabled(enabled);
8344 } catch (Exception e) {
8345 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008346 } finally {
8347 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008348 }
8349 }
8350
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008351 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008352 * Enable or disable Voice over NR (VoNR)
8353 * @param subId the subscription ID that this action applies to.
8354 * @param enabled enable or disable VoNR.
8355 * @return operation result.
8356 */
8357 @Override
8358 public int setVoNrEnabled(int subId, boolean enabled) {
8359 enforceModifyPermission();
8360 final Phone phone = getPhone(subId);
8361
8362 final long identity = Binder.clearCallingIdentity();
8363 if (phone == null) {
8364 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8365 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8366 }
8367
8368 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8369 try {
8370 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8371 workSource);
8372 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008373
8374 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8375 if (DBG) {
8376 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8377 }
8378 SubscriptionManager.setSubscriptionProperty(
8379 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8380 (enabled ? "1" : "0"));
8381 }
8382
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008383 return result;
8384 } finally {
8385 Binder.restoreCallingIdentity(identity);
8386 }
8387 }
8388
8389 /**
8390 * Is voice over NR enabled
8391 * @return true if VoNR is enabled else false
8392 */
8393 @Override
8394 public boolean isVoNrEnabled(int subId) {
8395 enforceReadPrivilegedPermission("isVoNrEnabled");
8396 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8397 final long identity = Binder.clearCallingIdentity();
8398 try {
8399 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8400 null, subId, workSource);
8401 if (DBG) log("isVoNrEnabled: " + isEnabled);
8402 return isEnabled;
8403 } finally {
8404 Binder.restoreCallingIdentity(identity);
8405 }
8406 }
8407
8408 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008409 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8410 * network status based on which carrier apps could apply actions accordingly,
8411 * enable/disable default url handler for example.
8412 *
8413 * @param subId the subscription ID that this action applies to.
8414 * @param report control start/stop reporting the default network status.
8415 * {@hide}
8416 */
8417 @Override
8418 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8419 enforceModifyPermission();
8420 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008421
8422 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008423 if (phone == null) {
8424 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8425 return;
8426 }
8427 try {
8428 phone.carrierActionReportDefaultNetworkStatus(report);
8429 } catch (Exception e) {
8430 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008431 } finally {
8432 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008433 }
8434 }
8435
8436 /**
fionaxud9622282017-07-17 17:51:30 -07008437 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8438 * @param subId the subscription ID that this action applies to.
8439 * {@hide}
8440 */
8441 @Override
8442 public void carrierActionResetAll(int subId) {
8443 enforceModifyPermission();
8444 final Phone phone = getPhone(subId);
8445 if (phone == null) {
8446 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8447 return;
8448 }
8449 try {
8450 phone.carrierActionResetAll();
8451 } catch (Exception e) {
8452 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8453 }
8454 }
8455
8456 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008457 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8458 * bug report is being generated.
8459 */
8460 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008461 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008462 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8463 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008464 writer.println("Permission Denial: can't dump Phone from pid="
8465 + Binder.getCallingPid()
8466 + ", uid=" + Binder.getCallingUid()
8467 + "without permission "
8468 + android.Manifest.permission.DUMP);
8469 return;
8470 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008471 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008472 }
Jack Yueb89b242016-06-22 13:27:47 -07008473
Brad Ebingerdac2f002018-04-03 15:17:52 -07008474 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008475 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8476 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8477 @NonNull String[] args) {
8478 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8479 this, in.getFileDescriptor(), out.getFileDescriptor(),
8480 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008481 }
8482
Jack Yueb89b242016-06-22 13:27:47 -07008483 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008484 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008485 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008486 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008487 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008488 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008489 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008490 */
8491 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008492 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008493 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008494 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8495 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8496 try {
8497 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008498 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008499 } catch (SecurityException se) {
8500 enforceModifyPermission();
8501 }
8502 } else {
8503 enforceModifyPermission();
8504 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008505
8506 final long identity = Binder.clearCallingIdentity();
8507 try {
8508 Phone phone = getPhone(subId);
8509 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008510 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8511 phone.carrierActionSetMeteredApnsEnabled(enabled);
8512 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008513 if (phone.isUsingNewDataStack()) {
Sarah Chinecc78c42022-03-31 21:16:48 -07008514 phone.getDataSettingsManager().setDataEnabled(
8515 reason, enabled, callingPackage);
Jack Yu99e87332021-12-17 23:14:15 -08008516 } else {
8517 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8518 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008520 }
8521 } finally {
8522 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008523 }
8524 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008525
8526 /**
8527 * Get Client request stats
8528 * @return List of Client Request Stats
8529 * @hide
8530 */
8531 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008532 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8533 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008535 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008536 return null;
8537 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008538 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008540 final long identity = Binder.clearCallingIdentity();
8541 try {
8542 if (phone != null) {
8543 return phone.getClientRequestStats();
8544 }
8545
8546 return null;
8547 } finally {
8548 Binder.restoreCallingIdentity(identity);
8549 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008550 }
8551
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008552 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008553 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008554 if (uid == Process.ROOT_UID && packageName == null) {
8555 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8556 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8557 // exception. ROOT_UID seems not to have a valid package name returned by
8558 // PackageManager, so just fake it here to avoid issues when running telephony shell
8559 // commands that plumb through the RIL as root, like so:
8560 // $ adb root
8561 // $ adb shell cmd phone ...
8562 packageName = "root";
8563 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008564 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008565 }
Jack Yueb4124c2017-02-16 15:32:43 -08008566
8567 /**
Grace Chen70990072017-03-24 17:21:30 -07008568 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008569 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008570 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008571 * @param state State of SIM (power down, power up, pass through)
8572 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8573 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8574 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008575 *
8576 **/
8577 @Override
Grace Chen70990072017-03-24 17:21:30 -07008578 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008579 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008580 Phone phone = PhoneFactory.getPhone(slotIndex);
8581
vagdeviaf9a5b92018-08-15 16:01:53 -07008582 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8583
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008584 final long identity = Binder.clearCallingIdentity();
8585 try {
8586 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008587 phone.setSimPowerState(state, null, workSource);
8588 }
8589 } finally {
8590 Binder.restoreCallingIdentity(identity);
8591 }
8592 }
8593
8594 /**
8595 * Set SIM card power state.
8596 *
8597 * @param slotIndex SIM slot id.
8598 * @param state State of SIM (power down, power up, pass through)
8599 * @param callback callback to trigger after success or failure
8600 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8601 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8602 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8603 *
8604 **/
8605 @Override
8606 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8607 IIntegerConsumer callback) {
8608 enforceModifyPermission();
8609 Phone phone = PhoneFactory.getPhone(slotIndex);
8610
8611 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8612
8613 final long identity = Binder.clearCallingIdentity();
8614 try {
8615 if (phone != null) {
8616 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8617 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008618 }
8619 } finally {
8620 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008621 }
8622 }
Shuo Qiandd210312017-04-12 22:11:33 +00008623
Tyler Gunn65d45c22017-06-05 11:22:26 -07008624 private boolean isUssdApiAllowed(int subId) {
8625 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008626 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008627 if (configManager == null) {
8628 return false;
8629 }
8630 PersistableBundle pb = configManager.getConfigForSubId(subId);
8631 if (pb == null) {
8632 return false;
8633 }
8634 return pb.getBoolean(
8635 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8636 }
8637
Shuo Qiandd210312017-04-12 22:11:33 +00008638 /**
8639 * Check if phone is in emergency callback mode
8640 * @return true if phone is in emergency callback mode
8641 * @param subId sub id
8642 */
goneil9c5f4872017-12-05 14:07:56 -08008643 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008644 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008645 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008646 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008647
8648 final long identity = Binder.clearCallingIdentity();
8649 try {
8650 if (phone != null) {
8651 return phone.isInEcm();
8652 } else {
8653 return false;
8654 }
8655 } finally {
8656 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008657 }
8658 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008659
8660 /**
8661 * Get the current signal strength information for the given subscription.
8662 * Because this information is not updated when the device is in a low power state
8663 * it should not be relied-upon to be current.
8664 * @param subId Subscription index
8665 * @return the most recent cached signal strength info from the modem
8666 */
8667 @Override
8668 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008669 final long identity = Binder.clearCallingIdentity();
8670 try {
8671 Phone p = getPhone(subId);
8672 if (p == null) {
8673 return null;
8674 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008676 return p.getSignalStrength();
8677 } finally {
8678 Binder.restoreCallingIdentity(identity);
8679 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008680 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008681
Pengquan Meng77b7f132018-08-22 14:49:57 -07008682 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008683 * Get the current modem radio state for the given slot.
8684 * @param slotIndex slot index.
8685 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008686 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008687 * @return the current radio power state from the modem
8688 */
8689 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008690 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008691 Phone phone = PhoneFactory.getPhone(slotIndex);
8692 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8694 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008695 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8696 }
8697
8698 final long identity = Binder.clearCallingIdentity();
8699 try {
8700 return phone.getRadioPowerState();
8701 } finally {
8702 Binder.restoreCallingIdentity(identity);
8703 }
8704 }
8705 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8706 }
8707
8708 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008709 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8710 *
8711 * <p>Requires one of the following permissions:
8712 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008713 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008714 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8715 * privileges.
8716 *
8717 * @param subId subscription id
8718 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8719 * {@code false}.
8720 */
8721 @Override
8722 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008723 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008724 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008725 try {
8726 mApp.enforceCallingOrSelfPermission(
8727 android.Manifest.permission.ACCESS_NETWORK_STATE,
8728 functionName);
8729 } catch (Exception e) {
8730 mApp.enforceCallingOrSelfPermission(
8731 permission.READ_BASIC_PHONE_STATE, functionName);
8732 }
Shuo Qian093013d2020-08-13 15:42:55 -07008733 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008734 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008735 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008736 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008737
Pengquan Menga1bb6272018-09-06 09:59:22 -07008738 boolean isEnabled = false;
8739 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008740 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008741 Phone phone = getPhone(subId);
8742 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008743 } finally {
8744 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008745 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008746 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008747 }
8748
8749
8750 /**
8751 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8752 *
8753 * <p> Requires permission:
8754 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8755 * privileges.
8756 *
8757 * @param subId subscription id
8758 * @param isEnabled {@code true} means enable, {@code false} means disable.
8759 */
8760 @Override
8761 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8763 mApp, subId, "setDataRoamingEnabled");
8764
Pengquan Menga1bb6272018-09-06 09:59:22 -07008765 final long identity = Binder.clearCallingIdentity();
8766 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008767 Phone phone = getPhone(subId);
8768 if (phone != null) {
8769 phone.setDataRoamingEnabled(isEnabled);
8770 }
8771 } finally {
8772 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008773 }
8774 }
8775
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008776 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008777 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008778 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008779 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008780 mApp, subId, "isManualNetworkSelectionAllowed");
8781
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008782 boolean isAllowed = true;
8783 final long identity = Binder.clearCallingIdentity();
8784 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008785 Phone phone = getPhone(subId);
8786 if (phone != null) {
8787 isAllowed = phone.isCspPlmnEnabled();
8788 }
8789 } finally {
8790 Binder.restoreCallingIdentity(identity);
8791 }
8792 return isAllowed;
8793 }
8794
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008795 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8796 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008797 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008798 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008799 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008800 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8801 if (phone == null) {
8802 return false;
8803 }
8804 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8805 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8806 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008807 }
8808
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008809 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008810 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008811 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008812 mApp.getSystemService(AppOpsManager.class)
8813 .checkPackage(Binder.getCallingUid(), callingPackage);
8814
Jordan Liu1e142fc2019-04-22 15:10:43 -07008815 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008816 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008817 try {
8818 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008819 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008820 } catch (SecurityException e) {
8821 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8822 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008823 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008824 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008825 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008826 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008827 }
sandeepjsb6c87872021-09-27 15:34:44 +00008828 // checking compatibility, if calling app's target SDK is T and beyond.
8829 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8830 Binder.getCallingUid())) {
8831 isIccIdAccessRestricted = true;
8832 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008833 final long identity = Binder.clearCallingIdentity();
8834 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008835 UiccController uiccController = UiccController.getInstance();
8836 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008837 if (hasReadPermission) {
8838 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008839 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008840
8841 // Remove private info if the caller doesn't have access
8842 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8843 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008844 //setting the value after compatibility check
8845 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008846 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8847 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008848 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008849 if (card == null) {
8850 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008851 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008852 continue;
8853 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008854 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8855 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008856 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008857 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008858 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008859 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8860 for (UiccPortInfo portInfo : portInfos) {
8861 UiccPort port = uiccController.getUiccPortForSlot(
8862 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8863 if (port == null) {
8864 // assume no access if port is null
8865 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8866 continue;
8867 }
8868 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8869 uiccPortInfos.add(portInfo);
8870 } else {
8871 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8872 }
8873 }
8874 filteredInfos.add(new UiccCardInfo(
8875 cardInfo.isEuicc(),
8876 cardInfo.getCardId(),
8877 null,
8878 cardInfo.getPhysicalSlotIndex(),
8879 cardInfo.isRemovable(),
8880 cardInfo.isMultipleEnabledProfilesSupported(),
8881 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008882 }
8883 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008884 } finally {
8885 Binder.restoreCallingIdentity(identity);
8886 }
8887 }
8888
sandeepjsb6c87872021-09-27 15:34:44 +00008889 /**
8890 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8891 * generally private and require carrier privileges to view.
8892 *
8893 * @hide
8894 */
8895 @NonNull
8896 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8897 List<UiccPortInfo> portinfo = new ArrayList<>();
8898 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8899 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8900 }
8901 return new UiccCardInfo(
8902 cardInfo.isEuicc(),
8903 cardInfo.getCardId(),
8904 null,
8905 cardInfo.getPhysicalSlotIndex(),
8906 cardInfo.isRemovable(),
8907 cardInfo.isMultipleEnabledProfilesSupported(),
8908 portinfo
8909 );
8910 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008911
sandeepjsb6c87872021-09-27 15:34:44 +00008912 /**
8913 * @hide
8914 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8915 * These values are generally private and require carrier privileges to view.
8916 */
8917 @NonNull
8918 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8919 return new UiccPortInfo(
8920 UiccPortInfo.ICCID_REDACTED,
8921 portInfo.getPortIndex(),
8922 portInfo.getLogicalSlotIndex(),
8923 portInfo.isActive()
8924 );
8925 }
8926 @Override
8927 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008928 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008929 mApp.getSystemService(AppOpsManager.class)
8930 .checkPackage(Binder.getCallingUid(), callingPackage);
8931
sandeepjsb6c87872021-09-27 15:34:44 +00008932 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008933
Aman Guptaf3c90b32022-03-17 04:54:16 +00008934 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8935 // we are reading iccId which is PII data.
8936 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008937
8938 // checking compatibility, if calling app's target SDK is T and beyond.
8939 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8940 Binder.getCallingUid())) {
8941 isLogicalSlotAccessRestricted = true;
8942 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008943 final long identity = Binder.clearCallingIdentity();
8944 try {
8945 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008946 if (slots == null || slots.length == 0) {
8947 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008948 return null;
8949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008950 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8951 for (int i = 0; i < slots.length; i++) {
8952 UiccSlot slot = slots[i];
8953 if (slot == null) {
8954 continue;
8955 }
8956
Jordan Liu7be7e652019-05-06 18:55:02 +00008957 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008958 UiccCard card = slot.getUiccCard();
8959 if (card != null) {
8960 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008961 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008962 cardId = slot.getEid();
8963 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00008964 // If cardId is null, use iccId of default port as cardId.
8965 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07008966 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008967 }
8968
Jordan Liu857451f2019-05-09 16:35:35 -07008969 if (cardId != null) {
8970 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8971 // if cardId is an EID, it's all digits so this is fine
8972 cardId = IccUtils.stripTrailingFs(cardId);
8973 }
8974
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008975 int cardState = 0;
8976 switch (slot.getCardState()) {
8977 case CARDSTATE_ABSENT:
8978 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8979 break;
8980 case CARDSTATE_PRESENT:
8981 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8982 break;
8983 case CARDSTATE_ERROR:
8984 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8985 break;
8986 case CARDSTATE_RESTRICTED:
8987 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8988 break;
8989 default:
8990 break;
8991
8992 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008993 List<UiccPortInfo> portInfos = new ArrayList<>();
8994 int[] portIndexes = slot.getPortList();
8995 for (int portIdx : portIndexes) {
8996 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00008997 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008998 portInfos.add(new UiccPortInfo(iccId, portIdx,
8999 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009000 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009001 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009002 slot.isEuicc(),
9003 cardId,
9004 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009005 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009006 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009007 //setting the value after compatibility check
9008 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009009 }
9010 return infos;
9011 } finally {
9012 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009013 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009014 }
9015
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009016 /* Returns null if doesn't have read permission or carrier privilege access. */
9017 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9018 boolean hasReadPermission) {
9019 String iccId = slot.getIccId(portIndex);
9020 if (hasReadPermission) { // if has read permission
9021 return iccId;
9022 } else {
9023 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9024 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9025 // if no read permission, checking carrier privilege access
9026 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9027 return iccId;
9028 }
9029 }
9030 }
9031 // No read permission or carrier privilege access.
9032 return UiccPortInfo.ICCID_REDACTED;
9033 }
9034
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009035 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009036 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009037 public boolean switchSlots(int[] physicalSlots) {
9038 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009039
9040 final long identity = Binder.clearCallingIdentity();
9041 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009042 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9043 for (int i = 0; i < physicalSlots.length; i++) {
9044 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9045 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9046 physicalSlots[i], i));
9047 }
9048 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009049 } finally {
9050 Binder.restoreCallingIdentity(identity);
9051 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009052 }
Jack Yu4c988042018-02-27 15:30:01 -08009053
9054 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009055 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9056 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9057 enforceModifyPermission();
9058
9059 final long identity = Binder.clearCallingIdentity();
9060 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009061 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009062 } finally {
9063 Binder.restoreCallingIdentity(identity);
9064 }
9065 }
9066
9067 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009068 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009069 final long identity = Binder.clearCallingIdentity();
9070 try {
9071 return UiccController.getInstance().getCardIdForDefaultEuicc();
9072 } finally {
9073 Binder.restoreCallingIdentity(identity);
9074 }
9075 }
9076
Pengquan Meng85728fb2018-03-12 16:31:21 -07009077 /**
goneil47ffb6e2018-04-06 15:40:58 -07009078 * A test API to reload the UICC profile.
9079 *
9080 * <p>Requires that the calling app has permission
9081 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9082 * @hide
9083 */
9084 @Override
9085 public void refreshUiccProfile(int subId) {
9086 enforceModifyPermission();
9087
9088 final long identity = Binder.clearCallingIdentity();
9089 try {
9090 Phone phone = getPhone(subId);
9091 if (phone == null) {
9092 return;
9093 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009094 UiccPort uiccPort = phone.getUiccPort();
9095 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009096 return;
9097 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009098 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009099 if (uiccProfile == null) {
9100 return;
9101 }
9102 uiccProfile.refresh();
9103 } finally {
9104 Binder.restoreCallingIdentity(identity);
9105 }
9106 }
9107
9108 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009109 * Returns false if the mobile data is disabled by default, otherwise return true.
9110 */
9111 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009112 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009113 }
9114
9115 /**
9116 * Returns true if the data roaming is enabled by default, i.e the system property
9117 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9118 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9119 */
9120 private boolean getDefaultDataRoamingEnabled(int subId) {
9121 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009122 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009123 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009124 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9125 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9126 return isDataRoamingEnabled;
9127 }
9128
9129 /**
9130 * Returns the default network type for the given {@code subId}, if the default network type is
9131 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9132 */
9133 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009134 List<Integer> list = TelephonyProperties.default_network();
9135 int phoneId = mSubscriptionController.getPhoneId(subId);
9136 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9137 return list.get(phoneId);
9138 }
9139 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009140 }
fionaxua13278b2018-03-21 00:08:13 -07009141
9142 @Override
9143 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009144 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009145 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009146
9147 final long identity = Binder.clearCallingIdentity();
9148 try {
9149 final Phone phone = getPhone(subId);
9150 if (phone == null) {
9151 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9152 return;
9153 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009154 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9155 if (cpt != null) {
9156 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9157 }
9158 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009159 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9160 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009161 if (carrierPrivilegeRules == null) {
9162 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9163 } else {
9164 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9165 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009166 } finally {
9167 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009168 }
fionaxua13278b2018-03-21 00:08:13 -07009169 }
9170
9171 @Override
9172 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009173 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009174
9175 final long identity = Binder.clearCallingIdentity();
9176 try {
9177 final Phone phone = getPhone(subId);
9178 if (phone == null) {
9179 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9180 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9181 }
9182 return phone.getCarrierIdListVersion();
9183 } finally {
9184 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009185 }
fionaxua13278b2018-03-21 00:08:13 -07009186 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009187
9188 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009189 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9190 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009192 mApp, subId, callingPackage, callingFeatureId,
9193 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009194 return -1;
9195 }
9196
9197 final long identity = Binder.clearCallingIdentity();
9198 try {
9199 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9200 } finally {
9201 Binder.restoreCallingIdentity(identity);
9202 }
9203 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009204
9205 @Override
9206 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009207 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009208 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009209 mApp, subId, "getCdmaRoamingMode");
9210
9211 final long identity = Binder.clearCallingIdentity();
9212 try {
9213 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9214 } finally {
9215 Binder.restoreCallingIdentity(identity);
9216 }
9217 }
9218
9219 @Override
9220 public boolean setCdmaRoamingMode(int subId, int mode) {
9221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9222 mApp, subId, "setCdmaRoamingMode");
9223
9224 final long identity = Binder.clearCallingIdentity();
9225 try {
9226 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9227 } finally {
9228 Binder.restoreCallingIdentity(identity);
9229 }
9230 }
9231
9232 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009233 public int getCdmaSubscriptionMode(int subId) {
9234 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009235 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009236 mApp, subId, "getCdmaSubscriptionMode");
9237
9238 final long identity = Binder.clearCallingIdentity();
9239 try {
9240 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9241 } finally {
9242 Binder.restoreCallingIdentity(identity);
9243 }
9244 }
9245
9246 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009247 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9249 mApp, subId, "setCdmaSubscriptionMode");
9250
9251 final long identity = Binder.clearCallingIdentity();
9252 try {
9253 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9254 } finally {
9255 Binder.restoreCallingIdentity(identity);
9256 }
9257 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009258
sqianc5eccab2018-10-19 18:46:41 -07009259 @Override
sqian8c685422019-02-22 15:55:18 -08009260 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009261 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009262 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009263 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9264 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009265 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9266 }
9267 final long identity = Binder.clearCallingIdentity();
9268 try {
sqian854d44b2018-12-12 16:48:18 -08009269 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9270 for (Phone phone: PhoneFactory.getPhones()) {
9271 if (phone.getEmergencyNumberTracker() != null
9272 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9273 emergencyNumberListInternal.put(
9274 phone.getSubId(),
9275 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9276 }
sqian11b7a0e2018-12-05 18:48:28 -08009277 }
sqian854d44b2018-12-12 16:48:18 -08009278 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009279 } finally {
9280 Binder.restoreCallingIdentity(identity);
9281 }
sqianc5eccab2018-10-19 18:46:41 -07009282 }
9283
9284 @Override
sqian8c685422019-02-22 15:55:18 -08009285 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009286 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009287 if (!exactMatch) {
9288 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009289 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009290 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009291 }
9292 final long identity = Binder.clearCallingIdentity();
9293 try {
sqian854d44b2018-12-12 16:48:18 -08009294 for (Phone phone: PhoneFactory.getPhones()) {
9295 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009296 && phone.getEmergencyNumberTracker()
9297 .isEmergencyNumber(number, exactMatch)) {
9298 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009299 }
sqian11b7a0e2018-12-05 18:48:28 -08009300 }
9301 return false;
9302 } finally {
9303 Binder.restoreCallingIdentity(identity);
9304 }
9305 }
9306
sqianf4ca7ed2019-01-15 18:32:07 -08009307 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009308 * Start emergency callback mode for GsmCdmaPhone for testing.
9309 */
9310 @Override
9311 public void startEmergencyCallbackMode() {
9312 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9313 "startEmergencyCallbackMode");
9314 enforceModifyPermission();
9315 final long identity = Binder.clearCallingIdentity();
9316 try {
9317 for (Phone phone : PhoneFactory.getPhones()) {
9318 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9319 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9320 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9321 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9322 gsmCdmaPhone.obtainMessage(
9323 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9324 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9325 }
9326 }
9327 } finally {
9328 Binder.restoreCallingIdentity(identity);
9329 }
9330 }
9331
9332 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009333 * Update emergency number list for test mode.
9334 */
9335 @Override
9336 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9337 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9338 "updateEmergencyNumberListTestMode");
9339
9340 final long identity = Binder.clearCallingIdentity();
9341 try {
9342 for (Phone phone: PhoneFactory.getPhones()) {
9343 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9344 if (tracker != null) {
9345 tracker.executeEmergencyNumberTestModeCommand(action, num);
9346 }
9347 }
9348 } finally {
9349 Binder.restoreCallingIdentity(identity);
9350 }
9351 }
9352
9353 /**
9354 * Get the full emergency number list for test mode.
9355 */
9356 @Override
9357 public List<String> getEmergencyNumberListTestMode() {
9358 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9359 "getEmergencyNumberListTestMode");
9360
9361 final long identity = Binder.clearCallingIdentity();
9362 try {
9363 Set<String> emergencyNumbers = new HashSet<>();
9364 for (Phone phone: PhoneFactory.getPhones()) {
9365 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9366 if (tracker != null) {
9367 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9368 emergencyNumbers.add(num.getNumber());
9369 }
9370 }
9371 }
9372 return new ArrayList<>(emergencyNumbers);
9373 } finally {
9374 Binder.restoreCallingIdentity(identity);
9375 }
9376 }
9377
chen xud6b45bd2018-10-30 22:27:10 -07009378 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009379 public int getEmergencyNumberDbVersion(int subId) {
9380 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9381
9382 final long identity = Binder.clearCallingIdentity();
9383 try {
9384 final Phone phone = getPhone(subId);
9385 if (phone == null) {
9386 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9387 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9388 }
9389 return phone.getEmergencyNumberDbVersion();
9390 } finally {
9391 Binder.restoreCallingIdentity(identity);
9392 }
9393 }
9394
9395 @Override
9396 public void notifyOtaEmergencyNumberDbInstalled() {
9397 enforceModifyPermission();
9398
9399 final long identity = Binder.clearCallingIdentity();
9400 try {
9401 for (Phone phone: PhoneFactory.getPhones()) {
9402 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9403 if (tracker != null) {
9404 tracker.updateOtaEmergencyNumberDatabase();
9405 }
9406 }
9407 } finally {
9408 Binder.restoreCallingIdentity(identity);
9409 }
9410 }
9411
9412 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009413 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009414 enforceActiveEmergencySessionPermission();
9415
9416 final long identity = Binder.clearCallingIdentity();
9417 try {
9418 for (Phone phone: PhoneFactory.getPhones()) {
9419 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9420 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009421 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9422 }
9423 }
9424 } finally {
9425 Binder.restoreCallingIdentity(identity);
9426 }
9427 }
9428
9429 @Override
9430 public void resetOtaEmergencyNumberDbFilePath() {
9431 enforceActiveEmergencySessionPermission();
9432
9433 final long identity = Binder.clearCallingIdentity();
9434 try {
9435 for (Phone phone: PhoneFactory.getPhones()) {
9436 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9437 if (tracker != null) {
9438 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009439 }
9440 }
9441 } finally {
9442 Binder.restoreCallingIdentity(identity);
9443 }
9444 }
9445
9446 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009447 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9448 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9449 Phone phone = getPhone(subId);
9450 if (phone == null) {
9451 return null;
9452 }
9453 final long identity = Binder.clearCallingIdentity();
9454 try {
9455 UiccProfile profile = UiccController.getInstance()
9456 .getUiccProfileForPhone(phone.getPhoneId());
9457 if (profile != null) {
9458 return profile.getCertsFromCarrierPrivilegeAccessRules();
9459 }
9460 } finally {
9461 Binder.restoreCallingIdentity(identity);
9462 }
9463 return null;
9464 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009465
9466 /**
9467 * Enable or disable a modem stack.
9468 */
9469 @Override
9470 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9471 enforceModifyPermission();
9472
9473 final long identity = Binder.clearCallingIdentity();
9474 try {
9475 Phone phone = PhoneFactory.getPhone(slotIndex);
9476 if (phone == null) {
9477 return false;
9478 } else {
9479 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9480 }
9481 } finally {
9482 Binder.restoreCallingIdentity(identity);
9483 }
9484 }
Michelecea4cf22018-12-21 15:00:11 -08009485
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009486 /**
9487 * Whether a modem stack is enabled or not.
9488 */
9489 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009490 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9491 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009492 Phone phone = PhoneFactory.getPhone(slotIndex);
9493 if (phone == null) return false;
9494
9495 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009496 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9497 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009498 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9499 }
9500
9501 final long identity = Binder.clearCallingIdentity();
9502 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009503 try {
9504 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9505 } catch (NoSuchElementException ex) {
9506 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9507 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009508 } finally {
9509 Binder.restoreCallingIdentity(identity);
9510 }
9511 }
9512
Michelecea4cf22018-12-21 15:00:11 -08009513 @Override
Michele0ea7d782019-03-19 14:58:42 -07009514 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009515 enforceModifyPermission();
9516
9517 final long identity = Binder.clearCallingIdentity();
9518 try {
9519 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009520 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009521 .commit();
9522 } finally {
9523 Binder.restoreCallingIdentity(identity);
9524 }
9525 }
9526
9527 @Override
Michele0ea7d782019-03-19 14:58:42 -07009528 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009529 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009531 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9532 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009533 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009534 }
Michelecea4cf22018-12-21 15:00:11 -08009535
9536 final long identity = Binder.clearCallingIdentity();
9537 try {
Michele0ea7d782019-03-19 14:58:42 -07009538 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009539 } finally {
9540 Binder.restoreCallingIdentity(identity);
9541 }
9542 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009543
Michele0ea7d782019-03-19 14:58:42 -07009544 @TelephonyManager.IsMultiSimSupportedResult
9545 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009546 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9547 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9548 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009549 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9550 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009551 }
9552 // Check if the hardware supports multisim functionality. If usage of multisim is not
9553 // supported by the modem, indicate that it is restricted.
9554 PhoneCapability staticCapability =
9555 mPhoneConfigurationManager.getStaticPhoneCapability();
9556 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009557 loge("isMultiSimSupportedInternal: no static configuration available");
9558 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009559 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009560 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009561 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9562 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009563 }
9564 // Check if support of multiple SIMs is restricted by carrier
9565 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009566 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009567 }
9568
Michele0ea7d782019-03-19 14:58:42 -07009569 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009570 }
9571
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009572 /**
9573 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009574 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9575 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9576 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009577 * @param numOfSims number of active sims we want to switch to
9578 */
9579 @Override
9580 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009581 if (numOfSims == 1) {
9582 enforceModifyPermission();
9583 } else {
9584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9585 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9586 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009587 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009588
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009589 try {
Michele30b57b22019-03-01 12:01:14 -08009590 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009591 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009592 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9593 return;
9594 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009595 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9596 } finally {
9597 Binder.restoreCallingIdentity(identity);
9598 }
9599 }
9600
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009601 @Override
9602 public boolean isApplicationOnUicc(int subId, int appType) {
9603 enforceReadPrivilegedPermission("isApplicationOnUicc");
9604 Phone phone = getPhone(subId);
9605 if (phone == null) {
9606 return false;
9607 }
9608 final long identity = Binder.clearCallingIdentity();
9609 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009610 UiccPort uiccPort = phone.getUiccPort();
9611 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009612 return false;
9613 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009614 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009615 if (uiccProfile == null) {
9616 return false;
9617 }
9618 if (TelephonyManager.APPTYPE_SIM <= appType
9619 && appType <= TelephonyManager.APPTYPE_ISIM) {
9620 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9621 }
9622 return false;
9623 } finally {
9624 Binder.restoreCallingIdentity(identity);
9625 }
9626 }
9627
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009628 /**
chen xub4baa772019-04-03 10:23:41 -07009629 * Get whether making changes to modem configurations will trigger reboot.
9630 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009631 */
9632 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009633 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9634 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009636 mApp, subId, callingPackage, callingFeatureId,
9637 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009638 return false;
9639 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009640 final long identity = Binder.clearCallingIdentity();
9641 try {
9642 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9643 } finally {
9644 Binder.restoreCallingIdentity(identity);
9645 }
9646 }
9647
Nathan Harold29f5f052019-02-15 13:41:57 -08009648 private void updateModemStateMetrics() {
9649 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9650 // TODO: check the state for each modem if the api is ready.
9651 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9652 }
9653
Pengquan Meng3889a572019-01-23 11:16:29 -08009654 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009655 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009656 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009657 // Verify that the callingPackage belongs to the calling UID
9658 mApp.getSystemService(AppOpsManager.class)
9659 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009660 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009661 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009662 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009663 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9664 if (slotInfos != null) {
9665 for (int i = 0; i < slotInfos.length; i++) {
9666 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9667 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9668 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9669 portInfo.getLogicalSlotIndex()));
9670 }
9671 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009672 }
9673 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009674 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009675 } finally {
9676 Binder.restoreCallingIdentity(identity);
9677 }
9678 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009679
9680 /**
9681 * Get the IRadio HAL Version
9682 */
9683 @Override
9684 public int getRadioHalVersion() {
9685 Phone phone = getDefaultPhone();
9686 if (phone == null) return -1;
9687 HalVersion hv = phone.getHalVersion();
9688 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9689 return hv.major * 100 + hv.minor;
9690 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009691
9692 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009693 * Get the current calling package name.
9694 * @return the current calling package name
9695 */
9696 @Override
9697 public String getCurrentPackageName() {
9698 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9699 }
9700
9701 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009702 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9703 * corresponding network requests on a subId.
9704 *
9705 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009706 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009707 * 2) APN is un-metered for this subscription, or
9708 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009709 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009710 *
9711 * @return whether data is allowed for a apn type.
9712 *
9713 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009714 */
9715 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009716 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009717 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9718 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009719
9720 // Now that all security checks passes, perform the operation as ourselves.
9721 final long identity = Binder.clearCallingIdentity();
9722 try {
9723 Phone phone = getPhone(subId);
9724 if (phone == null) return false;
9725
Jack Yu27422a52022-03-21 10:38:05 -07009726 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009727 boolean isDataEnabled;
9728 if (phone.isUsingNewDataStack()) {
Jack Yu27422a52022-03-21 10:38:05 -07009729 isMetered = phone.getDataNetworkController().getDataConfigManager()
9730 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9731 phone.getServiceState().getDataRoaming());
Jack Yu99e87332021-12-17 23:14:15 -08009732 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9733 } else {
Jack Yu27422a52022-03-21 10:38:05 -07009734 isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009735 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9736 }
9737 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009738 } finally {
9739 Binder.restoreCallingIdentity(identity);
9740 }
9741 }
9742
9743 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009744 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009745 enforceReadPrivilegedPermission("isApnMetered");
9746
9747 // Now that all security checks passes, perform the operation as ourselves.
9748 final long identity = Binder.clearCallingIdentity();
9749 try {
9750 Phone phone = getPhone(subId);
9751 if (phone == null) return true; // By default return true.
Jack Yu27422a52022-03-21 10:38:05 -07009752 if (phone.isUsingNewDataStack()) {
9753 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9754 DataUtils.apnTypeToNetworkCapability(apnType),
9755 phone.getServiceState().getDataRoaming());
9756 }
Malcolm Chene5ad5792019-04-18 13:51:02 -07009757
Jack Yu41407ee2019-05-13 16:54:09 -07009758 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009759 } finally {
9760 Binder.restoreCallingIdentity(identity);
9761 }
9762 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009763
9764 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009765 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9766 int subscriptionId, IBooleanConsumer resultCallback) {
9767 enforceModifyPermission();
9768 long token = Binder.clearCallingIdentity();
9769 try {
9770 Phone phone = getPhone(subscriptionId);
9771 if (phone == null) {
9772 try {
9773 if (resultCallback != null) {
9774 resultCallback.accept(false);
9775 }
9776 } catch (RemoteException e) {
9777 // ignore
9778 }
9779 return;
9780 }
9781 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9782 Pair.create(specifiers, (x) -> {
9783 try {
9784 if (resultCallback != null) {
9785 resultCallback.accept(x);
9786 }
9787 } catch (RemoteException e) {
9788 // ignore
9789 }
9790 });
9791 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9792 } finally {
9793 Binder.restoreCallingIdentity(token);
9794 }
9795 }
9796
9797 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009798 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9799 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009800 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009801 mApp, subId, "getSystemSelectionChannels");
9802 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9803 final long identity = Binder.clearCallingIdentity();
9804 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009805 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9806 if (result instanceof IllegalStateException) {
9807 throw (IllegalStateException) result;
9808 }
9809 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009810 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9811 return specifiers;
9812 } finally {
9813 Binder.restoreCallingIdentity(identity);
9814 }
9815 }
9816
9817 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009818 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009819 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009820 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009821 }
9822
9823 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009824 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9825 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009826 if (callingPackage == null) {
9827 callingPackage = getCurrentPackageName();
9828 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009829 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9830 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009831 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9832 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009833 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9834 }
9835 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9836 Intent intent = new Intent();
9837 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9838 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9839 // Bring up choose default SMS subscription dialog right now
9840 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9841 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9842 mApp.startActivity(intent);
9843 }
chen xud5ca2d52019-05-28 15:20:57 -07009844
9845 @Override
9846 public String getMmsUAProfUrl(int subId) {
9847 //TODO investigate if this API should require proper permission check in R b/133791609
9848 final long identity = Binder.clearCallingIdentity();
9849 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009850 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9851 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9852 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9853 return carrierUAProfUrl;
9854 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009855 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9856 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009857 } finally {
9858 Binder.restoreCallingIdentity(identity);
9859 }
9860 }
9861
9862 @Override
9863 public String getMmsUserAgent(int subId) {
9864 //TODO investigate if this API should require proper permission check in R b/133791609
9865 final long identity = Binder.clearCallingIdentity();
9866 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009867 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9868 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9869 if (!TextUtils.isEmpty(carrierUserAgent)) {
9870 return carrierUserAgent;
9871 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009872 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9873 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009874 } finally {
9875 Binder.restoreCallingIdentity(identity);
9876 }
9877 }
Jack Yub07d4972019-05-28 16:12:25 -07009878
9879 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009880 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9881 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009882
Jack Yub07d4972019-05-28 16:12:25 -07009883 final long identity = Binder.clearCallingIdentity();
9884 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009885 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009886 if (phone == null) return false;
9887
Hall Liua62f5da2020-09-25 10:42:19 -07009888 switch (policy) {
9889 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009890 if (phone.isUsingNewDataStack()) {
9891 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9892 } else {
9893 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9894 }
Hall Liua62f5da2020-09-25 10:42:19 -07009895 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009896 if (phone.isUsingNewDataStack()) {
9897 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9898 } else {
9899 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9900 }
Hall Liua62f5da2020-09-25 10:42:19 -07009901 default:
9902 throw new IllegalArgumentException(policy + " is not a valid policy");
9903 }
Jack Yub07d4972019-05-28 16:12:25 -07009904 } finally {
9905 Binder.restoreCallingIdentity(identity);
9906 }
9907 }
9908
9909 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009910 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009911 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009912 enforceModifyPermission();
9913
changbettyd5c246e2019-12-24 15:40:37 +08009914 final long identity = Binder.clearCallingIdentity();
9915 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009916 Phone phone = getPhone(subscriptionId);
9917 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009918
Hall Liua62f5da2020-09-25 10:42:19 -07009919 switch (policy) {
9920 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009921 if (phone.isUsingNewDataStack()) {
9922 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9923 } else {
9924 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9925 }
Hall Liua62f5da2020-09-25 10:42:19 -07009926 break;
9927 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009928 if (phone.isUsingNewDataStack()) {
9929 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9930 } else {
9931 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9932 }
Hall Liua62f5da2020-09-25 10:42:19 -07009933 break;
9934 default:
9935 throw new IllegalArgumentException(policy + " is not a valid policy");
9936 }
changbettyd5c246e2019-12-24 15:40:37 +08009937 } finally {
9938 Binder.restoreCallingIdentity(identity);
9939 }
9940 }
9941
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009942 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009943 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009944 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9945 * otherwise.
9946 */
9947 @Override
9948 public void setCepEnabled(boolean isCepEnabled) {
9949 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9950
9951 final long identity = Binder.clearCallingIdentity();
9952 try {
9953 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9954 for (Phone phone : PhoneFactory.getPhones()) {
9955 Phone defaultPhone = phone.getImsPhone();
9956 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9957 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9958 ImsPhoneCallTracker imsPhoneCallTracker =
9959 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9960 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9961 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9962 + imsPhone.getMsisdn());
9963 }
9964 }
9965 } finally {
9966 Binder.restoreCallingIdentity(identity);
9967 }
9968 }
allenwtsu46dcc572020-01-08 18:24:03 +08009969
9970 /**
9971 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9972 *
9973 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9974 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9975 * before being read.
9976 */
9977 @Override
9978 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9979 isCompressed) {
9980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9981 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009982 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9983 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9984 }
9985 if (!isImsAvailableOnDevice()) {
9986 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9987 "IMS not available on device.");
9988 }
9989
9990 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009991 try {
Hui Wang761a6682020-10-31 05:12:53 +00009992 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9993 } finally {
9994 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009995 }
9996 }
zoey chene02881a2019-12-30 16:11:23 +08009997
9998 @Override
9999 public boolean isIccLockEnabled(int subId) {
10000 enforceReadPrivilegedPermission("isIccLockEnabled");
10001
10002 // Now that all security checks passes, perform the operation as ourselves.
10003 final long identity = Binder.clearCallingIdentity();
10004 try {
10005 Phone phone = getPhone(subId);
10006 if (phone != null && phone.getIccCard() != null) {
10007 return phone.getIccCard().getIccLockEnabled();
10008 } else {
10009 return false;
10010 }
10011 } finally {
10012 Binder.restoreCallingIdentity(identity);
10013 }
10014 }
10015
10016 /**
10017 * Set the ICC pin lock enabled or disabled.
10018 *
10019 * @return an integer representing the status of IccLock enabled or disabled in the following
10020 * three cases:
10021 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10022 * successfully.
10023 * - Positive number and zero for remaining password attempts.
10024 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10025 *
10026 */
10027 @Override
10028 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10029 enforceModifyPermission();
10030
10031 Phone phone = getPhone(subId);
10032 if (phone == null) {
10033 return 0;
10034 }
10035 // Now that all security checks passes, perform the operation as ourselves.
10036 final long identity = Binder.clearCallingIdentity();
10037 try {
10038 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10039 new Pair<Boolean, String>(enabled, password), phone, null);
10040 return attemptsRemaining;
10041
10042 } catch (Exception e) {
10043 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10044 } finally {
10045 Binder.restoreCallingIdentity(identity);
10046 }
10047 return 0;
10048 }
10049
10050 /**
10051 * Change the ICC password used in ICC pin lock.
10052 *
10053 * @return an integer representing the status of IccLock changed in the following three cases:
10054 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10055 * - Positive number and zero for remaining password attempts.
10056 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10057 *
10058 */
10059 @Override
10060 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10061 enforceModifyPermission();
10062
10063 Phone phone = getPhone(subId);
10064 if (phone == null) {
10065 return 0;
10066 }
10067 // Now that all security checks passes, perform the operation as ourselves.
10068 final long identity = Binder.clearCallingIdentity();
10069 try {
10070 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10071 new Pair<String, String>(oldPassword, newPassword), phone, null);
10072 return attemptsRemaining;
10073
10074 } catch (Exception e) {
10075 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10076 } finally {
10077 Binder.restoreCallingIdentity(identity);
10078 }
10079 return 0;
10080 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010081
10082 /**
10083 * Request for receiving user activity notification
10084 */
10085 @Override
10086 public void requestUserActivityNotification() {
10087 if (!mNotifyUserActivity.get()
10088 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10089 mNotifyUserActivity.set(true);
10090 }
10091 }
10092
10093 /**
10094 * Called when userActivity is signalled in the power manager.
10095 * This is safe to call from any thread, with any window manager locks held or not.
10096 */
10097 @Override
10098 public void userActivity() {
10099 // ***************************************
10100 // * Inherited from PhoneWindowManager *
10101 // ***************************************
10102 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10103 // WITH ITS LOCKS HELD.
10104 //
10105 // This code must be VERY careful about the locks
10106 // it acquires.
10107 // In fact, the current code acquires way too many,
10108 // and probably has lurking deadlocks.
10109
10110 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10111 throw new SecurityException("Only the OS may call notifyUserActivity()");
10112 }
10113
10114 if (mNotifyUserActivity.getAndSet(false)) {
10115 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10116 USER_ACTIVITY_NOTIFICATION_DELAY);
10117 }
10118 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010119
10120 @Override
10121 public boolean canConnectTo5GInDsdsMode() {
10122 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10123 }
Jack Yud10cdd42020-09-28 20:28:01 -070010124
10125 @Override
10126 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10127 String callingFeatureId) {
10128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10129 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10130 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10131 }
10132
10133 Phone phone = getPhone(subId);
10134 if (phone == null) {
10135 throw new RuntimeException("phone is not available");
10136 }
10137 // Now that all security checks passes, perform the operation as ourselves.
10138 final long identity = Binder.clearCallingIdentity();
10139 try {
10140 return phone.getEquivalentHomePlmns();
10141 } finally {
10142 Binder.restoreCallingIdentity(identity);
10143 }
10144 }
Daniel Bright59e67312020-11-13 11:49:37 -080010145
10146 @Override
10147 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010148 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10149 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010150 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010151 if (radioInterfaceCapabilities == null) {
10152 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010153 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010154 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010155 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010156
Hui Wang641e81c2020-10-12 12:14:23 -070010157 @Override
10158 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10159 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010160 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10161 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10162 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10163 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10164 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010165 if (DBG) {
10166 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10167 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10168 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10169 }
10170
10171 if (!SubscriptionManager.isValidSubscriptionId(subId)
10172 || appType < TelephonyManager.APPTYPE_UNKNOWN
10173 || appType > TelephonyManager.APPTYPE_ISIM
10174 || nafUrl == null || securityProtocol == null || callback == null) {
10175 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10176 if (callback != null) {
10177 try {
10178 callback.onAuthenticationFailure(
10179 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10180 } catch (RemoteException exception) {
10181 log("Fail to notify onAuthenticationFailure due to " + exception);
10182 }
10183 return;
10184 }
10185 }
10186
10187 final long token = Binder.clearCallingIdentity();
10188 try {
10189 getGbaManager(subId).bootstrapAuthenticationRequest(
10190 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10191 forceBootStrapping, callback));
10192 } finally {
10193 Binder.restoreCallingIdentity(token);
10194 }
10195 }
10196
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010197 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010198 * Attempts to set the radio power state for all phones for thermal reason.
10199 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010200 * requested radio power state will actually be set. See {@link
10201 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10202 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010203 * @param enable {@code true} if trying to turn radio on.
10204 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10205 * false}.
10206 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010207 private boolean setRadioPowerForThermal(boolean enable) {
10208 boolean isPhoneAvailable = false;
10209 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10210 Phone phone = PhoneFactory.getPhone(i);
10211 if (phone != null) {
10212 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10213 isPhoneAvailable = true;
10214 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010215 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010216
10217 // return true if successfully informed the phone object about the thermal radio power
10218 // request.
10219 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010220 }
10221
10222 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010223 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010224 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10225 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10226 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10227 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10228 throw new IllegalArgumentException("modem does not support data throttling");
10229 }
10230
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010231 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10232 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010233 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010234 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10235 }
10236
Sarah Chinecc78c42022-03-31 21:16:48 -070010237 setDataEnabledForReason(
10238 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010239
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010240 if (isDataThrottlingSupported) {
10241 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010242 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010243 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10244 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10245 } else if (thermalMitigationResult
10246 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010247 log("Modem likely does not support data throttling on secondary carrier. Data " +
10248 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10249 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010250 }
10251 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010252 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010253
10254 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010255 }
10256
Jack Nudelman644b91a2021-03-12 14:09:48 -080010257 private static List<String> getThermalMitigationAllowlist(Context context) {
10258 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10259 for (String pckg : context.getResources()
10260 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10261 sThermalMitigationAllowlistedPackages.add(pckg);
10262 }
10263 }
10264
10265 return sThermalMitigationAllowlistedPackages;
10266 }
10267
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010268 private boolean isAnyPhoneInEmergencyState() {
10269 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10270 if (tm.isInEmergencyCall()) {
10271 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10272 return true;
10273 }
10274 for (Phone phone : PhoneFactory.getPhones()) {
10275 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10276 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10277 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10278 + phone.isInEcm());
10279 return true;
10280 }
10281 }
10282
10283 return false;
10284 }
10285
Jack Nudelman644b91a2021-03-12 14:09:48 -080010286 /**
10287 * Used by shell commands to add an authorized package name for thermal mitigation.
10288 * @param packageName name of package to be allowlisted
10289 * @param context
10290 */
10291 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10292 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10293 sThermalMitigationAllowlistedPackages.add(packageName);
10294 }
10295
10296 /**
10297 * Used by shell commands to remove an authorized package name for thermal mitigation.
10298 * @param packageName name of package to remove from allowlist
10299 * @param context
10300 */
10301 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10302 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10303 sThermalMitigationAllowlistedPackages.remove(packageName);
10304 }
10305
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010306 /**
10307 * Thermal mitigation request to control functionalities at modem.
10308 *
10309 * @param subId the id of the subscription.
10310 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010311 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010312 *
10313 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10314 */
10315 @Override
10316 @ThermalMitigationResult
10317 public int sendThermalMitigationRequest(
10318 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010319 ThermalMitigationRequest thermalMitigationRequest,
10320 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010321 enforceModifyPermission();
10322
Jack Nudelman644b91a2021-03-12 14:09:48 -080010323 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10324 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10325 .contains(callingPackage)) {
10326 throw new SecurityException("Calling package must be configured in the device config. "
10327 + "calling package: " + callingPackage);
10328 }
10329
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010330 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10331 final long identity = Binder.clearCallingIdentity();
10332
10333 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10334 try {
10335 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10336 switch (thermalMitigationAction) {
10337 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10338 thermalMitigationResult =
10339 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010340 thermalMitigationRequest.getDataThrottlingRequest(),
10341 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010342 break;
10343 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10344 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10345 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10346 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10347 }
10348
10349 // Ensure that radio is on. If not able to power on due to phone being
10350 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010351 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010352 thermalMitigationResult =
10353 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10354 break;
10355 }
10356
10357 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010358 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010359 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10360 break;
10361 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10362 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10363 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10364 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10365 }
10366
10367 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10368 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010369 Phone phone = getPhone(subId);
10370 if (phone == null) {
10371 thermalMitigationResult =
10372 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10373 break;
10374 }
10375
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010376 TelephonyConnectionService service =
10377 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010378 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010379 Log.e(LOG_TAG, "An emergency call is pending");
10380 thermalMitigationResult =
10381 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10382 break;
10383 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010384 thermalMitigationResult =
10385 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10386 break;
10387 }
10388 } else {
10389 thermalMitigationResult =
10390 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10391 break;
10392 }
10393
10394 // Turn radio off. If not able to power off due to phone being unavailable,
10395 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010396 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010397 thermalMitigationResult =
10398 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10399 break;
10400 }
10401 thermalMitigationResult =
10402 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10403 break;
10404 default:
10405 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10406 + "not exist. Requested action: " + thermalMitigationAction);
10407 }
10408 } catch (IllegalArgumentException e) {
10409 throw e;
10410 } catch (Exception e) {
10411 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10412 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10413 } finally {
10414 Binder.restoreCallingIdentity(identity);
10415 }
10416
10417 if (DBG) {
10418 log("thermalMitigationRequest returning with thermalMitigationResult: "
10419 + thermalMitigationResult);
10420 }
10421
10422 return thermalMitigationResult;
10423 }
Hui Wang641e81c2020-10-12 12:14:23 -070010424
10425 /**
10426 * Set the GbaService Package Name that Telephony will bind to.
10427 *
10428 * @param subId The sim that the GbaService is associated with.
10429 * @param packageName The name of the package to be replaced with.
10430 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10431 */
10432 @Override
10433 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10434 enforceModifyPermission();
10435
10436 final long identity = Binder.clearCallingIdentity();
10437 try {
10438 return getGbaManager(subId).overrideServicePackage(packageName);
10439 } finally {
10440 Binder.restoreCallingIdentity(identity);
10441 }
10442 }
10443
10444 /**
10445 * Return the package name of the currently bound GbaService.
10446 *
10447 * @param subId The sim that the GbaService is associated with.
10448 * @return the package name of the GbaService configuration, null if GBA is not supported.
10449 */
10450 @Override
10451 public String getBoundGbaService(int subId) {
10452 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10453
10454 final long identity = Binder.clearCallingIdentity();
10455 try {
10456 return getGbaManager(subId).getServicePackage();
10457 } finally {
10458 Binder.restoreCallingIdentity(identity);
10459 }
10460 }
10461
10462 /**
10463 * Set the release time for telephony to unbind GbaService.
10464 *
10465 * @param subId The sim that the GbaService is associated with.
10466 * @param interval The release time to unbind GbaService by millisecond.
10467 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10468 */
10469 @Override
10470 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10471 enforceModifyPermission();
10472
10473 final long identity = Binder.clearCallingIdentity();
10474 try {
10475 return getGbaManager(subId).overrideReleaseTime(interval);
10476 } finally {
10477 Binder.restoreCallingIdentity(identity);
10478 }
10479 }
10480
10481 /**
10482 * Return the release time for telephony to unbind GbaService.
10483 *
10484 * @param subId The sim that the GbaService is associated with.
10485 * @return The release time to unbind GbaService by millisecond.
10486 */
10487 @Override
10488 public int getGbaReleaseTime(int subId) {
10489 enforceReadPrivilegedPermission("getGbaReleaseTime");
10490
10491 final long identity = Binder.clearCallingIdentity();
10492 try {
10493 return getGbaManager(subId).getReleaseTime();
10494 } finally {
10495 Binder.restoreCallingIdentity(identity);
10496 }
10497 }
10498
10499 private GbaManager getGbaManager(int subId) {
10500 GbaManager instance = GbaManager.getInstance(subId);
10501 if (instance == null) {
10502 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10503 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10504 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10505 }
10506 return instance;
10507 }
Hui Wang761a6682020-10-31 05:12:53 +000010508
10509 /**
10510 * indicate whether the device and the carrier can support
10511 * RCS VoLTE single registration.
10512 */
10513 @Override
10514 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010515 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10516 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10517 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10518 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010519
10520 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10521 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10522 }
10523
10524 final long identity = Binder.clearCallingIdentity();
10525 try {
10526 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10527 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010528 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10529 if (isCapable != null) {
10530 return isCapable;
10531 }
Hui Wang761a6682020-10-31 05:12:53 +000010532 }
Hui Wang67af90e2021-06-04 16:57:15 -070010533 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10534 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010535 } finally {
10536 Binder.restoreCallingIdentity(identity);
10537 }
10538 }
10539
10540 /**
10541 * Register RCS provisioning callback.
10542 */
10543 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010544 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010545 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010546 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010547 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010548 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10549 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010550
10551 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10552 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10553 }
10554 if (!isImsAvailableOnDevice()) {
10555 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10556 "IMS not available on device.");
10557 }
10558
10559 final long identity = Binder.clearCallingIdentity();
10560 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010561 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010562 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010563 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10564 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010565 }
Hui Wang761a6682020-10-31 05:12:53 +000010566 } finally {
10567 Binder.restoreCallingIdentity(identity);
10568 }
10569 }
10570
10571 /**
10572 * Unregister RCS provisioning callback.
10573 */
10574 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010575 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010576 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010577 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010578 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010579 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10580 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010581
10582 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10583 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10584 }
10585 if (!isImsAvailableOnDevice()) {
10586 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10587 "IMS not available on device.");
10588 }
10589
10590 final long identity = Binder.clearCallingIdentity();
10591 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010592 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010593 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010594 } finally {
10595 Binder.restoreCallingIdentity(identity);
10596 }
10597 }
10598
10599 /**
10600 * trigger RCS reconfiguration.
10601 */
10602 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010603 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10604 "triggerRcsReconfiguration",
10605 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010606
10607 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10608 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10609 }
10610 if (!isImsAvailableOnDevice()) {
10611 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10612 "IMS not available on device.");
10613 }
10614
10615 final long identity = Binder.clearCallingIdentity();
10616 try {
10617 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10618 } finally {
10619 Binder.restoreCallingIdentity(identity);
10620 }
10621 }
10622
10623 /**
10624 * Provide the client configuration parameters of the RCS application.
10625 */
10626 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010627 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10628 "setRcsClientConfiguration",
10629 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010630
10631 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10632 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10633 }
10634 if (!isImsAvailableOnDevice()) {
10635 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10636 "IMS not available on device.");
10637 }
10638
10639 final long identity = Binder.clearCallingIdentity();
10640
10641 try {
10642 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10643 if (configBinder == null) {
10644 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010645 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10646 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010647 } else {
10648 configBinder.setRcsClientConfiguration(rcc);
10649 }
joonhunshin3e154242021-09-17 06:33:39 +000010650
10651 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10652 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010653 } catch (RemoteException e) {
10654 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010655 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10656 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010657 } finally {
10658 Binder.restoreCallingIdentity(identity);
10659 }
10660 }
10661
10662 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010663 * Enables or disables the test mode for RCS VoLTE single registration.
10664 */
10665 @Override
10666 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10667 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10668 "setRcsSingleRegistrationTestModeEnabled");
10669
10670 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10671 }
10672
10673 /**
10674 * Gets the test mode for RCS VoLTE single registration.
10675 */
10676 @Override
10677 public boolean getRcsSingleRegistrationTestModeEnabled() {
10678 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10679 "getRcsSingleRegistrationTestModeEnabled");
10680
10681 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10682 }
10683
10684 /**
Hui Wang761a6682020-10-31 05:12:53 +000010685 * Overrides the config of RCS VoLTE single registration enabled for the device.
10686 */
10687 @Override
10688 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10689 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10690 "setDeviceSingleRegistrationEnabledOverride");
10691 enforceModifyPermission();
10692
10693 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10694 : Boolean.parseBoolean(enabledStr);
10695 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010696 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010697 }
10698
10699 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010700 * Sends a device to device communication message. Only usable via shell.
10701 * @param message message to send.
10702 * @param value message value.
10703 */
10704 @Override
10705 public void sendDeviceToDeviceMessage(int message, int value) {
10706 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010707 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010708 enforceModifyPermission();
10709
10710 final long identity = Binder.clearCallingIdentity();
10711 try {
10712 TelephonyConnectionService service =
10713 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10714 if (service == null) {
10715 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10716 return;
10717 }
10718 service.sendTestDeviceToDeviceMessage(message, value);
10719 } finally {
10720 Binder.restoreCallingIdentity(identity);
10721 }
10722 }
10723
Tyler Gunnbabbda02021-02-10 11:05:02 -080010724 /**
10725 * Sets the specified device to device transport active.
10726 * @param transport The transport to set active.
10727 */
10728 @Override
10729 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10730 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10731 "setActiveDeviceToDeviceTransport");
10732 enforceModifyPermission();
10733
10734 final long identity = Binder.clearCallingIdentity();
10735 try {
10736 TelephonyConnectionService service =
10737 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10738 if (service == null) {
10739 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10740 return;
10741 }
10742 service.setActiveDeviceToDeviceTransport(transport);
10743 } finally {
10744 Binder.restoreCallingIdentity(identity);
10745 }
10746 }
Tyler Gunn92479152021-01-20 16:30:10 -080010747
Tyler Gunnd4339262021-05-03 14:46:49 -070010748 @Override
10749 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10750 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10751 "setDeviceToDeviceForceEnabled");
10752
10753 final long identity = Binder.clearCallingIdentity();
10754 try {
10755 Arrays.stream(PhoneFactory.getPhones()).forEach(
10756 p -> {
10757 Phone thePhone = p.getImsPhone();
10758 if (thePhone != null && thePhone instanceof ImsPhone) {
10759 ImsPhone imsPhone = (ImsPhone) thePhone;
10760 CallTracker tracker = imsPhone.getCallTracker();
10761 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10762 ImsPhoneCallTracker imsPhoneCallTracker =
10763 (ImsPhoneCallTracker) tracker;
10764 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10765 }
10766 }
10767 }
10768 );
10769 } finally {
10770 Binder.restoreCallingIdentity(identity);
10771 }
10772 }
10773
Tyler Gunn92479152021-01-20 16:30:10 -080010774 /**
Hui Wang761a6682020-10-31 05:12:53 +000010775 * Gets the config of RCS VoLTE single registration enabled for the device.
10776 */
10777 @Override
10778 public boolean getDeviceSingleRegistrationEnabled() {
10779 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10780 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10781 }
10782
10783 /**
10784 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10785 */
10786 @Override
10787 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10788 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10789 "setCarrierSingleRegistrationEnabledOverride");
10790 enforceModifyPermission();
10791
10792 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10793 : Boolean.parseBoolean(enabledStr);
10794 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10795 subId, enabled);
10796 }
10797
10798 /**
10799 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10800 */
10801 @Override
10802 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10803 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10804 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10805 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010806
10807 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010808 * Overrides the ims feature validation result
10809 */
10810 @Override
10811 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10812 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10813 "setImsFeatureValidationOverride");
10814
10815 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10816 : Boolean.parseBoolean(enabledStr);
10817 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10818 subId, enabled);
10819 }
10820
10821 /**
10822 * Gets the ims feature validation override value
10823 */
10824 @Override
10825 public boolean getImsFeatureValidationOverride(int subId) {
10826 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10827 "getImsFeatureValidationOverride");
10828 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10829 }
10830
10831 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010832 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10833 * their mobile plan.
10834 */
10835 @Override
10836 public String getMobileProvisioningUrl() {
10837 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10838 final long identity = Binder.clearCallingIdentity();
10839 try {
10840 return getDefaultPhone().getMobileProvisioningUrl();
10841 } finally {
10842 Binder.restoreCallingIdentity(identity);
10843 }
10844 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010845
James.cf Linbcdf8b32021-01-14 16:44:13 +080010846 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010847 * Get the EAB contact from the EAB database.
10848 */
10849 @Override
10850 public String getContactFromEab(String contact) {
10851 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10852 enforceModifyPermission();
10853 final long identity = Binder.clearCallingIdentity();
10854 try {
10855 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10856 } finally {
10857 Binder.restoreCallingIdentity(identity);
10858 }
10859 }
10860
10861 /**
Calvin Pana1434322021-07-01 19:27:01 +080010862 * Get the EAB capability from the EAB database.
10863 */
10864 @Override
10865 public String getCapabilityFromEab(String contact) {
10866 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10867 enforceModifyPermission();
10868 final long identity = Binder.clearCallingIdentity();
10869 try {
10870 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10871 } finally {
10872 Binder.restoreCallingIdentity(identity);
10873 }
10874 }
10875
10876 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010877 * Remove the EAB contacts from the EAB database.
10878 */
10879 @Override
10880 public int removeContactFromEab(int subId, String contacts) {
10881 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10882 enforceModifyPermission();
10883 final long identity = Binder.clearCallingIdentity();
10884 try {
10885 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10886 } finally {
10887 Binder.restoreCallingIdentity(identity);
10888 }
10889 }
10890
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010891 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010892 public boolean getDeviceUceEnabled() {
10893 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10894 final long identity = Binder.clearCallingIdentity();
10895 try {
10896 return mApp.getDeviceUceEnabled();
10897 } finally {
10898 Binder.restoreCallingIdentity(identity);
10899 }
10900 }
10901
10902 @Override
10903 public void setDeviceUceEnabled(boolean isEnabled) {
10904 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10905 final long identity = Binder.clearCallingIdentity();
10906 try {
10907 mApp.setDeviceUceEnabled(isEnabled);
10908 } finally {
10909 Binder.restoreCallingIdentity(identity);
10910 }
10911 }
10912
Brad Ebinger14d467f2021-02-12 06:18:28 +000010913 /**
10914 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10915 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10916 */
10917 // Used for SHELL command only right now.
10918 @Override
10919 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10920 List<String> featureTags) {
10921 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10922 "addUceRegistrationOverrideShell");
10923 final long identity = Binder.clearCallingIdentity();
10924 try {
10925 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10926 new ArraySet<>(featureTags));
10927 } catch (ImsException e) {
10928 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10929 } finally {
10930 Binder.restoreCallingIdentity(identity);
10931 }
10932 }
10933
10934 /**
10935 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10936 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10937 */
10938 // Used for SHELL command only right now.
10939 @Override
10940 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10941 List<String> featureTags) {
10942 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10943 "removeUceRegistrationOverrideShell");
10944 final long identity = Binder.clearCallingIdentity();
10945 try {
10946 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10947 new ArraySet<>(featureTags));
10948 } catch (ImsException e) {
10949 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10950 } finally {
10951 Binder.restoreCallingIdentity(identity);
10952 }
10953 }
10954
10955 /**
10956 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10957 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10958 */
10959 // Used for SHELL command only right now.
10960 @Override
10961 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10962 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10963 "clearUceRegistrationOverrideShell");
10964 final long identity = Binder.clearCallingIdentity();
10965 try {
10966 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10967 } catch (ImsException e) {
10968 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10969 } finally {
10970 Binder.restoreCallingIdentity(identity);
10971 }
10972 }
10973
10974 /**
10975 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10976 */
10977 // Used for SHELL command only right now.
10978 @Override
10979 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10980 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10981 "getLatestRcsContactUceCapabilityShell");
10982 final long identity = Binder.clearCallingIdentity();
10983 try {
10984 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10985 } catch (ImsException e) {
10986 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10987 } finally {
10988 Binder.restoreCallingIdentity(identity);
10989 }
10990 }
10991
10992 /**
10993 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10994 * device does not have an active PUBLISH.
10995 */
10996 // Used for SHELL command only right now.
10997 @Override
10998 public String getLastUcePidfXmlShell(int subId) {
10999 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11000 final long identity = Binder.clearCallingIdentity();
11001 try {
11002 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11003 } catch (ImsException e) {
11004 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11005 } finally {
11006 Binder.restoreCallingIdentity(identity);
11007 }
11008 }
11009
James.cf Line8713a42021-04-29 16:04:26 +080011010 /**
11011 * Remove UCE requests cannot be sent to the network status.
11012 */
11013 // Used for SHELL command only right now.
11014 @Override
11015 public boolean removeUceRequestDisallowedStatus(int subId) {
11016 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11017 final long identity = Binder.clearCallingIdentity();
11018 try {
11019 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11020 } catch (ImsException e) {
11021 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11022 } finally {
11023 Binder.restoreCallingIdentity(identity);
11024 }
11025 }
11026
James.cf Lin18bb9002021-05-25 01:37:38 +080011027 /**
11028 * Remove UCE requests cannot be sent to the network status.
11029 */
11030 // Used for SHELL command only.
11031 @Override
11032 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11033 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11034 final long identity = Binder.clearCallingIdentity();
11035 try {
11036 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11037 } catch (ImsException e) {
11038 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11039 } finally {
11040 Binder.restoreCallingIdentity(identity);
11041 }
11042 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011043
James.cf Lin4b784aa2021-01-31 03:25:15 +080011044 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011045 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11046 String callingPackage) {
11047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11048 mApp, subId, "setSignalStrengthUpdateRequest");
11049
11050 final int callingUid = Binder.getCallingUid();
11051 // Verify that tha callingPackage belongs to the calling UID
11052 mApp.getSystemService(AppOpsManager.class)
11053 .checkPackage(callingUid, callingPackage);
11054
Rambo Wang3607f502021-02-01 21:51:40 -080011055 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011056
11057 final long identity = Binder.clearCallingIdentity();
11058 try {
11059 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11060 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11061
11062 if (result instanceof IllegalStateException) {
11063 throw (IllegalStateException) result;
11064 }
11065 } finally {
11066 Binder.restoreCallingIdentity(identity);
11067 }
11068 }
11069
11070 @Override
11071 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11072 String callingPackage) {
11073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11074 mApp, subId, "clearSignalStrengthUpdateRequest");
11075
11076 final int callingUid = Binder.getCallingUid();
11077 // Verify that tha callingPackage belongs to the calling UID
11078 mApp.getSystemService(AppOpsManager.class)
11079 .checkPackage(callingUid, callingPackage);
11080
11081 final long identity = Binder.clearCallingIdentity();
11082 try {
11083 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11084 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11085
11086 if (result instanceof IllegalStateException) {
11087 throw (IllegalStateException) result;
11088 }
11089 } finally {
11090 Binder.restoreCallingIdentity(identity);
11091 }
11092 }
11093
Rambo Wang3607f502021-02-01 21:51:40 -080011094 private static void validateSignalStrengthUpdateRequest(Context context,
11095 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011096 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11097 // phone/system process do not have further restriction on request
11098 return;
11099 }
11100
11101 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011102 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011103 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011104 context.enforceCallingOrSelfPermission(
11105 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11106 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011107 }
11108
11109 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11110 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11111 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11112 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11113 || info.isEnabled()) {
11114 throw new IllegalArgumentException(
11115 "Only system can set hide fields in SignalThresholdInfo");
11116 }
11117
11118 // Thresholds length for each RAN need in range. This has been validated in
11119 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11120 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11121 final int[] thresholds = info.getThresholds();
11122 Objects.requireNonNull(thresholds);
11123 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11124 || thresholds.length
11125 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11126 throw new IllegalArgumentException(
11127 "thresholds length is out of range: " + thresholds.length);
11128 }
11129 }
11130 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011131
11132 /**
11133 * Gets the current phone capability.
11134 *
11135 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11136 * @return the PhoneCapability which describes the data connection capability of modem.
11137 * It's used to evaluate possible phone config change, for example from single
11138 * SIM device to multi-SIM device.
11139 */
11140 @Override
11141 public PhoneCapability getPhoneCapability() {
11142 enforceReadPrivilegedPermission("getPhoneCapability");
11143 final long identity = Binder.clearCallingIdentity();
11144 try {
11145 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11146 } finally {
11147 Binder.restoreCallingIdentity(identity);
11148 }
11149 }
Michele Berionne5e411512020-11-13 02:36:59 +000011150
11151 /**
11152 * Prepare TelephonyManager for an unattended reboot. The reboot is
11153 * required to be done shortly after the API is invoked.
11154 */
11155 @Override
11156 @TelephonyManager.PrepareUnattendedRebootResult
11157 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011158 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011159 enforceRebootPermission();
11160
11161 final long identity = Binder.clearCallingIdentity();
11162 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011163 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011164 } finally {
11165 Binder.restoreCallingIdentity(identity);
11166 }
11167 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011168
11169 /**
11170 * Request to get the current slicing configuration including URSP rules and
11171 * NSSAIs (configured, allowed and rejected).
11172 *
11173 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11174 */
11175 @Override
11176 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011177 TelephonyPermissions
11178 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11179 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011180
11181 final long identity = Binder.clearCallingIdentity();
11182 try {
11183 Phone phone = getDefaultPhone();
11184 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11185 } finally {
11186 Binder.restoreCallingIdentity(identity);
11187 }
11188 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011189
11190 /**
11191 * Register an IMS connection state callback
11192 */
11193 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011194 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11195 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011196 if (feature == ImsFeature.FEATURE_MMTEL) {
11197 // ImsMmTelManager
11198 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11199 TelephonyPermissions
11200 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11201 mApp, subId, "registerImsStateCallback");
11202 } else if (feature == ImsFeature.FEATURE_RCS) {
11203 // ImsRcsManager or SipDelegateManager
11204 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11205 Binder.getCallingUid(), "registerImsStateCallback",
11206 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11207 Manifest.permission.READ_PRECISE_PHONE_STATE,
11208 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11209 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11210 }
11211
11212 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11213 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11214 "IMS not available on device.");
11215 }
11216
11217 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11218 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11219 }
11220
11221 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11222 if (controller == null) {
11223 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11224 "IMS not available on device.");
11225 }
11226
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011227 if (callingPackage == null) {
11228 callingPackage = getCurrentPackageName();
11229 }
11230
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011231 final long token = Binder.clearCallingIdentity();
11232 try {
11233 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011234 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011235 } catch (ImsException e) {
11236 throw new ServiceSpecificException(e.getCode());
11237 } finally {
11238 Binder.restoreCallingIdentity(token);
11239 }
11240 }
11241
11242 /**
11243 * Unregister an IMS connection state callback
11244 */
11245 @Override
11246 public void unregisterImsStateCallback(IImsStateCallback cb) {
11247 final long token = Binder.clearCallingIdentity();
11248 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11249 if (controller == null) {
11250 return;
11251 }
11252 try {
11253 controller.unregisterImsStateCallback(cb);
11254 } finally {
11255 Binder.restoreCallingIdentity(token);
11256 }
11257 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011258
11259 /**
11260 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11261 *
11262 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11263 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11264 * SecurityException.
11265 * If there is current registered network this value will be same as the registered cell
11266 * identity. If the device goes out of service the previous cell identity is cached and
11267 * will be returned. If the cache age of the Cell identity is more than 24 hours
11268 * it will be cleared and null will be returned.
11269 *
11270 */
11271 @Override
11272 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11273 String callingFeatureId) {
11274 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11275 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11276 LocationAccessPolicy.checkLocationPermission(mApp,
11277 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11278 .setCallingPackage(callingPackage)
11279 .setCallingFeatureId(callingFeatureId)
11280 .setCallingPid(Binder.getCallingPid())
11281 .setCallingUid(Binder.getCallingUid())
11282 .setMethod("getLastKnownCellIdentity")
11283 .setLogAsInfo(true)
11284 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11285 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11286 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11287 .build());
11288
11289 boolean hasFinePermission =
11290 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11291 if (!hasFinePermission
11292 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11293 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011294 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011295 }
11296
11297 final long identity = Binder.clearCallingIdentity();
11298 try {
11299 Phone phone = getPhone(subId);
11300 if (phone == null) return null;
11301 ServiceStateTracker sst = phone.getServiceStateTracker();
11302 if (sst == null) return null;
11303 return sst.getLastKnownCellIdentity();
11304 } finally {
11305 Binder.restoreCallingIdentity(identity);
11306 }
11307 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011308
11309 @Override
11310 public boolean isUsingNewDataStack() {
11311 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11312 return getDefaultPhone().isUsingNewDataStack();
11313 }
jimsun3b9ccac2021-10-26 15:01:23 +080011314
11315 /**
11316 * Sets the modem service class Name that Telephony will bind to.
11317 *
11318 * @param serviceName The class name of the modem service.
11319 * @return true if the operation is succeed, otherwise false.
11320 */
11321 public boolean setModemService(String serviceName) {
11322 Log.d(LOG_TAG, "setModemService - " + serviceName);
11323 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11325 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11326 "setModemService");
11327 return mPhoneConfigurationManager.setModemService(serviceName);
11328 }
11329
11330 /**
11331 * Return the class name of the currently bounded modem service.
11332 *
11333 * @return the class name of the modem service.
11334 */
11335 public String getModemService() {
11336 String result;
11337 Log.d(LOG_TAG, "getModemService");
11338 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11339 TelephonyPermissions
11340 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11341 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11342 "getModemService");
11343 result = mPhoneConfigurationManager.getModemService();
11344 Log.d(LOG_TAG, "result = " + result);
11345 return result;
11346 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011347
11348 @Override
11349 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11350 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11351 mApp.enforceCallingOrSelfPermission(
11352 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11353 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11354
11355 final long identity = Binder.clearCallingIdentity();
11356 try {
11357 Phone phone = getPhone(subId);
11358 if (phone == null) return;
11359 phone.setVoiceServiceStateOverride(hasService);
11360 } finally {
11361 Binder.restoreCallingIdentity(identity);
11362 }
11363 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011364
11365 /**
11366 * set removable eSIM as default eUICC.
11367 *
11368 * @hide
11369 */
11370 @Override
11371 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11372 enforceModifyPermission();
11373 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11374
11375 final long identity = Binder.clearCallingIdentity();
11376 try {
11377 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11378 } finally {
11379 Binder.restoreCallingIdentity(identity);
11380 }
11381 }
11382
11383 /**
11384 * Returns whether the removable eSIM is default eUICC or not.
11385 *
11386 * @hide
11387 */
11388 @Override
11389 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11390 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11391 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11392
11393 final long identity = Binder.clearCallingIdentity();
11394 try {
11395 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11396 } finally {
11397 Binder.restoreCallingIdentity(identity);
11398 }
11399 }
11400
11401
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011402}