blob: 461484675cdbe2925c1451c3b68af900e594037d [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;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700189import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800190import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700191import com.android.internal.telephony.imsphone.ImsPhone;
192import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000193import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800194import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700195import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700196import com.android.internal.telephony.uicc.IccIoResult;
197import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800198import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700199import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800200import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000202import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800203import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000204import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800205import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700206import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700207import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800208import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800209import com.android.phone.callcomposer.CallComposerPictureManager;
210import com.android.phone.callcomposer.CallComposerPictureTransfer;
211import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700212import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700213import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800214import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700215import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700216import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800217import com.android.services.telephony.TelecomAccountRegistry;
218import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800219import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800220
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700222import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.io.IOException;
224import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700225import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800227import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000228import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800229import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800230import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800231import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800232import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100233import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800234import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700235import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800236import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800237import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800238import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800239import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800240import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241
242/**
243 * Implementation of the ITelephony interface.
244 */
Santos Cordon117fee72014-05-16 17:56:12 -0700245public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246 private static final String LOG_TAG = "PhoneInterfaceManager";
247 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
248 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800249 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250
251 // Message codes used with mMainThreadHandler
252 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700253 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
254 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700255 private static final int CMD_OPEN_CHANNEL = 9;
256 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
257 private static final int CMD_CLOSE_CHANNEL = 11;
258 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800259 private static final int CMD_NV_READ_ITEM = 13;
260 private static final int EVENT_NV_READ_ITEM_DONE = 14;
261 private static final int CMD_NV_WRITE_ITEM = 15;
262 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
263 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
264 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_RESET_MODEM_CONFIG = 19;
266 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800267 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
268 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800269 private static final int CMD_SEND_ENVELOPE = 25;
270 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000271 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
272 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700273 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
274 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
275 private static final int CMD_EXCHANGE_SIM_IO = 31;
276 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800277 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
278 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700279 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
280 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700281 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
282 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700283 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
284 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
285 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
286 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700287 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
288 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
289 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
290 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700291 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800292 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
293 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000294 private static final int CMD_SWITCH_SLOTS = 50;
295 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700296 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
297 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
298 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
299 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
300 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
301 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
302 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
303 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700304 private static final int CMD_GET_ALL_CELL_INFO = 60;
305 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
306 private static final int CMD_GET_CELL_LOCATION = 62;
307 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700308 private static final int CMD_MODEM_REBOOT = 64;
309 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700310 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
311 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800312 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
313 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700314 private static final int CMD_GET_MODEM_STATUS = 70;
315 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700316 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
317 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700318 private static final int CMD_ERASE_MODEM_CONFIG = 74;
319 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800320 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
321 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
322 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
323 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800324 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
325 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800326 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800327 private static final int CMD_GET_CALL_FORWARDING = 83;
328 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
329 private static final int CMD_SET_CALL_FORWARDING = 85;
330 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
331 private static final int CMD_GET_CALL_WAITING = 87;
332 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
333 private static final int CMD_SET_CALL_WAITING = 89;
334 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700335 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
336 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
337 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
338 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700339 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
340 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800341 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
342 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800343 private static final int CMD_SET_DATA_THROTTLING = 99;
344 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800345 private static final int CMD_SET_SIM_POWER = 101;
346 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800347 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
348 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
349 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
350 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800351 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
352 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000353 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800354 private static final int CMD_GET_SLICING_CONFIG = 110;
355 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800356 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700357 private static final int CMD_ENABLE_VONR = 113;
358 private static final int EVENT_ENABLE_VONR_DONE = 114;
359 private static final int CMD_IS_VONR_ENABLED = 115;
360 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800362 // Parameters of select command.
363 private static final int SELECT_COMMAND = 0xA4;
364 private static final int SELECT_P1 = 0x04;
365 private static final int SELECT_P2 = 0;
366 private static final int SELECT_P3 = 0x10;
367
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 /** The singleton instance. */
369 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800370 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800373 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800374 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700375 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700377 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800379 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800380 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700381 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800382 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000383 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
Peter Wangdafb9ac2020-01-15 14:13:38 -0800385 /** User Activity */
386 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800387 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
388
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700389 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
390
Derek Tan97ebb422014-09-05 16:55:38 -0700391 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
392 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800393 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800394 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700395
Michelecea4cf22018-12-21 15:00:11 -0800396 // String to store multi SIM allowed
397 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
398
Derek Tan740e1672017-06-27 14:56:27 -0700399 // The AID of ISD-R.
400 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
401
yinxub1bed742017-04-17 11:45:04 -0700402 private NetworkScanRequestTracker mNetworkScanRequestTracker;
403
David Kelly5e06a7f2018-03-12 14:10:59 +0000404 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
405 private static final int MANUFACTURER_CODE_LENGTH = 8;
406
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800407 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800408 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800409
Derek Tan89e89d42014-07-08 17:00:10 -0700410 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700411 * Experiment flag to enable erase modem config on reset network, default value is false
412 */
413 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
414 "reset_network_erase_modem_config_enabled";
415
Rambo Wang0f050d82021-02-12 11:43:36 -0800416 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800417
sandeepjsb6c87872021-09-27 15:34:44 +0000418 /**
419 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
420 * one ICCID active at the same time.
421 * Apps should use below API signatures if targeting SDK is T and beyond.
422 *
423 * @hide
424 */
425 @ChangeId
426 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
427 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800428
Naina Nallurid63128d2019-09-17 14:10:30 -0700429 /**
Chen Xu540470b2021-12-14 17:15:47 -0800430 * Apps targeting on Android T and beyond will get exception whenever icc close channel
431 * operation fails.
432 */
433 @ChangeId
434 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
435 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
436
437 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 * A request object to use for transmitting data to an ICC.
439 */
440 private static final class IccAPDUArgument {
441 public int channel, cla, command, p1, p2, p3;
442 public String data;
443
444 public IccAPDUArgument(int channel, int cla, int command,
445 int p1, int p2, int p3, String data) {
446 this.channel = channel;
447 this.cla = cla;
448 this.command = command;
449 this.p1 = p1;
450 this.p2 = p2;
451 this.p3 = p3;
452 this.data = data;
453 }
454 }
455
456 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700457 * A request object to use for transmitting data to an ICC.
458 */
459 private static final class ManualNetworkSelectionArgument {
460 public OperatorInfo operatorInfo;
461 public boolean persistSelection;
462
463 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
464 this.operatorInfo = operatorInfo;
465 this.persistSelection = persistSelection;
466 }
467 }
468
469 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
471 * request after sending. The main thread will notify the request when it is complete.
472 */
473 private static final class MainThreadRequest {
474 /** The argument to use for the request */
475 public Object argument;
476 /** The result of the request that is run on the main thread */
477 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800478 // The subscriber id that this request applies to. Defaults to
479 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
480 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481
Nathan Harold92bed182018-10-12 18:16:49 -0700482 // In cases where subId is unavailable, the caller needs to specify the phone.
483 public Phone phone;
484
vagdeviaf9a5b92018-08-15 16:01:53 -0700485 public WorkSource workSource;
486
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700487 public MainThreadRequest(Object argument) {
488 this.argument = argument;
489 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800490
Nathan Harold92bed182018-10-12 18:16:49 -0700491 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
492 this.argument = argument;
493 if (phone != null) {
494 this.phone = phone;
495 }
496 this.workSource = workSource;
497 }
498
vagdeviaf9a5b92018-08-15 16:01:53 -0700499 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800500 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800501 if (subId != null) {
502 this.subId = subId;
503 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700504 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 }
507
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800508 private static final class IncomingThirdPartyCallArgs {
509 public final ComponentName component;
510 public final String callId;
511 public final String callerDisplayName;
512
513 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
514 String callerDisplayName) {
515 this.component = component;
516 this.callId = callId;
517 this.callerDisplayName = callerDisplayName;
518 }
519 }
520
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 /**
522 * A handler that processes messages on the main thread in the phone process. Since many
523 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
524 * inbound binder threads to the main thread in the phone process. The Binder thread
525 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
526 * on, which will be notified when the operation completes and will contain the result of the
527 * request.
528 *
529 * <p>If a MainThreadRequest object is provided in the msg.obj field,
530 * note that request.result must be set to something non-null for the calling thread to
531 * unblock.
532 */
533 private final class MainThreadHandler extends Handler {
534 @Override
535 public void handleMessage(Message msg) {
536 MainThreadRequest request;
537 Message onCompleted;
538 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000539 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800541 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542
543 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 case CMD_HANDLE_USSD_REQUEST: {
545 request = (MainThreadRequest) msg.obj;
546 final Phone phone = getPhoneFromRequest(request);
547 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800548 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700550
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 if (!isUssdApiAllowed(request.subId)) {
552 // Carrier does not support use of this API, return failure.
553 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
554 UssdResponse response = new UssdResponse(ussdRequest, null);
555 Bundle returnData = new Bundle();
556 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
557 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700558
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 request.result = true;
560 notifyRequester(request);
561 return;
562 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700563
Pengquan Menga1bb6272018-09-06 09:59:22 -0700564 try {
565 request.result = phone != null
566 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
567 } catch (CallStateException cse) {
568 request.result = false;
569 }
570 // Wake up the requesting thread
571 notifyRequester(request);
572 break;
pkanwar32d516d2016-10-14 19:37:38 -0700573 }
574
Yorke Lee716f67e2015-06-17 15:39:16 -0700575 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700576 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700577 final Phone phone = getPhoneFromRequest(request);
578 request.result = phone != null ?
579 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
580 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700581 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700585
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000589 uiccPort = getUiccPortFromRequest(request);
590 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800592 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800596 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000597 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800598 iccArgument.channel, iccArgument.cla, iccArgument.command,
599 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
600 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 break;
603
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 ar = (AsyncResult) msg.obj;
606 request = (MainThreadRequest) ar.userObj;
607 if (ar.exception == null && ar.result != null) {
608 request.result = ar.result;
609 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800610 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.result == null) {
612 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800613 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800615 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 } else {
617 loge("iccTransmitApduLogicalChannel: Unknown exception");
618 }
619 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 break;
622
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
624 request = (MainThreadRequest) msg.obj;
625 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000626 uiccPort = getUiccPortFromRequest(request);
627 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800629 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 } else {
632 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800633 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000634 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800635 iccArgument.cla, iccArgument.command, iccArgument.p1,
636 iccArgument.p2,
637 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 }
639 break;
640
641 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
642 ar = (AsyncResult) msg.obj;
643 request = (MainThreadRequest) ar.userObj;
644 if (ar.exception == null && ar.result != null) {
645 request.result = ar.result;
646 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800647 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 if (ar.result == null) {
649 loge("iccTransmitApduBasicChannel: Empty response");
650 } else if (ar.exception instanceof CommandException) {
651 loge("iccTransmitApduBasicChannel: CommandException: " +
652 ar.exception);
653 } else {
654 loge("iccTransmitApduBasicChannel: Unknown exception");
655 }
656 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 break;
659
660 case CMD_EXCHANGE_SIM_IO:
661 request = (MainThreadRequest) msg.obj;
662 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000663 uiccPort = getUiccPortFromRequest(request);
664 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800666 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 } else {
669 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
670 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000671 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
673 iccArgument.data, onCompleted);
674 }
675 break;
676
677 case EVENT_EXCHANGE_SIM_IO_DONE:
678 ar = (AsyncResult) msg.obj;
679 request = (MainThreadRequest) ar.userObj;
680 if (ar.exception == null && ar.result != null) {
681 request.result = ar.result;
682 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800683 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 break;
687
Derek Tan4d5e5c12014-02-04 11:54:58 -0800688 case CMD_SEND_ENVELOPE:
689 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000690 uiccPort = getUiccPortFromRequest(request);
691 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800693 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700694 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 } else {
696 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800697 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700698 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800699 break;
700
701 case EVENT_SEND_ENVELOPE_DONE:
702 ar = (AsyncResult) msg.obj;
703 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700704 if (ar.exception == null && ar.result != null) {
705 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800706 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800707 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700708 if (ar.result == null) {
709 loge("sendEnvelopeWithStatus: Empty response");
710 } else if (ar.exception instanceof CommandException) {
711 loge("sendEnvelopeWithStatus: CommandException: " +
712 ar.exception);
713 } else {
714 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
715 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800718 break;
719
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 case CMD_OPEN_CHANNEL:
721 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000722 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800723 IccLogicalChannelRequest openChannelRequest =
724 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000725 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700726 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800727 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800728 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700729 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700730 } else {
731 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800732 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
733 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700734 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700735 break;
736
737 case EVENT_OPEN_CHANNEL_DONE:
738 ar = (AsyncResult) msg.obj;
739 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700740 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 int[] result = (int[]) ar.result;
743 int channelId = result[0];
744 byte[] selectResponse = null;
745 if (result.length > 1) {
746 selectResponse = new byte[result.length - 1];
747 for (int i = 1; i < result.length; ++i) {
748 selectResponse[i - 1] = (byte) result[i];
749 }
750 }
751 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800752 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800753
754 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700755 if (uiccPort == null) {
756 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
757 } else {
758 IccLogicalChannelRequest channelRequest =
759 (IccLogicalChannelRequest) request.argument;
760 channelRequest.channel = channelId;
761 uiccPort.onLogicalChannelOpened(channelRequest);
762 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 if (ar.result == null) {
765 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700766 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700767 if (ar.exception != null) {
768 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
769 }
770
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700771 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700772 if (ar.exception instanceof CommandException) {
773 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800774 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700775 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700776 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700777 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700778 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700779 }
780 }
781 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800782 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700783 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700784 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700785 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700786 break;
787
788 case CMD_CLOSE_CHANNEL:
789 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000790 uiccPort = getUiccPortFromRequest(request);
791 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700792 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800793 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800794 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800795 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700796 } else {
797 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000798 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700799 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 break;
801
802 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
805 if (ar.exception == null) {
806 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800807 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700808 if (uiccPort == null) {
809 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
810 } else {
811 final int channelId = (Integer) request.argument;
812 uiccPort.onLogicalChannelClosed(channelId);
813 }
Chen Xu540470b2021-12-14 17:15:47 -0800814 } else {
815 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800816 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800817 if (ar.exception instanceof CommandException) {
818 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
819 CommandException.Error error =
820 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800821 if (error == CommandException.Error.INVALID_ARGUMENTS) {
822 // should only throw exceptions from the binder threads.
823 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800824 "iccCloseLogicalChannel: invalid argument ");
825 }
826 } else {
827 loge("iccCloseLogicalChannel: Unknown exception");
828 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800829 request.result = (exception != null) ? exception :
830 new IllegalStateException(
831 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800832 }
833 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800834 break;
835
836 case CMD_NV_READ_ITEM:
837 request = (MainThreadRequest) msg.obj;
838 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800839 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
840 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800841 break;
842
843 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700844 ar = (AsyncResult) msg.obj;
845 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800846 if (ar.exception == null && ar.result != null) {
847 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800849 request.result = "";
850 if (ar.result == null) {
851 loge("nvReadItem: Empty response");
852 } else if (ar.exception instanceof CommandException) {
853 loge("nvReadItem: CommandException: " +
854 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700855 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800856 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700857 }
858 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700859 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700860 break;
861
Jake Hambye994d462014-02-03 13:10:13 -0800862 case CMD_NV_WRITE_ITEM:
863 request = (MainThreadRequest) msg.obj;
864 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
865 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800866 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700867 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800868 break;
869
870 case EVENT_NV_WRITE_ITEM_DONE:
871 handleNullReturnEvent(msg, "nvWriteItem");
872 break;
873
874 case CMD_NV_WRITE_CDMA_PRL:
875 request = (MainThreadRequest) msg.obj;
876 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800877 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800878 break;
879
880 case EVENT_NV_WRITE_CDMA_PRL_DONE:
881 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
882 break;
883
chen xu6dac5ab2018-10-26 17:39:23 -0700884 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800885 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700886 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800887 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800888 break;
889
chen xu6dac5ab2018-10-26 17:39:23 -0700890 case EVENT_RESET_MODEM_CONFIG_DONE:
891 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800892 break;
893
Sooraj Sasindran37444802020-08-11 10:40:43 -0700894 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
895 request = (MainThreadRequest) msg.obj;
896 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
897 request);
898 Phone phone = getPhoneFromRequest(request);
899 if (phone != null) {
900 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
901 } else {
902 loge("isNRDualConnectivityEnabled: No phone object");
903 request.result = false;
904 notifyRequester(request);
905 }
906 break;
907 }
908
909 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result;
914 } else {
915 // request.result must be set to something non-null
916 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700917 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700918 request.result = ar.result;
919 } else {
920 request.result = false;
921 }
922 if (ar.result == null) {
923 loge("isNRDualConnectivityEnabled: Empty response");
924 } else if (ar.exception instanceof CommandException) {
925 loge("isNRDualConnectivityEnabled: CommandException: "
926 + ar.exception);
927 } else {
928 loge("isNRDualConnectivityEnabled: Unknown exception");
929 }
930 }
931 notifyRequester(request);
932 break;
933
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700934 case CMD_IS_VONR_ENABLED: {
935 request = (MainThreadRequest) msg.obj;
936 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
937 request);
938 Phone phone = getPhoneFromRequest(request);
939 if (phone != null) {
940 phone.isVoNrEnabled(onCompleted, request.workSource);
941 } else {
942 loge("isVoNrEnabled: No phone object");
943 request.result = false;
944 notifyRequester(request);
945 }
946 break;
947 }
948
949 case EVENT_IS_VONR_ENABLED_DONE:
950 ar = (AsyncResult) msg.obj;
951 request = (MainThreadRequest) ar.userObj;
952 if (ar.exception == null && ar.result != null) {
953 request.result = ar.result;
954 } else {
955 // request.result must be set to something non-null
956 // for the calling thread to unblock
957 if (ar.result != null) {
958 request.result = ar.result;
959 } else {
960 request.result = false;
961 }
962 if (ar.result == null) {
963 loge("isVoNrEnabled: Empty response");
964 } else if (ar.exception instanceof CommandException) {
965 loge("isVoNrEnabled: CommandException: "
966 + ar.exception);
967 } else {
968 loge("isVoNrEnabled: Unknown exception");
969 }
970 }
971 notifyRequester(request);
972 break;
973
Sooraj Sasindran37444802020-08-11 10:40:43 -0700974 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
975 request = (MainThreadRequest) msg.obj;
976 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
977 Phone phone = getPhoneFromRequest(request);
978 if (phone != null) {
979 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
980 request.workSource);
981 } else {
982 loge("enableNrDualConnectivity: No phone object");
983 request.result =
984 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
985 notifyRequester(request);
986 }
987 break;
988 }
989
990 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
991 ar = (AsyncResult) msg.obj;
992 request = (MainThreadRequest) ar.userObj;
993 if (ar.exception == null) {
994 request.result =
995 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
996 } else {
997 request.result =
998 TelephonyManager
999 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1000 if (ar.exception instanceof CommandException) {
1001 CommandException.Error error =
1002 ((CommandException) (ar.exception)).getCommandError();
1003 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1004 request.result =
1005 TelephonyManager
1006 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001007 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1008 request.result =
1009 TelephonyManager
1010 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001011 }
1012 loge("enableNrDualConnectivity" + ": CommandException: "
1013 + ar.exception);
1014 } else {
1015 loge("enableNrDualConnectivity" + ": Unknown exception");
1016 }
1017 }
1018 notifyRequester(request);
1019 break;
1020 }
1021
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001022 case CMD_ENABLE_VONR: {
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1025 Phone phone = getPhoneFromRequest(request);
1026 if (phone != null) {
1027 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1028 request.workSource);
1029 } else {
1030 loge("setVoNrEnabled: No phone object");
1031 request.result =
1032 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1033 notifyRequester(request);
1034 }
1035 break;
1036 }
1037
1038 case EVENT_ENABLE_VONR_DONE: {
1039 ar = (AsyncResult) msg.obj;
1040 request = (MainThreadRequest) ar.userObj;
1041 if (ar.exception == null) {
1042 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1043 } else {
1044 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1045 if (ar.exception instanceof CommandException) {
1046 CommandException.Error error =
1047 ((CommandException) (ar.exception)).getCommandError();
1048 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1049 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1050 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1051 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1052 } else {
1053 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1054 }
1055 loge("setVoNrEnabled" + ": CommandException: "
1056 + ar.exception);
1057 } else {
1058 loge("setVoNrEnabled" + ": Unknown exception");
1059 }
1060 }
1061 notifyRequester(request);
1062 break;
1063 }
1064
SongFerngWang3ef3e072020-12-21 16:41:52 +08001065 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001066 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001067 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1068 request);
1069 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001070 break;
1071
SongFerngWang3ef3e072020-12-21 16:41:52 +08001072 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001073 ar = (AsyncResult) msg.obj;
1074 request = (MainThreadRequest) ar.userObj;
1075 if (ar.exception == null && ar.result != null) {
1076 request.result = ar.result; // Integer
1077 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301078 // request.result must be set to something non-null
1079 // for the calling thread to unblock
1080 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001081 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001082 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001083 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001084 loge("getAllowedNetworkTypesBitmask: CommandException: "
1085 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001086 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001087 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001088 }
1089 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001090 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001091 break;
1092
SongFerngWang3ef3e072020-12-21 16:41:52 +08001093 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001094 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001095 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1096 request);
1097 Pair<Integer, Long> reasonWithNetworkTypes =
1098 (Pair<Integer, Long>) request.argument;
1099 getPhoneFromRequest(request).setAllowedNetworkTypes(
1100 reasonWithNetworkTypes.first,
1101 reasonWithNetworkTypes.second,
1102 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001103 break;
1104
SongFerngWang3ef3e072020-12-21 16:41:52 +08001105 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1106 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001107 break;
1108
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001109 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1110 request = (MainThreadRequest)msg.obj;
1111 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001112 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001113 break;
1114
1115 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1116 ar = (AsyncResult)msg.obj;
1117 request = (MainThreadRequest)ar.userObj;
1118 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001119 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001120 break;
1121
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001122 case CMD_SET_VOICEMAIL_NUMBER:
1123 request = (MainThreadRequest) msg.obj;
1124 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1125 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001126 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1127 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001128 break;
1129
1130 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1131 handleNullReturnEvent(msg, "setVoicemailNumber");
1132 break;
1133
Stuart Scott54788802015-03-30 13:18:01 -07001134 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1135 request = (MainThreadRequest) msg.obj;
1136 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1137 request);
1138 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1139 break;
1140
1141 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1142 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1143 break;
1144
Shishir Agrawal302c8692015-06-19 13:49:39 -07001145 case CMD_PERFORM_NETWORK_SCAN:
1146 request = (MainThreadRequest) msg.obj;
1147 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1148 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1149 break;
1150
Hall Liu27d24262020-09-18 19:04:59 -07001151 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001152 request = (MainThreadRequest) msg.obj;
1153 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001154 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1155 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1156 request.argument;
1157 int callForwardingReason = args.first;
1158 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001159 break;
Hall Liu27d24262020-09-18 19:04:59 -07001160 }
1161 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001162 ar = (AsyncResult) msg.obj;
1163 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001164 TelephonyManager.CallForwardingInfoCallback callback =
1165 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1166 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001167 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001168 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001169 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1170 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1171 // Service Class is a bit mask per 3gpp 27.007. Search for
1172 // any service for voice call.
1173 if ((callForwardInfo.serviceClass
1174 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001175 callForwardingInfo = new CallForwardingInfo(
1176 callForwardInfo.status
1177 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001178 callForwardInfo.reason,
1179 callForwardInfo.number,
1180 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001181 break;
1182 }
1183 }
1184 // Didn't find a call forward info for voice call.
1185 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001186 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1187 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001188 }
Hall Liu27d24262020-09-18 19:04:59 -07001189 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001190 } else {
1191 if (ar.result == null) {
1192 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1193 }
1194 if (ar.exception != null) {
1195 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1196 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001197 int errorCode = TelephonyManager
1198 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001199 if (ar.exception instanceof CommandException) {
1200 CommandException.Error error =
1201 ((CommandException) (ar.exception)).getCommandError();
1202 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001203 errorCode = TelephonyManager
1204 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001205 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001206 errorCode = TelephonyManager
1207 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001208 }
1209 }
Hall Liu27d24262020-09-18 19:04:59 -07001210 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001211 }
Shuo Qian4a594052020-01-23 11:59:30 -08001212 break;
Hall Liu27d24262020-09-18 19:04:59 -07001213 }
Shuo Qian4a594052020-01-23 11:59:30 -08001214
Hall Liu27d24262020-09-18 19:04:59 -07001215 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001216 request = (MainThreadRequest) msg.obj;
1217 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001218 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001219 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001220 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1221 request.argument).first;
1222 request.phone.setCallForwardingOption(
1223 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001224 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001225 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001226 callForwardingInfoToSet.getReason(),
1227 callForwardingInfoToSet.getNumber(),
1228 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1229 break;
Hall Liu27d24262020-09-18 19:04:59 -07001230 }
Shuo Qian4a594052020-01-23 11:59:30 -08001231
Hall Liu27d24262020-09-18 19:04:59 -07001232 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001233 ar = (AsyncResult) msg.obj;
1234 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001235 Consumer<Integer> callback =
1236 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1237 request.argument).second;
1238 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001239 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001240 int errorCode = TelephonyManager.CallForwardingInfoCallback
1241 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001242 if (ar.exception instanceof CommandException) {
1243 CommandException.Error error =
1244 ((CommandException) (ar.exception)).getCommandError();
1245 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001246 errorCode = TelephonyManager.CallForwardingInfoCallback
1247 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001248 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001249 errorCode = TelephonyManager.CallForwardingInfoCallback
1250 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001251 }
1252 }
1253 callback.accept(errorCode);
1254 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001255 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001256 }
Shuo Qian4a594052020-01-23 11:59:30 -08001257 break;
Hall Liu27d24262020-09-18 19:04:59 -07001258 }
Shuo Qian4a594052020-01-23 11:59:30 -08001259
Hall Liu27d24262020-09-18 19:04:59 -07001260 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001261 request = (MainThreadRequest) msg.obj;
1262 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1263 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1264 break;
Hall Liu27d24262020-09-18 19:04:59 -07001265 }
Shuo Qian4a594052020-01-23 11:59:30 -08001266
Hall Liu27d24262020-09-18 19:04:59 -07001267 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001268 ar = (AsyncResult) msg.obj;
1269 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001270 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001271 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001272 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001273 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001274 // Service Class is a bit mask per 3gpp 27.007.
1275 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001276 if (callForwardResults.length > 1
1277 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001278 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001279 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001280 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1281 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001282 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001283 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001284 }
1285 } else {
1286 if (ar.result == null) {
1287 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1288 }
1289 if (ar.exception != null) {
1290 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1291 }
1292 if (ar.exception instanceof CommandException) {
1293 CommandException.Error error =
1294 ((CommandException) (ar.exception)).getCommandError();
1295 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001296 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001297 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001298 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1299 callWaitingStatus =
1300 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001301 }
1302 }
1303 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001304 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001305 break;
Hall Liu27d24262020-09-18 19:04:59 -07001306 }
Shuo Qian4a594052020-01-23 11:59:30 -08001307
Hall Liu27d24262020-09-18 19:04:59 -07001308 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001309 request = (MainThreadRequest) msg.obj;
1310 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001311 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1312 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001313 break;
Hall Liu27d24262020-09-18 19:04:59 -07001314 }
Shuo Qian4a594052020-01-23 11:59:30 -08001315
Hall Liu27d24262020-09-18 19:04:59 -07001316 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001317 ar = (AsyncResult) msg.obj;
1318 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001319 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1320 Consumer<Integer> callback =
1321 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1322 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001323 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001324 if (ar.exception instanceof CommandException) {
1325 CommandException.Error error =
1326 ((CommandException) (ar.exception)).getCommandError();
1327 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1328 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001329 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1330 callback.accept(
1331 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001332 } else {
1333 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1334 }
1335 } else {
1336 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1337 }
1338 } else {
1339 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1340 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001341 }
Shuo Qian4a594052020-01-23 11:59:30 -08001342 break;
Hall Liu27d24262020-09-18 19:04:59 -07001343 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001344 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1345 ar = (AsyncResult) msg.obj;
1346 request = (MainThreadRequest) ar.userObj;
1347 CellNetworkScanResult cellScanResult;
1348 if (ar.exception == null && ar.result != null) {
1349 cellScanResult = new CellNetworkScanResult(
1350 CellNetworkScanResult.STATUS_SUCCESS,
1351 (List<OperatorInfo>) ar.result);
1352 } else {
1353 if (ar.result == null) {
1354 loge("getCellNetworkScanResults: Empty response");
1355 }
1356 if (ar.exception != null) {
1357 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1358 }
1359 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1360 if (ar.exception instanceof CommandException) {
1361 CommandException.Error error =
1362 ((CommandException) (ar.exception)).getCommandError();
1363 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1364 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1365 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1366 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1367 }
1368 }
1369 cellScanResult = new CellNetworkScanResult(errorCode, null);
1370 }
1371 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001372 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001373 break;
1374
1375 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1376 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001377 ManualNetworkSelectionArgument selArg =
1378 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001379 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1380 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001381 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1382 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001383 break;
1384
1385 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001386 ar = (AsyncResult) msg.obj;
1387 request = (MainThreadRequest) ar.userObj;
1388 if (ar.exception == null) {
1389 request.result = true;
1390 } else {
1391 request.result = false;
1392 loge("setNetworkSelectionModeManual " + ar.exception);
1393 }
1394 notifyRequester(request);
1395 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001396 break;
1397
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001398 case CMD_GET_MODEM_ACTIVITY_INFO:
1399 request = (MainThreadRequest) msg.obj;
1400 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001401 if (defaultPhone != null) {
1402 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001403 } else {
1404 ResultReceiver result = (ResultReceiver) request.argument;
1405 Bundle bundle = new Bundle();
1406 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001407 new ModemActivityInfo(0, 0, 0,
1408 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001409 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001410 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001411 break;
1412
Hall Liud0f208c2020-10-14 16:54:44 -07001413 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001414 ar = (AsyncResult) msg.obj;
1415 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001416 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001417 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001418 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001419 if (mLastModemActivityInfo == null) {
1420 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1421 mLastModemActivitySpecificInfo[0] =
1422 new ActivityStatsTechSpecificInfo(
1423 0,
1424 0,
1425 new int[ModemActivityInfo.getNumTxPowerLevels()],
1426 0);
1427 mLastModemActivityInfo =
1428 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1429 }
1430
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001431 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001432 // Update the last modem activity info and the result of the request.
1433 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1434 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001435 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001436 }
Kai Shi917fdc62022-11-28 14:01:02 -08001437 // This is needed to decouple ret from mLastModemActivityInfo
1438 // We don't want to return mLastModemActivityInfo which is updated
1439 // inside mergeModemActivityInfo()
1440 ret = new ModemActivityInfo(
1441 mLastModemActivityInfo.getTimestampMillis(),
1442 mLastModemActivityInfo.getSleepTimeMillis(),
1443 mLastModemActivityInfo.getIdleTimeMillis(),
1444 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001445
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001446 } else {
1447 if (ar.result == null) {
1448 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001449 error = TelephonyManager.ModemActivityInfoException
1450 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001451 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001452 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001453 error = TelephonyManager.ModemActivityInfoException
1454 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001455 } else {
1456 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001457 error = TelephonyManager.ModemActivityInfoException
1458 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001459 }
1460 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001461 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001462 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001463 bundle.putParcelable(
1464 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001465 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001466 } else {
1467 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1468 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001469 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001470 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001471 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001472 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001473
Meng Wang1a7c35a2016-05-05 20:56:15 -07001474 case CMD_SET_ALLOWED_CARRIERS:
1475 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001476 CarrierRestrictionRules argument =
1477 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001478 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001479 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001480 break;
1481
1482 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1483 ar = (AsyncResult) msg.obj;
1484 request = (MainThreadRequest) ar.userObj;
1485 if (ar.exception == null && ar.result != null) {
1486 request.result = ar.result;
1487 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001488 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1489 if (ar.exception instanceof CommandException) {
1490 loge("setAllowedCarriers: CommandException: " + ar.exception);
1491 CommandException.Error error =
1492 ((CommandException) (ar.exception)).getCommandError();
1493 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1494 request.result =
1495 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1496 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001497 } else {
1498 loge("setAllowedCarriers: Unknown exception");
1499 }
1500 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001501 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001502 break;
1503
1504 case CMD_GET_ALLOWED_CARRIERS:
1505 request = (MainThreadRequest) msg.obj;
1506 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001507 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001508 break;
1509
1510 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1511 ar = (AsyncResult) msg.obj;
1512 request = (MainThreadRequest) ar.userObj;
1513 if (ar.exception == null && ar.result != null) {
1514 request.result = ar.result;
1515 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001516 request.result = new IllegalStateException(
1517 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001518 if (ar.result == null) {
1519 loge("getAllowedCarriers: Empty response");
1520 } else if (ar.exception instanceof CommandException) {
1521 loge("getAllowedCarriers: CommandException: " +
1522 ar.exception);
1523 } else {
1524 loge("getAllowedCarriers: Unknown exception");
1525 }
1526 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001527 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001528 break;
1529
Nathan Haroldb3014052017-01-25 15:57:32 -08001530 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1531 ar = (AsyncResult) msg.obj;
1532 request = (MainThreadRequest) ar.userObj;
1533 if (ar.exception == null && ar.result != null) {
1534 request.result = ar.result;
1535 } else {
1536 request.result = new IllegalArgumentException(
1537 "Failed to retrieve Forbidden Plmns");
1538 if (ar.result == null) {
1539 loge("getForbiddenPlmns: Empty response");
1540 } else {
1541 loge("getForbiddenPlmns: Unknown exception");
1542 }
1543 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001544 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001545 break;
1546
1547 case CMD_GET_FORBIDDEN_PLMNS:
1548 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001549 uiccPort = getUiccPortFromRequest(request);
1550 if (uiccPort == null) {
1551 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001552 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001553 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001554 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001555 break;
1556 }
1557 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001558 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001559 if (uiccApp == null) {
1560 loge("getForbiddenPlmns() no app with specified type -- "
1561 + appType);
1562 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001563 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001564 break;
1565 } else {
1566 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1567 + " specified type -- " + appType);
1568 }
1569 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1570 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1571 onCompleted);
1572 break;
1573
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001574 case CMD_SWITCH_SLOTS:
1575 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001576 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001577 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001578 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001579 break;
1580
1581 case EVENT_SWITCH_SLOTS_DONE:
1582 ar = (AsyncResult) msg.obj;
1583 request = (MainThreadRequest) ar.userObj;
1584 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001585 notifyRequester(request);
1586 break;
1587 case CMD_GET_NETWORK_SELECTION_MODE:
1588 request = (MainThreadRequest) msg.obj;
1589 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1590 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1591 break;
1592
1593 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1594 ar = (AsyncResult) msg.obj;
1595 request = (MainThreadRequest) ar.userObj;
1596 if (ar.exception != null) {
1597 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1598 } else {
1599 int mode = ((int[]) ar.result)[0];
1600 if (mode == 0) {
1601 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1602 } else {
1603 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1604 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001605 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001606 notifyRequester(request);
1607 break;
1608 case CMD_GET_CDMA_ROAMING_MODE:
1609 request = (MainThreadRequest) msg.obj;
1610 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1611 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1612 break;
1613 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1614 ar = (AsyncResult) msg.obj;
1615 request = (MainThreadRequest) ar.userObj;
1616 if (ar.exception != null) {
1617 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1618 } else {
1619 request.result = ((int[]) ar.result)[0];
1620 }
1621 notifyRequester(request);
1622 break;
1623 case CMD_SET_CDMA_ROAMING_MODE:
1624 request = (MainThreadRequest) msg.obj;
1625 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1626 int mode = (int) request.argument;
1627 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1628 break;
1629 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1630 ar = (AsyncResult) msg.obj;
1631 request = (MainThreadRequest) ar.userObj;
1632 request.result = ar.exception == null;
1633 notifyRequester(request);
1634 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001635 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1636 request = (MainThreadRequest) msg.obj;
1637 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1638 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1639 break;
1640 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1641 ar = (AsyncResult) msg.obj;
1642 request = (MainThreadRequest) ar.userObj;
1643 if (ar.exception != null) {
1644 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1645 } else {
1646 request.result = ((int[]) ar.result)[0];
1647 }
1648 notifyRequester(request);
1649 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001650 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1651 request = (MainThreadRequest) msg.obj;
1652 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1653 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001654 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1655 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001656 break;
1657 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1658 ar = (AsyncResult) msg.obj;
1659 request = (MainThreadRequest) ar.userObj;
1660 request.result = ar.exception == null;
1661 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001662 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001663 case CMD_GET_ALL_CELL_INFO:
1664 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001665 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001666 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001667 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001668 case EVENT_GET_ALL_CELL_INFO_DONE:
1669 ar = (AsyncResult) msg.obj;
1670 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001671 // If a timeout occurs, the response will be null
1672 request.result = (ar.exception == null && ar.result != null)
1673 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001674 synchronized (request) {
1675 request.notifyAll();
1676 }
1677 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001678 case CMD_REQUEST_CELL_INFO_UPDATE:
1679 request = (MainThreadRequest) msg.obj;
1680 request.phone.requestCellInfoUpdate(request.workSource,
1681 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1682 break;
1683 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1684 ar = (AsyncResult) msg.obj;
1685 request = (MainThreadRequest) ar.userObj;
1686 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1687 try {
1688 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001689 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001690 cb.onError(
1691 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1692 ar.exception.getClass().getName(),
1693 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001694 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001695 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001696 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001697 } else {
1698 // use the result as returned
1699 cb.onCellInfo((List<CellInfo>) ar.result);
1700 }
1701 } catch (RemoteException re) {
1702 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1703 }
1704 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001705 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001706 request = (MainThreadRequest) msg.obj;
1707 WorkSource ws = (WorkSource) request.argument;
1708 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001709 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001710 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001711 }
1712 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 if (ar.exception == null) {
1716 request.result = ar.result;
1717 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001718 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001719 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001720 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001721 }
1722
1723 synchronized (request) {
1724 request.notifyAll();
1725 }
1726 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001727 }
chen xu6dac5ab2018-10-26 17:39:23 -07001728 case CMD_MODEM_REBOOT:
1729 request = (MainThreadRequest) msg.obj;
1730 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001731 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001732 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001733 case EVENT_CMD_MODEM_REBOOT_DONE:
1734 handleNullReturnEvent(msg, "rebootModem");
1735 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001736 case CMD_REQUEST_ENABLE_MODEM:
1737 request = (MainThreadRequest) msg.obj;
1738 boolean enable = (boolean) request.argument;
1739 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001740 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001741 PhoneConfigurationManager.getInstance()
1742 .enablePhone(request.phone, enable, onCompleted);
1743 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001744 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001745 ar = (AsyncResult) msg.obj;
1746 request = (MainThreadRequest) ar.userObj;
1747 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001748 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001749 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001750 if ((boolean) request.result) {
1751 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1752 updateModemStateMetrics();
1753 } else {
1754 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1755 + ar.exception);
1756 }
1757 notifyRequester(request);
1758 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001759 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001760 case CMD_GET_MODEM_STATUS:
1761 request = (MainThreadRequest) msg.obj;
1762 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1763 PhoneConfigurationManager.getInstance()
1764 .getPhoneStatusFromModem(request.phone, onCompleted);
1765 break;
1766 case EVENT_GET_MODEM_STATUS_DONE:
1767 ar = (AsyncResult) msg.obj;
1768 request = (MainThreadRequest) ar.userObj;
1769 int id = request.phone.getPhoneId();
1770 if (ar.exception == null && ar.result != null) {
1771 request.result = ar.result;
1772 //update the cache as modem status has changed
1773 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1774 (boolean) request.result);
1775 } else {
1776 // Return true if modem status cannot be retrieved. For most cases,
1777 // modem status is on. And for older version modems, GET_MODEM_STATUS
1778 // and disable modem are not supported. Modem is always on.
1779 // TODO: this should be fixed in R to support a third
1780 // status UNKNOWN b/131631629
1781 request.result = true;
1782 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1783 + ar.exception);
1784 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001785 notifyRequester(request);
1786 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001787 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1788 request = (MainThreadRequest) msg.obj;
1789 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1790 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1791 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1792 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1793 break;
1794 }
1795 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1796 ar = (AsyncResult) msg.obj;
1797 request = (MainThreadRequest) ar.userObj;
1798 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1799 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1800 args.second.accept(ar.exception == null);
1801 notifyRequester(request);
1802 break;
1803 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001804 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1805 request = (MainThreadRequest) msg.obj;
1806 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1807 Phone phone = getPhoneFromRequest(request);
1808 if (phone != null) {
1809 phone.getSystemSelectionChannels(onCompleted);
1810 } else {
1811 loge("getSystemSelectionChannels: No phone object");
1812 request.result = new ArrayList<RadioAccessSpecifier>();
1813 notifyRequester(request);
1814 }
1815 break;
1816 }
1817 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1818 ar = (AsyncResult) msg.obj;
1819 request = (MainThreadRequest) ar.userObj;
1820 if (ar.exception == null && ar.result != null) {
1821 request.result = ar.result;
1822 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001823 request.result = new IllegalStateException(
1824 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001825 if (ar.result == null) {
1826 loge("getSystemSelectionChannels: Empty response");
1827 } else {
1828 loge("getSystemSelectionChannels: Unknown exception");
1829 }
1830 }
1831 notifyRequester(request);
1832 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001833 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1834 ar = (AsyncResult) msg.obj;
1835 request = (MainThreadRequest) ar.userObj;
1836 if (ar.exception == null && ar.result != null) {
1837 request.result = ar.result;
1838 } else {
1839 request.result = -1;
1840 loge("Failed to set Forbidden Plmns");
1841 if (ar.result == null) {
1842 loge("setForbidenPlmns: Empty response");
1843 } else if (ar.exception != null) {
1844 loge("setForbiddenPlmns: Exception: " + ar.exception);
1845 request.result = -1;
1846 } else {
1847 loge("setForbiddenPlmns: Unknown exception");
1848 }
1849 }
1850 notifyRequester(request);
1851 break;
1852 case CMD_SET_FORBIDDEN_PLMNS:
1853 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001854 uiccPort = getUiccPortFromRequest(request);
1855 if (uiccPort == null) {
1856 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001857 request.result = -1;
1858 notifyRequester(request);
1859 break;
1860 }
1861 Pair<Integer, List<String>> setFplmnsArgs =
1862 (Pair<Integer, List<String>>) request.argument;
1863 appType = setFplmnsArgs.first;
1864 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001865 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001866 if (uiccApp == null) {
1867 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1868 request.result = -1;
1869 loge("Failed to get UICC App");
1870 notifyRequester(request);
1871 } else {
1872 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1873 ((SIMRecords) uiccApp.getIccRecords())
1874 .setForbiddenPlmns(onCompleted, fplmns);
1875 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001876 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001877 case CMD_ERASE_MODEM_CONFIG:
1878 request = (MainThreadRequest) msg.obj;
1879 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1880 defaultPhone.eraseModemConfig(onCompleted);
1881 break;
1882 case EVENT_ERASE_MODEM_CONFIG_DONE:
1883 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001884 break;
zoey chene02881a2019-12-30 16:11:23 +08001885
Kai Shif70f46f2021-03-03 13:59:46 -08001886 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1887 request = (MainThreadRequest) msg.obj;
1888 request.result = defaultPhone.eraseDataInSharedPreferences();
1889 notifyRequester(request);
1890 break;
1891
zoey chene02881a2019-12-30 16:11:23 +08001892 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1893 request = (MainThreadRequest) msg.obj;
1894 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1895 Pair<String, String> changed = (Pair<String, String>) request.argument;
1896 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1897 changed.first, changed.second, onCompleted);
1898 break;
1899 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1900 ar = (AsyncResult) msg.obj;
1901 request = (MainThreadRequest) ar.userObj;
1902 if (ar.exception == null) {
1903 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001904 // If the operation is successful, update the PIN storage
1905 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1906 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001907 UiccController.getInstance().getPinStorage()
1908 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001909 } else {
1910 request.result = msg.arg1;
1911 }
1912 notifyRequester(request);
1913 break;
1914
Michele Berionne5e411512020-11-13 02:36:59 +00001915 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001916 request = (MainThreadRequest) msg.obj;
1917 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1918 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1919 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1920 enabled.first, enabled.second, onCompleted);
1921 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001922 }
zoey chene02881a2019-12-30 16:11:23 +08001923 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1924 ar = (AsyncResult) msg.obj;
1925 request = (MainThreadRequest) ar.userObj;
1926 if (ar.exception == null) {
1927 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001928 // If the operation is successful, update the PIN storage
1929 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1930 int phoneId = getPhoneFromRequest(request).getPhoneId();
1931 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001932 UiccController.getInstance().getPinStorage()
1933 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001934 } else {
1935 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1936 }
zoey chene02881a2019-12-30 16:11:23 +08001937 } else {
1938 request.result = msg.arg1;
1939 }
Michele Berionne5e411512020-11-13 02:36:59 +00001940
1941
zoey chene02881a2019-12-30 16:11:23 +08001942 notifyRequester(request);
1943 break;
1944
Peter Wangdafb9ac2020-01-15 14:13:38 -08001945 case MSG_NOTIFY_USER_ACTIVITY:
1946 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001947 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001948 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1949 getDefaultPhone().getContext().sendBroadcastAsUser(
1950 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1951 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001952
1953 case CMD_SET_DATA_THROTTLING: {
1954 request = (MainThreadRequest) msg.obj;
1955 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1956 DataThrottlingRequest dataThrottlingRequest =
1957 (DataThrottlingRequest) request.argument;
1958 Phone phone = getPhoneFromRequest(request);
1959 if (phone != null) {
1960 phone.setDataThrottling(onCompleted,
1961 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1962 dataThrottlingRequest.getCompletionDurationMillis());
1963 } else {
1964 loge("setDataThrottling: No phone object");
1965 request.result =
1966 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1967 notifyRequester(request);
1968 }
1969
1970 break;
1971 }
1972 case EVENT_SET_DATA_THROTTLING_DONE:
1973 ar = (AsyncResult) msg.obj;
1974 request = (MainThreadRequest) ar.userObj;
1975
1976 if (ar.exception == null) {
1977 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1978 } else if (ar.exception instanceof CommandException) {
1979 loge("setDataThrottling: CommandException: " + ar.exception);
1980 CommandException.Error error =
1981 ((CommandException) (ar.exception)).getCommandError();
1982
1983 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1984 request.result = TelephonyManager
1985 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1986 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1987 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001988 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1989 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001990 } else {
1991 request.result =
1992 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1993 }
1994 } else {
1995 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1996 }
1997 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1998 notifyRequester(request);
1999 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002000
2001 case CMD_SET_SIM_POWER: {
2002 request = (MainThreadRequest) msg.obj;
2003 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2004 request = (MainThreadRequest) msg.obj;
2005 int stateToSet =
2006 ((Pair<Integer, IIntegerConsumer>)
2007 request.argument).first;
2008 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2009 break;
2010 }
2011 case EVENT_SET_SIM_POWER_DONE: {
2012 ar = (AsyncResult) msg.obj;
2013 request = (MainThreadRequest) ar.userObj;
2014 IIntegerConsumer callback =
2015 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2016 if (ar.exception != null) {
2017 loge("setSimPower exception: " + ar.exception);
2018 int errorCode = TelephonyManager.CallForwardingInfoCallback
2019 .RESULT_ERROR_UNKNOWN;
2020 if (ar.exception instanceof CommandException) {
2021 CommandException.Error error =
2022 ((CommandException) (ar.exception)).getCommandError();
2023 if (error == CommandException.Error.SIM_ERR) {
2024 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2025 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2026 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2027 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2028 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2029 } else {
2030 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2031 }
2032 }
2033 try {
2034 callback.accept(errorCode);
2035 } catch (RemoteException e) {
2036 // Ignore if the remote process is no longer available to call back.
2037 Log.w(LOG_TAG, "setSimPower: callback not available.");
2038 }
2039 } else {
2040 try {
2041 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2042 } catch (RemoteException e) {
2043 // Ignore if the remote process is no longer available to call back.
2044 Log.w(LOG_TAG, "setSimPower: callback not available.");
2045 }
2046 }
2047 break;
2048 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002049 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2050 request = (MainThreadRequest) msg.obj;
2051
2052 final Phone phone = getPhoneFromRequest(request);
2053 if (phone == null || phone.getServiceStateTracker() == null) {
2054 request.result = new IllegalStateException("Phone or SST is null");
2055 notifyRequester(request);
2056 break;
2057 }
2058
2059 Pair<Integer, SignalStrengthUpdateRequest> pair =
2060 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2061 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2062 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002063 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002064 request.subId, pair.first /*callingUid*/,
2065 pair.second /*request*/, onCompleted);
2066 break;
2067 }
2068 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2069 ar = (AsyncResult) msg.obj;
2070 request = (MainThreadRequest) ar.userObj;
2071 // request.result will be the exception of ar if present, true otherwise.
2072 // Be cautious not to leave result null which will wait() forever
2073 request.result = ar.exception != null ? ar.exception : true;
2074 notifyRequester(request);
2075 break;
2076 }
2077 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2078 request = (MainThreadRequest) msg.obj;
2079
2080 Phone phone = getPhoneFromRequest(request);
2081 if (phone == null || phone.getServiceStateTracker() == null) {
2082 request.result = new IllegalStateException("Phone or SST is null");
2083 notifyRequester(request);
2084 break;
2085 }
2086
2087 Pair<Integer, SignalStrengthUpdateRequest> pair =
2088 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2089 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2090 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002091 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002092 request.subId, pair.first /*callingUid*/,
2093 pair.second /*request*/, onCompleted);
2094 break;
2095 }
2096 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2097 ar = (AsyncResult) msg.obj;
2098 request = (MainThreadRequest) ar.userObj;
2099 request.result = ar.exception != null ? ar.exception : true;
2100 notifyRequester(request);
2101 break;
2102 }
Jordan Liu109698e2020-11-24 14:50:34 -08002103
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002104 case CMD_GET_SLICING_CONFIG: {
2105 request = (MainThreadRequest) msg.obj;
2106 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2107 request.phone.getSlicingConfig(onCompleted);
2108 break;
2109 }
2110 case EVENT_GET_SLICING_CONFIG_DONE: {
2111 ar = (AsyncResult) msg.obj;
2112 request = (MainThreadRequest) ar.userObj;
2113 ResultReceiver result = (ResultReceiver) request.argument;
2114
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002115 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002116 Bundle bundle = new Bundle();
2117 int resultCode = 0;
2118 if (ar.exception != null) {
2119 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2120 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002121 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002122 } else if (ar.result == null) {
2123 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002124 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002125 } else {
2126 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002127 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2128 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002129 }
2130
2131 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002132 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002133 }
2134 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2135 result.send(resultCode, bundle);
2136 notifyRequester(request);
2137 break;
2138 }
2139
Michele Berionne5e411512020-11-13 02:36:59 +00002140 case CMD_PREPARE_UNATTENDED_REBOOT:
2141 request = (MainThreadRequest) msg.obj;
2142 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002143 UiccController.getInstance().getPinStorage()
2144 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002145 notifyRequester(request);
2146 break;
2147
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002148 default:
2149 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2150 break;
2151 }
2152 }
Jake Hambye994d462014-02-03 13:10:13 -08002153
Pengquan Menga1bb6272018-09-06 09:59:22 -07002154 private void notifyRequester(MainThreadRequest request) {
2155 synchronized (request) {
2156 request.notifyAll();
2157 }
2158 }
2159
Jake Hambye994d462014-02-03 13:10:13 -08002160 private void handleNullReturnEvent(Message msg, String command) {
2161 AsyncResult ar = (AsyncResult) msg.obj;
2162 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2163 if (ar.exception == null) {
2164 request.result = true;
2165 } else {
2166 request.result = false;
2167 if (ar.exception instanceof CommandException) {
2168 loge(command + ": CommandException: " + ar.exception);
2169 } else {
2170 loge(command + ": Unknown exception");
2171 }
2172 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002173 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002174 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175 }
2176
2177 /**
2178 * Posts the specified command to be executed on the main thread,
2179 * waits for the request to complete, and returns the result.
2180 * @see #sendRequestAsync
2181 */
2182 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002183 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2184 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002185 }
2186
2187 /**
2188 * Posts the specified command to be executed on the main thread,
2189 * waits for the request to complete, and returns the result.
2190 * @see #sendRequestAsync
2191 */
2192 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2193 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002194 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002195 }
2196
2197 /**
2198 * Posts the specified command to be executed on the main thread,
2199 * waits for the request to complete, and returns the result.
2200 * @see #sendRequestAsync
2201 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002202 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002203 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2204 }
2205
2206 /**
2207 * Posts the specified command to be executed on the main thread,
2208 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2209 * if not timeout or null otherwise.
2210 * @see #sendRequestAsync
2211 */
2212 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2213 long timeoutInMs) {
2214 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002215 }
2216
2217 /**
2218 * Posts the specified command to be executed on the main thread,
2219 * waits for the request to complete, and returns the result.
2220 * @see #sendRequestAsync
2221 */
Nathan Harold92bed182018-10-12 18:16:49 -07002222 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002223 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002224 }
2225
2226 /**
2227 * Posts the specified command to be executed on the main thread,
2228 * waits for the request to complete, and returns the result.
2229 * @see #sendRequestAsync
2230 */
2231 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002232 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2233 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002234 }
2235
2236 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002237 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2238 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2239 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002240 * @see #sendRequestAsync
2241 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002242 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2243 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2245 throw new RuntimeException("This method will deadlock if called from the main thread.");
2246 }
2247
Nathan Harold92bed182018-10-12 18:16:49 -07002248 MainThreadRequest request = null;
2249 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2250 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2251 } else if (phone != null) {
2252 request = new MainThreadRequest(argument, phone, workSource);
2253 } else {
2254 request = new MainThreadRequest(argument, subId, workSource);
2255 }
2256
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 Message msg = mMainThreadHandler.obtainMessage(command, request);
2258 msg.sendToTarget();
2259
Rambo Wang0f050d82021-02-12 11:43:36 -08002260
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002262 if (timeoutInMs >= 0) {
2263 // Wait for at least timeoutInMs before returning null request result
2264 long now = SystemClock.elapsedRealtime();
2265 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002266 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002267 try {
2268 request.wait(deadline - now);
2269 } catch (InterruptedException e) {
2270 // Do nothing, go back and check if request is completed or timeout
2271 } finally {
2272 now = SystemClock.elapsedRealtime();
2273 }
2274 }
2275 } else {
2276 // Wait for the request to complete
2277 while (request.result == null) {
2278 try {
2279 request.wait();
2280 } catch (InterruptedException e) {
2281 // Do nothing, go back and wait until the request is complete
2282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 }
2284 }
2285 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002286 if (request.result == null) {
2287 Log.wtf(LOG_TAG,
2288 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290 return request.result;
2291 }
2292
2293 /**
2294 * Asynchronous ("fire and forget") version of sendRequest():
2295 * Posts the specified command to be executed on the main thread, and
2296 * returns immediately.
2297 * @see #sendRequest
2298 */
2299 private void sendRequestAsync(int command) {
2300 mMainThreadHandler.sendEmptyMessage(command);
2301 }
2302
2303 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002304 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002305 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002306 */
2307 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002308 sendRequestAsync(command, argument, null, null);
2309 }
2310
2311 /**
2312 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2313 * @see {@link #sendRequest(int,Object)}
2314 */
2315 private void sendRequestAsync(
2316 int command, Object argument, Phone phone, WorkSource workSource) {
2317 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002318 Message msg = mMainThreadHandler.obtainMessage(command, request);
2319 msg.sendToTarget();
2320 }
2321
2322 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 * Initialize the singleton PhoneInterfaceManager instance.
2324 * This is only done once, at startup, from PhoneApp.onCreate().
2325 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002326 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 synchronized (PhoneInterfaceManager.class) {
2328 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002329 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 } else {
2331 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2332 }
2333 return sInstance;
2334 }
2335 }
2336
2337 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002338 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002341 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002342 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002344 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002346 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002347 mTelephonySharedPreferences =
2348 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002349 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002350 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002351 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002352 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002353 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002354 mTelephony2gUpdater = new Telephony2gUpdater(
2355 Executors.newSingleThreadExecutor(), mApp);
2356 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 publish();
2358 }
2359
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002360 private Phone getDefaultPhone() {
2361 Phone thePhone = getPhone(getDefaultSubscription());
2362 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2363 }
2364
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365 private void publish() {
2366 if (DBG) log("publish: " + this);
2367
Peter Wangc035ce42020-01-08 21:00:22 -08002368 TelephonyFrameworkInitializer
2369 .getTelephonyServiceManager()
2370 .getTelephonyServiceRegisterer()
2371 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 }
2373
Stuart Scott584921c2015-01-15 17:10:34 -08002374 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002375 if (request.phone != null) {
2376 return request.phone;
2377 } else {
2378 return getPhoneFromSubId(request.subId);
2379 }
2380 }
2381
2382 private Phone getPhoneFromSubId(int subId) {
2383 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2384 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002385 }
2386
Rambo Wange53e07d2022-05-10 13:01:13 -07002387 @Nullable
2388 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002389 Phone phone = getPhoneFromRequest(request);
2390 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002391 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002392 }
2393
Wink Saville36469e72014-06-11 15:17:00 -07002394 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002395 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002396 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002398
Kai Shif70f46f2021-03-03 13:59:46 -08002399 private void sendEraseModemConfig(@NonNull Phone phone) {
2400 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2401 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2402 }
2403
2404 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2405 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2406 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002407 }
2408
Peter Wang44b186e2020-01-13 23:33:09 -08002409 private boolean isImsAvailableOnDevice() {
2410 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2411 if (pm == null) {
2412 // For some reason package manger is not available.. This will fail internally anyway,
2413 // so do not throw error and allow.
2414 return true;
2415 }
2416 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2417 }
2418
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002420 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002421 }
2422
Wink Savilleb564aae2014-10-23 10:18:09 -07002423 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 if (DBG) log("dial: " + number);
2425 // No permission check needed here: This is just a wrapper around the
2426 // ACTION_DIAL intent, which is available to any app since it puts up
2427 // the UI before it does anything.
2428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002429 final long identity = Binder.clearCallingIdentity();
2430 try {
2431 String url = createTelUrl(number);
2432 if (url == null) {
2433 return;
2434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002436 // PENDING: should we just silently fail if phone is offhook or ringing?
2437 PhoneConstants.State state = mCM.getState(subId);
2438 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2439 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2440 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2441 mApp.startActivity(intent);
2442 }
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 }
2446 }
2447
2448 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002449 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002450 }
2451
Wink Savilleb564aae2014-10-23 10:18:09 -07002452 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 if (DBG) log("call: " + number);
2454
2455 // This is just a wrapper around the ACTION_CALL intent, but we still
2456 // need to do a permission check since we're calling startActivity()
2457 // from the context of the phone app.
2458 enforceCallPermission();
2459
Jordan Liu1617b712019-07-10 15:06:26 -07002460 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 != AppOpsManager.MODE_ALLOWED) {
2462 return;
2463 }
2464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 String url = createTelUrl(number);
2468 if (url == null) {
2469 return;
2470 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472 boolean isValid = false;
2473 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2474 if (slist != null) {
2475 for (SubscriptionInfo subInfoRecord : slist) {
2476 if (subInfoRecord.getSubscriptionId() == subId) {
2477 isValid = true;
2478 break;
2479 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002480 }
Wink Saville08874612014-08-31 19:19:58 -07002481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482 if (!isValid) {
2483 return;
2484 }
Wink Saville08874612014-08-31 19:19:58 -07002485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2487 intent.putExtra(SUBSCRIPTION_KEY, subId);
2488 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2489 mApp.startActivity(intent);
2490 } finally {
2491 Binder.restoreCallingIdentity(identity);
2492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 }
2494
Wink Savilleb564aae2014-10-23 10:18:09 -07002495 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002496 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002497 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2498 }
2499
Wink Savilleb564aae2014-10-23 10:18:09 -07002500 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002501 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002502 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2503 }
2504
Wink Savilleb564aae2014-10-23 10:18:09 -07002505 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507
2508 final long identity = Binder.clearCallingIdentity();
2509 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002510 Phone phone = getPhone(subId);
2511 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 checkSimPin.start();
2513 return checkSimPin.unlockSim(null, pin);
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
2516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
Wink Savilleb564aae2014-10-23 10:18:09 -07002519 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002521
2522 final long identity = Binder.clearCallingIdentity();
2523 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002524 Phone phone = getPhone(subId);
2525 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002526 checkSimPuk.start();
2527 return checkSimPuk.unlockSim(puk, pin);
2528 } finally {
2529 Binder.restoreCallingIdentity(identity);
2530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 }
2532
2533 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002534 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002535 * a synchronous one.
2536 */
2537 private static class UnlockSim extends Thread {
2538
2539 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002540 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541
2542 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002543 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2544 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002545
2546 // For replies from SimCard interface
2547 private Handler mHandler;
2548
2549 // For async handler to identify request type
2550 private static final int SUPPLY_PIN_COMPLETE = 100;
2551
Michele Berionne5e411512020-11-13 02:36:59 +00002552 UnlockSim(int phoneId, IccCard simCard) {
2553 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 mSimCard = simCard;
2555 }
2556
2557 @Override
2558 public void run() {
2559 Looper.prepare();
2560 synchronized (UnlockSim.this) {
2561 mHandler = new Handler() {
2562 @Override
2563 public void handleMessage(Message msg) {
2564 AsyncResult ar = (AsyncResult) msg.obj;
2565 switch (msg.what) {
2566 case SUPPLY_PIN_COMPLETE:
2567 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2568 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002569 mRetryCount = msg.arg1;
2570 if (ar.exception != null) {
2571 if (ar.exception instanceof CommandException &&
2572 ((CommandException)(ar.exception)).getCommandError()
2573 == CommandException.Error.PASSWORD_INCORRECT) {
2574 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002575 } //When UiccCardApp dispose,handle message and return exception
2576 else if (ar.exception instanceof CommandException &&
2577 ((CommandException) (ar.exception)).getCommandError()
2578 == CommandException.Error.ABORTED) {
2579 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002580 } else {
2581 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2582 }
2583 } else {
2584 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 mDone = true;
2587 UnlockSim.this.notifyAll();
2588 }
2589 break;
2590 }
2591 }
2592 };
2593 UnlockSim.this.notifyAll();
2594 }
2595 Looper.loop();
2596 }
2597
2598 /*
2599 * Use PIN or PUK to unlock SIM card
2600 *
2601 * If PUK is null, unlock SIM card with PIN
2602 *
2603 * If PUK is not null, unlock SIM card with PUK and set PIN code
2604 */
Wink Saville9de0f752013-10-22 19:04:03 -07002605 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606
2607 while (mHandler == null) {
2608 try {
2609 wait();
2610 } catch (InterruptedException e) {
2611 Thread.currentThread().interrupt();
2612 }
2613 }
2614 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2615
2616 if (puk == null) {
2617 mSimCard.supplyPin(pin, callback);
2618 } else {
2619 mSimCard.supplyPuk(puk, pin, callback);
2620 }
2621
2622 while (!mDone) {
2623 try {
2624 Log.d(LOG_TAG, "wait for done");
2625 wait();
2626 } catch (InterruptedException e) {
2627 // Restore the interrupted status
2628 Thread.currentThread().interrupt();
2629 }
2630 }
2631 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002632 int[] resultArray = new int[2];
2633 resultArray[0] = mResult;
2634 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002635
2636 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002637 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002638 }
2639
Wink Saville9de0f752013-10-22 19:04:03 -07002640 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002641 }
2642 }
2643
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002644 /**
2645 * This method has been removed due to privacy and stability concerns.
2646 */
2647 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002649 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2650 return;
Wink Saville36469e72014-06-11 15:17:00 -07002651 }
2652
Nathan Harold1f889d82020-06-04 17:05:26 -07002653 @Override
2654 public void updateServiceLocationWithPackageName(String callingPackage) {
2655 mApp.getSystemService(AppOpsManager.class)
2656 .checkPackage(Binder.getCallingUid(), callingPackage);
2657
Nathan Haroldf096d982020-11-18 17:18:06 -08002658 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002659 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2660 // Callers targeting S have no business invoking this method.
2661 return;
2662 }
2663
2664 LocationAccessPolicy.LocationPermissionResult locationResult =
2665 LocationAccessPolicy.checkLocationPermission(mApp,
2666 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2667 .setCallingPackage(callingPackage)
2668 .setCallingFeatureId(null)
2669 .setCallingPid(Binder.getCallingPid())
2670 .setCallingUid(Binder.getCallingUid())
2671 .setMethod("updateServiceLocation")
2672 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2673 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2674 .build());
2675 // Apps that lack location permission have no business calling this method;
2676 // however, because no permission was declared in the public API, denials must
2677 // all be "soft".
2678 switch (locationResult) {
2679 case DENIED_HARD: /* fall through */
2680 case DENIED_SOFT:
2681 return;
2682 }
2683
2684 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685 final long identity = Binder.clearCallingIdentity();
2686 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002687 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002689 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690 }
2691 } finally {
2692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 }
2695
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002696 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002697 @Override
2698 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002699 return isRadioOnWithFeature(callingPackage, null);
2700 }
2701
2702
2703 @Override
2704 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2705 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2706 callingFeatureId);
2707 }
2708
2709 @Deprecated
2710 @Override
2711 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2712 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002713 }
2714
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002715 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002716 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2717 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002719 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002720 return false;
2721 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722
2723 final long identity = Binder.clearCallingIdentity();
2724 try {
2725 return isRadioOnForSubscriber(subId);
2726 } finally {
2727 Binder.restoreCallingIdentity(identity);
2728 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002729 }
2730
2731 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002732 final long identity = Binder.clearCallingIdentity();
2733 try {
2734 final Phone phone = getPhone(subId);
2735 if (phone != null) {
2736 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2737 } else {
2738 return false;
2739 }
2740 } finally {
2741 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002742 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 }
2744
2745 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002746 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002747 }
Wink Saville36469e72014-06-11 15:17:00 -07002748
Wink Savilleb564aae2014-10-23 10:18:09 -07002749 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002750 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002751
2752 final long identity = Binder.clearCallingIdentity();
2753 try {
2754 final Phone phone = getPhone(subId);
2755 if (phone != null) {
2756 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2757 }
2758 } finally {
2759 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002760 }
Wink Saville36469e72014-06-11 15:17:00 -07002761 }
2762
2763 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002764 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002765 }
2766
Wink Savilleb564aae2014-10-23 10:18:09 -07002767 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002768 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769
2770 final long identity = Binder.clearCallingIdentity();
2771 try {
2772 final Phone phone = getPhone(subId);
2773 if (phone == null) {
2774 return false;
2775 }
2776 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2777 toggleRadioOnOffForSubscriber(subId);
2778 }
2779 return true;
2780 } finally {
2781 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002782 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 }
Wink Saville36469e72014-06-11 15:17:00 -07002784
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002785 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002786 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002787 /*
2788 * If any of the Radios are available, it will need to be
2789 * shutdown. So return true if any Radio is available.
2790 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 final long identity = Binder.clearCallingIdentity();
2792 try {
2793 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2794 Phone phone = PhoneFactory.getPhone(i);
2795 if (phone != null && phone.isRadioAvailable()) return true;
2796 }
2797 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2798 return false;
2799 } finally {
2800 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002801 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002802 }
2803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002805 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 enforceModifyPermission();
2807
2808 final long identity = Binder.clearCallingIdentity();
2809 try {
2810 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2811 logv("Shutting down Phone " + i);
2812 shutdownRadioUsingPhoneId(i);
2813 }
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002816 }
2817 }
2818
2819 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002820 Phone phone = PhoneFactory.getPhone(phoneId);
2821 if (phone != null && phone.isRadioAvailable()) {
2822 phone.shutdownRadio();
2823 }
2824 }
2825
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002826 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002827 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828
2829 final long identity = Binder.clearCallingIdentity();
2830 try {
2831 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2832 if (defaultPhone != null) {
2833 defaultPhone.setRadioPower(turnOn);
2834 return true;
2835 } else {
2836 loge("There's no default phone.");
2837 return false;
2838 }
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002841 }
Wink Saville36469e72014-06-11 15:17:00 -07002842 }
2843
Wink Savilleb564aae2014-10-23 10:18:09 -07002844 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002845 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846
2847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 final Phone phone = getPhone(subId);
2850 if (phone != null) {
2851 phone.setRadioPower(turnOn);
2852 return true;
2853 } else {
2854 return false;
2855 }
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 }
2860
Wink Saville36469e72014-06-11 15:17:00 -07002861 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002862 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002863 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002864 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865
2866 final long identity = Binder.clearCallingIdentity();
2867 try {
2868 int subId = mSubscriptionController.getDefaultDataSubId();
2869 final Phone phone = getPhone(subId);
2870 if (phone != null) {
Jack Yud7b8d372022-07-31 00:43:21 -07002871 phone.getDataSettingsManager().setDataEnabled(
2872 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002873 return true;
2874 } else {
2875 return false;
2876 }
2877 } finally {
2878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 }
2881
Wink Saville36469e72014-06-11 15:17:00 -07002882 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002883 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002884 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002885 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002886
2887 final long identity = Binder.clearCallingIdentity();
2888 try {
2889 int subId = mSubscriptionController.getDefaultDataSubId();
2890 final Phone phone = getPhone(subId);
2891 if (phone != null) {
Jack Yud7b8d372022-07-31 00:43:21 -07002892 phone.getDataSettingsManager().setDataEnabled(
2893 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894 return true;
2895 } else {
2896 return false;
2897 }
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901 }
2902
Sanket Padawe356d7632015-06-22 14:03:32 -07002903 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002904 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 final Phone phone = getPhone(subId);
2908 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07002909 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 } else {
2911 return false;
2912 }
2913 } finally {
2914 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002916 }
2917
2918 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002919 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002920 }
2921
pkanwarae03a6b2016-11-06 20:37:09 -08002922 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923 enforceCallPermission();
2924
2925 final long identity = Binder.clearCallingIdentity();
2926 try {
2927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2928 return;
2929 }
2930 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2931 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2932 } finally {
2933 Binder.restoreCallingIdentity(identity);
2934 }
pkanwar32d516d2016-10-14 19:37:38 -07002935 };
2936
Wink Savilleb564aae2014-10-23 10:18:09 -07002937 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002938 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939
2940 final long identity = Binder.clearCallingIdentity();
2941 try {
2942 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2943 return false;
2944 }
2945 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2946 } finally {
2947 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002949 }
2950
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002951 /**
2952 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2953 * tag on getCallState Binder call.
2954 */
2955 @Deprecated
2956 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002957 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002958 if (CompatChanges.isChangeEnabled(
2959 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2960 Binder.getCallingUid())) {
2961 // Do not allow this API to be called on API version 31+, it should only be
2962 // called on old apps using this Binder call directly.
2963 throw new SecurityException("This method can only be used for applications "
2964 + "targeting API version 30 or less.");
2965 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002966 final long identity = Binder.clearCallingIdentity();
2967 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002968 Phone phone = getPhone(getDefaultSubscription());
2969 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2970 PhoneConstantConversions.convertCallState(phone.getState());
2971 } finally {
2972 Binder.restoreCallingIdentity(identity);
2973 }
2974 }
2975
2976 @Override
2977 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2978 if (CompatChanges.isChangeEnabled(
2979 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2980 Binder.getCallingUid())) {
2981 // Check READ_PHONE_STATE for API version 31+
2982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2983 featureId, "getCallStateForSubscription")) {
2984 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2985 + "targeting API level 31+.");
2986 }
2987 }
2988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2992 PhoneConstantConversions.convertCallState(phone.getState());
2993 } finally {
2994 Binder.restoreCallingIdentity(identity);
2995 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002996 }
2997
Sanket Padawe356d7632015-06-22 14:03:32 -07002998 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002999 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003000 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3001 }
3002
3003 @Override
3004 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005 final long identity = Binder.clearCallingIdentity();
3006 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003007 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 if (phone != null) {
Jack Yud7b8d372022-07-31 00:43:21 -07003009 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003010 } else {
3011 return PhoneConstantConversions.convertDataState(
3012 PhoneConstants.DataState.DISCONNECTED);
3013 }
3014 } finally {
3015 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003017 }
3018
Sanket Padawe356d7632015-06-22 14:03:32 -07003019 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003020 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003021 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3022 }
3023
3024 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003025 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 final long identity = Binder.clearCallingIdentity();
3027 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003028 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003030 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003031 } else {
3032 return TelephonyManager.DATA_ACTIVITY_NONE;
3033 }
3034 } finally {
3035 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003036 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003037 }
3038
3039 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003040 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003041 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003042 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003043
3044 LocationAccessPolicy.LocationPermissionResult locationResult =
3045 LocationAccessPolicy.checkLocationPermission(mApp,
3046 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3047 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003048 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003049 .setCallingPid(Binder.getCallingPid())
3050 .setCallingUid(Binder.getCallingUid())
3051 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003052 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003053 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3054 .build());
3055 switch (locationResult) {
3056 case DENIED_HARD:
3057 throw new SecurityException("Not allowed to access cell location");
3058 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003059 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3060 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061 }
3062
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003063 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064 final long identity = Binder.clearCallingIdentity();
3065 try {
3066 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003067 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003068 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
Svetoslav64fad262015-04-14 14:35:21 -07003072 }
3073
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003075 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003076 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3077 // registered cell info, so return a NULL country instead.
3078 final long identity = Binder.clearCallingIdentity();
3079 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003080 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3081 // Get default phone in this case.
3082 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3083 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003084 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003085 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003086 if (phone == null) return "";
3087 ServiceStateTracker sst = phone.getServiceStateTracker();
3088 if (sst == null) return "";
3089 LocaleTracker lt = sst.getLocaleTracker();
3090 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003091 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003095 }
3096
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003097 /**
3098 * This method was removed due to potential issues caused by performing partial
3099 * updates of service state, and lack of a credible use case.
3100 *
3101 * This has the ability to break the telephony implementation by disabling notification of
3102 * changes in device connectivity. DO NOT USE THIS!
3103 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003104 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003105 public void enableLocationUpdates() {
3106 mApp.enforceCallingOrSelfPermission(
3107 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 }
3109
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003110 /**
3111 * This method was removed due to potential issues caused by performing partial
3112 * updates of service state, and lack of a credible use case.
3113 *
3114 * This has the ability to break the telephony implementation by disabling notification of
3115 * changes in device connectivity. DO NOT USE THIS!
3116 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 @Override
3118 public void disableLocationUpdates() {
3119 mApp.enforceCallingOrSelfPermission(
3120 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003121 }
3122
3123 @Override
3124 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003125 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3126 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003127 try {
3128 mApp.getSystemService(AppOpsManager.class)
3129 .checkPackage(Binder.getCallingUid(), callingPackage);
3130 } catch (SecurityException e) {
3131 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3132 throw e;
3133 }
3134
Nathan Haroldf096d982020-11-18 17:18:06 -08003135 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003136 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3137 throw new SecurityException(
3138 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3139 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003140
Jordan Liu1617b712019-07-10 15:06:26 -07003141 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003142 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3143 return null;
3144 }
Svetoslav64fad262015-04-14 14:35:21 -07003145
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003146 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003147
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003148 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003149 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003150
Nathan Haroldf180aac2018-06-01 18:43:55 -07003151 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3152 for (CellInfo ci : info) {
3153 if (ci instanceof CellInfoGsm) {
3154 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3155 } else if (ci instanceof CellInfoWcdma) {
3156 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003159 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003160 }
3161
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003162 private List<CellInfo> getCachedCellInfo() {
3163 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3164 for (Phone phone : PhoneFactory.getPhones()) {
3165 List<CellInfo> info = phone.getAllCellInfo();
3166 if (info != null) cellInfos.addAll(info);
3167 }
3168 return cellInfos;
3169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170
3171 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003172 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003173 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003174 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003175
3176 LocationAccessPolicy.LocationPermissionResult locationResult =
3177 LocationAccessPolicy.checkLocationPermission(mApp,
3178 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3179 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003180 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003181 .setCallingPid(Binder.getCallingPid())
3182 .setCallingUid(Binder.getCallingUid())
3183 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003184 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003185 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3186 .build());
3187 switch (locationResult) {
3188 case DENIED_HARD:
3189 throw new SecurityException("Not allowed to access cell info");
3190 case DENIED_SOFT:
3191 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003192 }
3193
Nathan Haroldf096d982020-11-18 17:18:06 -08003194 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003195 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3196 return getCachedCellInfo();
3197 }
3198
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003199 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003200 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201 final long identity = Binder.clearCallingIdentity();
3202 try {
3203 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3204 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003205 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003206 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 if (info != null) cellInfos.addAll(info);
3208 }
3209 return cellInfos;
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 }
3213 }
3214
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003215 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003216 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3217 String callingFeatureId) {
3218 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3219 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003220 }
3221
3222 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003223 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3224 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003225 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003226 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003227 }
3228
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003229 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3230 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003231 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003232 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003233
3234 LocationAccessPolicy.LocationPermissionResult locationResult =
3235 LocationAccessPolicy.checkLocationPermission(mApp,
3236 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3237 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003238 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003239 .setCallingPid(Binder.getCallingPid())
3240 .setCallingUid(Binder.getCallingUid())
3241 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003242 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3243 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003244 .build());
3245 switch (locationResult) {
3246 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003247 if (TelephonyPermissions
3248 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003249 // Safetynet logging for b/154934934
3250 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3251 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003252 throw new SecurityException("Not allowed to access cell info");
3253 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003254 if (TelephonyPermissions
3255 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003256 // Safetynet logging for b/154934934
3257 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3258 }
Nathan Harold5320c422019-05-09 10:26:08 -07003259 try {
3260 cb.onCellInfo(new ArrayList<CellInfo>());
3261 } catch (RemoteException re) {
3262 // Drop without consequences
3263 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003264 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003265 }
3266
Nathan Harolda939a962019-05-09 10:13:47 -07003267
3268 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003269 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3270
3271 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3272 }
3273
3274 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003276 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003277 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278
3279 final long identity = Binder.clearCallingIdentity();
3280 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003281 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282 } finally {
3283 Binder.restoreCallingIdentity(identity);
3284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003285 }
3286
Shishir Agrawala9f32182016-04-12 12:00:16 -07003287 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003288 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003289 Phone phone = PhoneFactory.getPhone(slotIndex);
3290 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003291 return null;
3292 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003293 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003294 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003295 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003296 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003297 return null;
3298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003299
3300 final long identity = Binder.clearCallingIdentity();
3301 try {
3302 return phone.getImei();
3303 } finally {
3304 Binder.restoreCallingIdentity(identity);
3305 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003306 }
3307
3308 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003309 public String getTypeAllocationCodeForSlot(int slotIndex) {
3310 Phone phone = PhoneFactory.getPhone(slotIndex);
3311 String tac = null;
3312 if (phone != null) {
3313 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003314 try {
3315 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3316 } catch (IndexOutOfBoundsException e) {
3317 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3318 return null;
3319 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003320 }
3321 return tac;
3322 }
3323
3324 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003325 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003326 try {
3327 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3328 } catch (SecurityException se) {
3329 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3330 throw new SecurityException("Package " + callingPackage + " does not belong to "
3331 + Binder.getCallingUid());
3332 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003333 Phone phone = PhoneFactory.getPhone(slotIndex);
3334 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003335 return null;
3336 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003337
Jeff Davidson913390f2018-02-23 17:11:49 -08003338 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003339 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003340 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003341 return null;
3342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343
3344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 return phone.getMeid();
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
Jack Yu2af8d712017-03-15 17:14:14 -07003350 }
3351
3352 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003353 public String getManufacturerCodeForSlot(int slotIndex) {
3354 Phone phone = PhoneFactory.getPhone(slotIndex);
3355 String manufacturerCode = null;
3356 if (phone != null) {
3357 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003358 try {
3359 manufacturerCode =
3360 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3361 } catch (IndexOutOfBoundsException e) {
3362 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3363 return null;
3364 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003365 }
3366 return manufacturerCode;
3367 }
3368
3369 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003370 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3371 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003372 Phone phone = PhoneFactory.getPhone(slotIndex);
3373 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003374 return null;
3375 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003376 int subId = phone.getSubId();
3377 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003378 mApp, subId, callingPackage, callingFeatureId,
3379 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003380 return null;
3381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382
3383 final long identity = Binder.clearCallingIdentity();
3384 try {
3385 return phone.getDeviceSvn();
3386 } finally {
3387 Binder.restoreCallingIdentity(identity);
3388 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003389 }
3390
fionaxu43304da2017-11-27 22:51:16 -08003391 @Override
3392 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393 final long identity = Binder.clearCallingIdentity();
3394 try {
3395 final Phone phone = getPhone(subId);
3396 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
fionaxu43304da2017-11-27 22:51:16 -08003400 }
3401
3402 @Override
3403 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404 final long identity = Binder.clearCallingIdentity();
3405 try {
3406 final Phone phone = getPhone(subId);
3407 return phone == null ? null : phone.getCarrierName();
3408 } finally {
3409 Binder.restoreCallingIdentity(identity);
3410 }
fionaxu43304da2017-11-27 22:51:16 -08003411 }
3412
calvinpanffe225e2018-11-01 19:43:06 +08003413 @Override
chen xu0026ca62019-03-06 15:28:50 -08003414 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 final Phone phone = getPhone(subId);
3418 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003419 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003420 } finally {
3421 Binder.restoreCallingIdentity(identity);
3422 }
3423 }
3424
3425 @Override
chen xu0026ca62019-03-06 15:28:50 -08003426 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003430 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003431 } finally {
3432 Binder.restoreCallingIdentity(identity);
3433 }
3434 }
3435
chen xu651eec72018-11-11 19:03:44 -08003436 @Override
chen xu864e11c2018-12-06 22:10:03 -08003437 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3438 if (!isSubscriptionMccMnc) {
3439 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3440 }
chen xu651eec72018-11-11 19:03:44 -08003441 final Phone phone = PhoneFactory.getPhone(slotIndex);
3442 if (phone == null) {
3443 return TelephonyManager.UNKNOWN_CARRIER_ID;
3444 }
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
3451 }
3452
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003453 //
3454 // Internal helper methods.
3455 //
3456
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003457 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003458 * Make sure the caller is the calling package itself
3459 *
3460 * @throws SecurityException if the caller is not the calling package
3461 */
3462 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3463 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003464 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3465 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003466 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003467 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003468 } catch (PackageManager.NameNotFoundException e) {
3469 // packageUid is -1
3470 }
3471 if (packageUid != callingUid) {
3472 throw new SecurityException(message + ": Package " + callingPackage
3473 + " does not belong to " + callingUid);
3474 }
3475 }
3476
3477 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003478 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3479 *
3480 * @throws SecurityException if the caller does not have the required permission
3481 */
3482 private void enforceModifyPermission() {
3483 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3484 }
3485
Shuo Qian3b6ee772019-11-13 17:43:31 -08003486 private void enforceActiveEmergencySessionPermission() {
3487 mApp.enforceCallingOrSelfPermission(
3488 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3489 }
3490
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003491 /**
3492 * Make sure the caller has the CALL_PHONE permission.
3493 *
3494 * @throws SecurityException if the caller does not have the required permission
3495 */
3496 private void enforceCallPermission() {
3497 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3498 }
3499
paulhu5a773602019-08-23 19:17:33 +08003500 private void enforceSettingsPermission() {
3501 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003502 }
3503
Michele Berionne5e411512020-11-13 02:36:59 +00003504 private void enforceRebootPermission() {
3505 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3506 }
3507
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508 private String createTelUrl(String number) {
3509 if (TextUtils.isEmpty(number)) {
3510 return null;
3511 }
3512
Jake Hambye994d462014-02-03 13:10:13 -08003513 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003514 }
3515
Ihab Awadf9e92732013-12-05 18:02:52 -08003516 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003517 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3518 }
3519
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003520 private static void logv(String msg) {
3521 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3522 }
3523
Ihab Awadf9e92732013-12-05 18:02:52 -08003524 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003525 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3526 }
3527
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003528 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003529 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003530 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003531 }
3532
Sanket Padawe356d7632015-06-22 14:03:32 -07003533 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003534 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 final Phone phone = PhoneFactory.getPhone(slotIndex);
3538 if (phone == null) {
3539 return PhoneConstants.PHONE_TYPE_NONE;
3540 } else {
3541 return phone.getPhoneType();
3542 }
3543 } finally {
3544 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003546 }
3547
3548 /**
3549 * Returns the CDMA ERI icon index to display
3550 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003551 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003552 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3553 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3554 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003555 }
3556
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003558 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3559 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003561 mApp, subId, callingPackage, callingFeatureId,
3562 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003563 return -1;
3564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565
3566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 final Phone phone = getPhone(subId);
3569 if (phone != null) {
3570 return phone.getCdmaEriIconIndex();
3571 } else {
3572 return -1;
3573 }
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003577 }
3578
3579 /**
3580 * Returns the CDMA ERI icon mode,
3581 * 0 - ON
3582 * 1 - FLASHING
3583 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003584 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003585 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3586 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3587 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003588 }
3589
Sanket Padawe356d7632015-06-22 14:03:32 -07003590 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003591 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3592 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003593 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003594 mApp, subId, callingPackage, callingFeatureId,
3595 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003596 return -1;
3597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598
3599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 final Phone phone = getPhone(subId);
3602 if (phone != null) {
3603 return phone.getCdmaEriIconMode();
3604 } else {
3605 return -1;
3606 }
3607 } finally {
3608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003610 }
3611
3612 /**
3613 * Returns the CDMA ERI text,
3614 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003615 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003616 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3617 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3618 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003619 }
3620
Sanket Padawe356d7632015-06-22 14:03:32 -07003621 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003622 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3623 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003624 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003625 mApp, subId, callingPackage, callingFeatureId,
3626 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003627 return null;
3628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629
3630 final long identity = Binder.clearCallingIdentity();
3631 try {
3632 final Phone phone = getPhone(subId);
3633 if (phone != null) {
3634 return phone.getCdmaEriText();
3635 } else {
3636 return null;
3637 }
3638 } finally {
3639 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003641 }
3642
3643 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003644 * Returns the CDMA MDN.
3645 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003646 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003647 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3649 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650
3651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003654 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655 return phone.getLine1Number();
3656 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003657 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003658 return null;
3659 }
3660 } finally {
3661 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003662 }
3663 }
3664
3665 /**
3666 * Returns the CDMA MIN.
3667 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003668 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003669 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3671 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672
3673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 final Phone phone = getPhone(subId);
3676 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3677 return phone.getCdmaMin();
3678 } else {
3679 return null;
3680 }
3681 } finally {
3682 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003683 }
3684 }
3685
Hall Liud892bec2018-11-30 14:51:45 -08003686 @Override
3687 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3688 INumberVerificationCallback callback, String callingPackage) {
3689 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3690 != PERMISSION_GRANTED) {
3691 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3692 }
3693 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3694
3695 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3696 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003697 throw new SecurityException("Calling package must be configured in the device config: "
3698 + "calling package: " + callingPackage
3699 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003700 }
3701
3702 if (range == null) {
3703 throw new NullPointerException("Range must be non-null");
3704 }
3705
3706 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003707 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003708
3709 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3710 }
3711
Junda Liuca05d5d2014-08-14 22:36:34 -07003712 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003713 * Returns true if CDMA provisioning needs to run.
3714 */
3715 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716 final long identity = Binder.clearCallingIdentity();
3717 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003718 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719 } finally {
3720 Binder.restoreCallingIdentity(identity);
3721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003722 }
3723
3724 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003725 * Sets the voice mail number of a given subId.
3726 */
3727 @Override
3728 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003729 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3730 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003731
3732 final long identity = Binder.clearCallingIdentity();
3733 try {
3734 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3735 new Pair<String, String>(alphaTag, number), new Integer(subId));
3736 return success;
3737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003740 }
3741
Ta-wei Yen87c49842016-05-13 21:19:52 -07003742 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003743 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3744 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003745 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3746 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003747 if (!TextUtils.equals(callingPackage, systemDialer)) {
3748 throw new SecurityException("caller must be system dialer");
3749 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750
3751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3754 if (phoneAccountHandle == null) {
3755 return null;
3756 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003757 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003758 } finally {
3759 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003760 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003761 }
3762
3763 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003764 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3765 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003766 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003768 mApp, subId, callingPackage, callingFeatureId,
3769 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003770 return null;
3771 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003773 final long identity = Binder.clearCallingIdentity();
3774 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003775 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003776 } finally {
3777 Binder.restoreCallingIdentity(identity);
3778 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003779 }
3780
3781 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003782 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3783 VisualVoicemailSmsFilterSettings settings) {
3784 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785
3786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003789 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790 } finally {
3791 Binder.restoreCallingIdentity(identity);
3792 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003793 }
3794
3795 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003796 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3797 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798
3799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003802 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003803 } finally {
3804 Binder.restoreCallingIdentity(identity);
3805 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003806 }
3807
3808 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003809 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3810 String callingPackage, int subId) {
3811 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812
3813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003816 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817 } finally {
3818 Binder.restoreCallingIdentity(identity);
3819 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003820 }
3821
3822 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003823 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003824 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825
3826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003829 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830 } finally {
3831 Binder.restoreCallingIdentity(identity);
3832 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003833 }
3834
3835 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003836 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3837 String callingAttributionTag, int subId, String number, int port, String text,
3838 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003839 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003840 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003841 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003842 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003843 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3844 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003845 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003846
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003847 /**
fionaxu0152e512016-11-14 13:36:14 -08003848 * Sets the voice activation state of a given subId.
3849 */
3850 @Override
3851 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3853 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003854
3855 final long identity = Binder.clearCallingIdentity();
3856 try {
3857 final Phone phone = getPhone(subId);
3858 if (phone != null) {
3859 phone.setVoiceActivationState(activationState);
3860 } else {
3861 loge("setVoiceActivationState fails with invalid subId: " + subId);
3862 }
3863 } finally {
3864 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003865 }
3866 }
3867
3868 /**
3869 * Sets the data activation state of a given subId.
3870 */
3871 @Override
3872 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3874 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003875
3876 final long identity = Binder.clearCallingIdentity();
3877 try {
3878 final Phone phone = getPhone(subId);
3879 if (phone != null) {
3880 phone.setDataActivationState(activationState);
3881 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003882 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003883 }
3884 } finally {
3885 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003886 }
3887 }
3888
3889 /**
3890 * Returns the voice activation state of a given subId.
3891 */
3892 @Override
3893 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895
fionaxu0152e512016-11-14 13:36:14 -08003896 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 if (phone != null) {
3900 return phone.getVoiceActivationState();
3901 } else {
3902 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3903 }
3904 } finally {
3905 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003906 }
3907 }
3908
3909 /**
3910 * Returns the data activation state of a given subId.
3911 */
3912 @Override
3913 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003914 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003915
fionaxu0152e512016-11-14 13:36:14 -08003916 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917 final long identity = Binder.clearCallingIdentity();
3918 try {
3919 if (phone != null) {
3920 return phone.getDataActivationState();
3921 } else {
3922 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3923 }
3924 } finally {
3925 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003926 }
3927 }
3928
3929 /**
Wink Saville36469e72014-06-11 15:17:00 -07003930 * Returns the unread count of voicemails for a subId
3931 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003932 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003933 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3934 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003936 mApp, subId, callingPackage, callingFeatureId,
3937 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003938 return 0;
3939 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 final Phone phone = getPhone(subId);
3943 if (phone != null) {
3944 return phone.getVoiceMessageCount();
3945 } else {
3946 return 0;
3947 }
3948 } finally {
3949 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003951 }
3952
3953 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003954 * returns true, if the device is in a state where both voice and data
3955 * are supported simultaneously. This can change based on location or network condition.
3956 */
3957 @Override
3958 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003959 final long identity = Binder.clearCallingIdentity();
3960 try {
3961 final Phone phone = getPhone(subId);
3962 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3963 } finally {
3964 Binder.restoreCallingIdentity(identity);
3965 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003966 }
3967
3968 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003969 * Send the dialer code if called from the current default dialer or the caller has
3970 * carrier privilege.
3971 * @param inputCode The dialer code to send
3972 */
3973 @Override
3974 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003975 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003976 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003977 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3978 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003979 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003980 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003981 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003983
3984 final long identity = Binder.clearCallingIdentity();
3985 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003986 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987 } finally {
3988 Binder.restoreCallingIdentity(identity);
3989 }
fionaxu235cc5e2017-03-06 22:25:57 -08003990 }
3991
Pengquan Menga1bb6272018-09-06 09:59:22 -07003992 @Override
3993 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003994 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003995 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003996 mApp, subId, "getNetworkSelectionMode");
3997 final long identity = Binder.clearCallingIdentity();
3998 try {
3999 if (!isActiveSubscription(subId)) {
4000 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4001 }
4002 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4003 } finally {
4004 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004005 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004006 }
4007
Brad Ebinger35c841c2018-10-01 10:40:55 -07004008 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004009 public boolean isInEmergencySmsMode() {
4010 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4011 final long identity = Binder.clearCallingIdentity();
4012 try {
4013 for (Phone phone : PhoneFactory.getPhones()) {
4014 if (phone.isInEmergencySmsMode()) {
4015 return true;
4016 }
4017 }
4018 } finally {
4019 Binder.restoreCallingIdentity(identity);
4020 }
4021 return false;
4022 }
4023
shilu366312e2019-12-17 09:28:10 -08004024 /**
4025 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4026 * @param subId The subscription to use to check the configuration.
4027 * @param c The callback that will be used to send the result.
4028 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004029 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004030 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4031 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004032 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004033 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004034
4035 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4036 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4037 "IMS not available on device.");
4038 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 final long token = Binder.clearCallingIdentity();
4040 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004041 int slotId = getSlotIndexOrException(subId);
4042 verifyImsMmTelConfiguredOrThrow(slotId);
4043 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004044 } catch (ImsException e) {
4045 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004046 } finally {
4047 Binder.restoreCallingIdentity(token);
4048 }
4049 }
4050
shilu366312e2019-12-17 09:28:10 -08004051 /**
4052 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4053 * @param subId The subscription to use to check the configuration.
4054 * @param c The callback that will be used to send the result.
4055 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004056 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004057 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004058 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004059 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004060 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4061 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4062 }
Meng Wangafbc5852019-09-19 17:37:13 -07004063 final long token = Binder.clearCallingIdentity();
4064 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004065 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4066 .removeRegistrationCallbackForSubscription(c, subId);
4067 } catch (ImsException e) {
4068 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4069 + "is inactive, ignoring unregister.");
4070 // If the subscription is no longer active, just return, since the callback
4071 // will already have been removed internally.
4072 } finally {
4073 Binder.restoreCallingIdentity(token);
4074 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 }
4076
Brad Ebingera34a6c22019-10-22 17:36:18 -07004077 /**
4078 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4079 */
4080 @Override
4081 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4082 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4083 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4084 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4085 "IMS not available on device.");
4086 }
4087 final long token = Binder.clearCallingIdentity();
4088 try {
4089 Phone phone = getPhone(subId);
4090 if (phone == null) {
4091 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4092 + subId + "'");
4093 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4094 }
4095 phone.getImsRegistrationState(regState -> {
4096 try {
4097 consumer.accept((regState == null)
4098 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4099 } catch (RemoteException e) {
4100 // Ignore if the remote process is no longer available to call back.
4101 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4102 }
4103 });
4104 } finally {
4105 Binder.restoreCallingIdentity(token);
4106 }
4107 }
4108
4109 /**
4110 * Get the transport type for the IMS service registration state.
4111 */
4112 @Override
4113 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004114 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004115 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004116 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4117 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4118 "IMS not available on device.");
4119 }
4120 final long token = Binder.clearCallingIdentity();
4121 try {
4122 Phone phone = getPhone(subId);
4123 if (phone == null) {
4124 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4125 + subId + "'");
4126 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4127 }
4128 phone.getImsRegistrationTech(regTech -> {
4129 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4130 int regTechConverted = (regTech == null)
4131 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4132 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4133 regTechConverted);
4134 try {
4135 consumer.accept(regTechConverted);
4136 } catch (RemoteException e) {
4137 // Ignore if the remote process is no longer available to call back.
4138 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4139 }
4140 });
4141 } finally {
4142 Binder.restoreCallingIdentity(token);
4143 }
4144 }
4145
shilu366312e2019-12-17 09:28:10 -08004146 /**
4147 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4148 * @param subId The subscription to use to check the configuration.
4149 * @param c The callback that will be used to send the result.
4150 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004152 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4153 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004154 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004155 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004156 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4157 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4158 "IMS not available on device.");
4159 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 final long token = Binder.clearCallingIdentity();
4161 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004162 int slotId = getSlotIndexOrException(subId);
4163 verifyImsMmTelConfiguredOrThrow(slotId);
4164 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004165 } catch (ImsException e) {
4166 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004167 } finally {
4168 Binder.restoreCallingIdentity(token);
4169 }
4170 }
4171
shilu366312e2019-12-17 09:28:10 -08004172 /**
4173 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4174 * @param subId The subscription to use to check the configuration.
4175 * @param c The callback that will be used to send the result.
4176 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004178 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004179 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004180 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004181 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4182 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4183 }
Meng Wangafbc5852019-09-19 17:37:13 -07004184
4185 final long token = Binder.clearCallingIdentity();
4186 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004187 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004188 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004189 } catch (ImsException e) {
4190 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4191 + "is inactive, ignoring unregister.");
4192 // If the subscription is no longer active, just return, since the callback
4193 // will already have been removed internally.
4194 } finally {
4195 Binder.restoreCallingIdentity(token);
4196 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 }
4198
4199 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004200 public boolean isCapable(int subId, int capability, int regTech) {
4201 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004202 final long token = Binder.clearCallingIdentity();
4203 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004204 int slotId = getSlotIndexOrException(subId);
4205 verifyImsMmTelConfiguredOrThrow(slotId);
4206 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4207 } catch (com.android.ims.ImsException e) {
4208 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4209 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004210 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004211 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4212 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 } finally {
4214 Binder.restoreCallingIdentity(token);
4215 }
4216 }
4217
4218 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004219 public boolean isAvailable(int subId, int capability, int regTech) {
4220 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 final long token = Binder.clearCallingIdentity();
4222 try {
4223 Phone phone = getPhone(subId);
4224 if (phone == null) return false;
4225 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004226 } catch (com.android.ims.ImsException e) {
4227 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4228 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004229 } finally {
4230 Binder.restoreCallingIdentity(token);
4231 }
4232 }
4233
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004234 /**
4235 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4236 * subscription.
4237 * @param subId The subscription to use to check the configuration.
4238 * @param callback The callback that will be used to send the result.
4239 * @param capability The MmTelFeature capability that will be used to send the result.
4240 * @param transportType The transport type of the MmTelFeature capability.
4241 */
4242 @Override
4243 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4244 int transportType) {
4245 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004246 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4247 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4248 "IMS not available on device.");
4249 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004250 final long token = Binder.clearCallingIdentity();
4251 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004252 int slotId = getSlotIndex(subId);
4253 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4254 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4255 + subId + "'");
4256 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4257 }
4258 verifyImsMmTelConfiguredOrThrow(slotId);
4259 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4260 transportType, aBoolean -> {
4261 try {
4262 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4263 } catch (RemoteException e) {
4264 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4265 + "running. Ignore");
4266 }
4267 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004268 } catch (ImsException e) {
4269 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004270 } finally {
4271 Binder.restoreCallingIdentity(token);
4272 }
4273 }
4274
shilu366312e2019-12-17 09:28:10 -08004275 /**
4276 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4277 * @param subId The subscription to use to check the configuration.
4278 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004279 @Override
4280 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004281 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004282 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004283
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 final long token = Binder.clearCallingIdentity();
4285 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004286 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004287 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004288 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004289 } catch (ImsException e) {
4290 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 } finally {
4292 Binder.restoreCallingIdentity(token);
4293 }
4294 }
4295
4296 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004297 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004299 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004300 final long identity = Binder.clearCallingIdentity();
4301 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004302 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004303 // This setting doesn't require an active ImsService connection, so do not verify. The
4304 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004305 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004306 } catch (ImsException e) {
4307 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004308 } finally {
4309 Binder.restoreCallingIdentity(identity);
4310 }
4311 }
4312
shilu366312e2019-12-17 09:28:10 -08004313 /**
4314 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4315 * @param subId The subscription to use to check the configuration.
4316 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004317 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004318 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004319 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004320 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004321 final long identity = Binder.clearCallingIdentity();
4322 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004323 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004324 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004325 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004326 } catch (ImsException e) {
4327 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 } finally {
4329 Binder.restoreCallingIdentity(identity);
4330 }
4331 }
4332
4333 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004334 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004336 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004337 final long identity = Binder.clearCallingIdentity();
4338 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004339 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004340 // This setting doesn't require an active ImsService connection, so do not verify. The
4341 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004342 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004343 } catch (ImsException e) {
4344 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004345 } finally {
4346 Binder.restoreCallingIdentity(identity);
4347 }
4348 }
4349
shilu366312e2019-12-17 09:28:10 -08004350 /**
4351 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4352 * @param subId The subscription to use to check the configuration.
4353 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 @Override
4355 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004356 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004357 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004358 final long identity = Binder.clearCallingIdentity();
4359 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004360 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004361 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004362 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004363 } catch (ImsException e) {
4364 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 } finally {
4366 Binder.restoreCallingIdentity(identity);
4367 }
4368 }
4369
4370 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004371 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004373 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 final long identity = Binder.clearCallingIdentity();
4375 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004376 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004377 // This setting doesn't require an active ImsService connection, so do not verify. The
4378 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004379 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004380 } catch (ImsException e) {
4381 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
4385 }
4386
shilu366312e2019-12-17 09:28:10 -08004387 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004388 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4389 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4390 * @param subId The subscription to use to check the configuration.
4391 */
4392 @Override
4393 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004394 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004395 mApp, subId, "isCrossSimCallingEnabledByUser");
4396 final long identity = Binder.clearCallingIdentity();
4397 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004398 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004399 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004400 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004401 } catch (ImsException e) {
4402 throw new ServiceSpecificException(e.getCode());
4403 } finally {
4404 Binder.restoreCallingIdentity(identity);
4405 }
4406 }
4407
4408 /**
4409 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4410 * Requires MODIFY_PHONE_STATE permission.
4411 * @param subId The subscription to use to check the configuration.
4412 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4413 * false otherwise
4414 */
4415 @Override
4416 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4418 "setCrossSimCallingEnabled");
4419 final long identity = Binder.clearCallingIdentity();
4420 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004421 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004422 // This setting doesn't require an active ImsService connection, so do not verify. The
4423 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004424 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004425 } catch (ImsException e) {
4426 throw new ServiceSpecificException(e.getCode());
4427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
4430 }
4431
4432 /**
shilu366312e2019-12-17 09:28:10 -08004433 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4434 * @param subId The subscription to use to check the configuration.
4435 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004436 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004437
Brad Ebinger35c841c2018-10-01 10:40:55 -07004438 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004439 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004440 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004441 final long identity = Binder.clearCallingIdentity();
4442 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004443 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004444 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004445 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004446 } catch (ImsException e) {
4447 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
4451 }
4452
4453 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004454 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004456 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004457 final long identity = Binder.clearCallingIdentity();
4458 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004459 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004460 // This setting doesn't require an active ImsService connection, so do not verify. The
4461 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004462 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004463 } catch (ImsException e) {
4464 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004465 } finally {
4466 Binder.restoreCallingIdentity(identity);
4467 }
4468 }
4469
4470 @Override
4471 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4473 "setVoWiFiNonPersistent");
4474 final long identity = Binder.clearCallingIdentity();
4475 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004476 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004477 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004478 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004479 } catch (ImsException e) {
4480 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
4484 }
4485
shilu366312e2019-12-17 09:28:10 -08004486 /**
4487 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4488 * @param subId The subscription to use to check the configuration.
4489 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004490 @Override
4491 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004492 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004493 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004494 final long identity = Binder.clearCallingIdentity();
4495 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004496 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004497 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004498 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004499 } catch (ImsException e) {
4500 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
4504 }
4505
4506 @Override
4507 public void setVoWiFiModeSetting(int subId, int mode) {
4508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4509 "setVoWiFiModeSetting");
4510 final long identity = Binder.clearCallingIdentity();
4511 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004512 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004513 // This setting doesn't require an active ImsService connection, so do not verify. The
4514 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004515 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004516 } catch (ImsException e) {
4517 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
4521 }
4522
4523 @Override
4524 public int getVoWiFiRoamingModeSetting(int subId) {
4525 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4526 final long identity = Binder.clearCallingIdentity();
4527 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004528 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004529 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004530 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004531 } catch (ImsException e) {
4532 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004533 } finally {
4534 Binder.restoreCallingIdentity(identity);
4535 }
4536 }
4537
4538 @Override
4539 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4541 "setVoWiFiRoamingModeSetting");
4542 final long identity = Binder.clearCallingIdentity();
4543 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004544 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004545 // This setting doesn't require an active ImsService connection, so do not verify. The
4546 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004547 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004548 } catch (ImsException e) {
4549 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
4553 }
4554
4555 @Override
4556 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4558 "setRttCapabilityEnabled");
4559 final long identity = Binder.clearCallingIdentity();
4560 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004561 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004562 // This setting doesn't require an active ImsService connection, so do not verify. The
4563 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004564 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004565 } catch (ImsException e) {
4566 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004567 } finally {
4568 Binder.restoreCallingIdentity(identity);
4569 }
4570 }
4571
shilu366312e2019-12-17 09:28:10 -08004572 /**
4573 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4574 * @param subId The subscription to use to check the configuration.
4575 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004576 @Override
4577 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004578 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004579 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004580 final long identity = Binder.clearCallingIdentity();
4581 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004582 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004583 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004584 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004585 } catch (ImsException e) {
4586 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004587 } finally {
4588 Binder.restoreCallingIdentity(identity);
4589 }
4590 }
4591
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004592 @Override
4593 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4594 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004595
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004596 final long identity = Binder.clearCallingIdentity();
4597 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004598 if (!isImsAvailableOnDevice()) {
4599 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4600 "IMS not available on device.");
4601 }
4602 int slotId = getSlotIndexOrException(subId);
4603 verifyImsMmTelConfiguredOrThrow(slotId);
4604 ImsManager.getInstance(mApp, slotId)
4605 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004606 } catch (ImsException e) {
4607 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004608 } finally {
4609 Binder.restoreCallingIdentity(identity);
4610 }
4611 }
4612
4613 @Override
4614 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4615 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004616
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004617 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004618 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4619 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4620 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004621 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004622 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004623 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004624 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004625 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4626 + "is inactive, ignoring unregister.");
4627 // If the subscription is no longer active, just return, since the callback will already
4628 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004629 } finally {
4630 Binder.restoreCallingIdentity(identity);
4631 }
4632 }
4633
joonhunshincffb7fc2021-11-28 07:32:01 +00004634 @Override
4635 public void registerFeatureProvisioningChangedCallback(int subId,
4636 IFeatureProvisioningCallback callback) {
4637 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4638 mApp, subId, "registerFeatureProvisioningChangedCallback");
4639
4640 final long identity = Binder.clearCallingIdentity();
4641 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4642 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4643 }
4644
joonhunshin91bc1952022-04-29 08:47:15 +00004645 try {
4646 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4647 if (controller == null) {
4648 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4649 "Device does not support IMS");
4650 }
4651 controller.addFeatureProvisioningChangedCallback(subId, callback);
4652 } finally {
4653 Binder.restoreCallingIdentity(identity);
4654 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004655 }
4656
4657 @Override
4658 public void unregisterFeatureProvisioningChangedCallback(int subId,
4659 IFeatureProvisioningCallback callback) {
4660 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4661 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4662
4663 final long identity = Binder.clearCallingIdentity();
4664 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4665 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4666 }
4667
joonhunshin91bc1952022-04-29 08:47:15 +00004668 try {
4669 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4670 if (controller == null) {
4671 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4672 return;
4673 }
4674 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4675 } finally {
4676 Binder.restoreCallingIdentity(identity);
4677 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004678 }
allenwtsu99c623b2020-01-03 18:24:23 +08004679
4680 private void checkModifyPhoneStatePermission(int subId, String message) {
4681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4682 message);
4683 }
4684
allenwtsu99c623b2020-01-03 18:24:23 +08004685 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004686 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004687 boolean isProvisioned) {
4688 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4689
4690 final long identity = Binder.clearCallingIdentity();
4691 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004692 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4693 if (controller == null) {
4694 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4695 return;
4696 }
4697 controller.setRcsProvisioningStatusForCapability(
4698 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004699 } finally {
4700 Binder.restoreCallingIdentity(identity);
4701 }
allenwtsu99c623b2020-01-03 18:24:23 +08004702 }
4703
4704
4705 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004706 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4707 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4708 mApp, subId, "getRcsProvisioningStatusForCapability");
4709
allenwtsu99c623b2020-01-03 18:24:23 +08004710 final long identity = Binder.clearCallingIdentity();
4711 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004712 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4713 if (controller == null) {
4714 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4715
4716 // device does not support IMS, this method will return true always.
4717 return true;
4718 }
4719 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004720 } finally {
4721 Binder.restoreCallingIdentity(identity);
4722 }
4723 }
4724
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004725 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004726 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4727 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004728 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004729
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004730 final long identity = Binder.clearCallingIdentity();
4731 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004732 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4733 if (controller == null) {
4734 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4735 return;
4736 }
4737 controller.setImsProvisioningStatusForCapability(
4738 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004739 } finally {
4740 Binder.restoreCallingIdentity(identity);
4741 }
4742 }
4743
4744 @Override
4745 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004746 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4747 mApp, subId, "getProvisioningStatusForCapability");
4748
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004749 final long identity = Binder.clearCallingIdentity();
4750 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004751 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4752 if (controller == null) {
4753 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004754
joonhunshin91bc1952022-04-29 08:47:15 +00004755 // device does not support IMS, this method will return true always.
4756 return true;
4757 }
4758 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004759 } finally {
4760 Binder.restoreCallingIdentity(identity);
4761 }
4762 }
4763
4764 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004765 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4766 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4767 mApp, subId, "isProvisioningRequiredForCapability");
4768
4769 final long identity = Binder.clearCallingIdentity();
4770 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004771 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4772 if (controller == null) {
4773 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4774
4775 // device does not support IMS, this method will return false
4776 return false;
4777 }
4778 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004779 } finally {
4780 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004781 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004782 }
4783
4784 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004785 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4786 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4787 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004788
joonhunshincffb7fc2021-11-28 07:32:01 +00004789 final long identity = Binder.clearCallingIdentity();
4790 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004791 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4792 if (controller == null) {
4793 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4794
4795 // device does not support IMS, this method will return false
4796 return false;
4797 }
4798 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004799 } finally {
4800 Binder.restoreCallingIdentity(identity);
4801 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004802 }
4803
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004804 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004805 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004806 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4807 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4808 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004809 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4810 mApp, subId, "getImsProvisioningInt");
4811
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004812 final long identity = Binder.clearCallingIdentity();
4813 try {
4814 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004815 int slotId = getSlotIndex(subId);
4816 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4817 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4818 + subId + "' for key:" + key);
4819 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4820 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004821
joonhunshin91bc1952022-04-29 08:47:15 +00004822 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4823 if (controller == null) {
4824 loge("getImsProvisioningInt: Device does not support IMS");
4825
4826 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4827 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4828 }
4829 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004830 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4831 return retVal;
4832 }
4833
calvinpanb5a34062021-02-08 19:59:36 +08004834 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004835 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004836 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4837 + subId + "' for key:" + key);
4838 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004839 } finally {
4840 Binder.restoreCallingIdentity(identity);
4841 }
4842 }
4843
4844 @Override
4845 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004846 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4847 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4848 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004849 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4850 mApp, subId, "getImsProvisioningString");
4851
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004852 final long identity = Binder.clearCallingIdentity();
4853 try {
4854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004855 int slotId = getSlotIndex(subId);
4856 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4857 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4858 + subId + "' for key:" + key);
4859 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4860 }
calvinpanb5a34062021-02-08 19:59:36 +08004861 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004862 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004863 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4864 + subId + "' for key:" + key);
4865 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004866 } finally {
4867 Binder.restoreCallingIdentity(identity);
4868 }
4869 }
4870
4871 @Override
4872 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4874 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4875 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4877 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004878
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004879 final long identity = Binder.clearCallingIdentity();
4880 try {
4881 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004882 int slotId = getSlotIndex(subId);
4883 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4884 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4885 + subId + "' for key:" + key);
4886 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4887 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004888
joonhunshin91bc1952022-04-29 08:47:15 +00004889 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4890 if (controller == null) {
4891 loge("setImsProvisioningInt: Device does not support IMS");
4892
4893 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
4894 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4895 }
4896 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00004897 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4898 return retVal;
4899 }
4900
calvinpanb5a34062021-02-08 19:59:36 +08004901 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4902 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004903 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004904 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004905 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004906 } finally {
4907 Binder.restoreCallingIdentity(identity);
4908 }
4909 }
4910
4911 @Override
4912 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004913 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4914 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4915 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4917 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004918 final long identity = Binder.clearCallingIdentity();
4919 try {
4920 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004921 int slotId = getSlotIndex(subId);
4922 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4923 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4924 + subId + "' for key:" + key);
4925 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4926 }
calvinpanb5a34062021-02-08 19:59:36 +08004927 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4928 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004929 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004930 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004931 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
4935 }
4936
Brad Ebinger919631e2021-06-02 17:46:35 -07004937 /**
4938 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4939 * for the given slot ID or no ImsResolver instance has been created.
4940 * @param slotId The slot ID that the IMS service is created for.
4941 * @throws ImsException If there is no ImsService configured for this slot.
4942 */
4943 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4944 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4945 ImsFeature.FEATURE_MMTEL)) {
4946 throw new ImsException("This subscription does not support MMTEL over IMS",
4947 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4948 }
4949 }
4950
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004951 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004952 int slotId = SubscriptionManager.getSlotIndex(subId);
4953 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004954 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4955 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004956 }
4957 return slotId;
4958 }
4959
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004960 private int getSlotIndex(int subId) {
4961 int slotId = SubscriptionManager.getSlotIndex(subId);
4962 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4963 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4964 }
4965 return slotId;
4966 }
4967
Wink Saville36469e72014-06-11 15:17:00 -07004968 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004969 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004970 */
4971 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004972 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4973 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004974 try {
4975 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4976 } catch (SecurityException se) {
4977 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4978 throw new SecurityException("Package " + callingPackage + " does not belong to "
4979 + Binder.getCallingUid());
4980 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004981 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004982 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004983 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004984 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004985 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004986 mApp, subId, callingPackage, callingFeatureId,
4987 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004988 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4989 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 final long identity = Binder.clearCallingIdentity();
4992 try {
4993 final Phone phone = getPhone(subId);
4994 if (phone != null) {
4995 return phone.getServiceState().getDataNetworkType();
4996 } else {
4997 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4998 }
4999 } finally {
5000 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005002 }
5003
5004 /**
5005 * Returns the data network type
5006 */
5007 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005008 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005009 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5010 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005011 }
5012
5013 /**
5014 * Returns the data network type for a subId
5015 */
5016 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005017 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5018 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005019 String functionName = "getDataNetworkTypeForSubscriber";
5020 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5021 mApp, functionName)) {
5022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5023 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5024 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5025 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005026 }
5027
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 final long identity = Binder.clearCallingIdentity();
5029 try {
5030 final Phone phone = getPhone(subId);
5031 if (phone != null) {
5032 return phone.getServiceState().getDataNetworkType();
5033 } else {
5034 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5035 }
5036 } finally {
5037 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005038 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005039 }
5040
5041 /**
Wink Saville36469e72014-06-11 15:17:00 -07005042 * Returns the Voice network type for a subId
5043 */
5044 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005045 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5046 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005047 String functionName = "getVoiceNetworkTypeForSubscriber";
5048 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5049 mApp, functionName)) {
5050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5051 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5052 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5053 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005054 }
5055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005056 final long identity = Binder.clearCallingIdentity();
5057 try {
5058 final Phone phone = getPhone(subId);
5059 if (phone != null) {
5060 return phone.getServiceState().getVoiceNetworkType();
5061 } else {
5062 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5063 }
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005067 }
5068
5069 /**
5070 * @return true if a ICC card is present
5071 */
5072 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005073 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005074 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5075 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005076 }
5077
5078 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005079 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005080 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005081 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005082 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083 final long identity = Binder.clearCallingIdentity();
5084 try {
5085 final Phone phone = PhoneFactory.getPhone(slotIndex);
5086 if (phone != null) {
5087 return phone.getIccCard().hasIccCard();
5088 } else {
5089 return false;
5090 }
5091 } finally {
5092 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005094 }
5095
5096 /**
5097 * Return if the current radio is LTE on CDMA. This
5098 * is a tri-state return value as for a period of time
5099 * the mode may be unknown.
5100 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005101 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005102 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005103 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005104 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005105 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005106 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5107 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5108 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005109 }
5110
Sanket Padawe356d7632015-06-22 14:03:32 -07005111 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005112 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5113 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005114 try {
5115 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5116 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005117 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5118 }
5119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005120 final long identity = Binder.clearCallingIdentity();
5121 try {
5122 final Phone phone = getPhone(subId);
5123 if (phone == null) {
5124 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5125 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005126 return TelephonyProperties.lte_on_cdma_device()
5127 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128 }
5129 } finally {
5130 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005131 }
Wink Saville36469e72014-06-11 15:17:00 -07005132 }
5133
Wink Saville36469e72014-06-11 15:17:00 -07005134 /**
5135 * {@hide}
5136 * Returns Default subId, 0 in the case of single standby.
5137 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005138 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005139 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005140 }
5141
Shishir Agrawala9f32182016-04-12 12:00:16 -07005142 private int getSlotForDefaultSubscription() {
5143 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5144 }
5145
Wink Savilleb564aae2014-10-23 10:18:09 -07005146 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005147 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005148 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005149
Pengquan Menge92a50d2018-09-21 15:54:48 -07005150 private boolean isActiveSubscription(int subId) {
5151 return mSubscriptionController.isActiveSubId(subId);
5152 }
5153
Ihab Awadf2177b72013-11-25 13:33:23 -08005154 /**
5155 * @see android.telephony.TelephonyManager.WifiCallingChoices
5156 */
5157 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 final long identity = Binder.clearCallingIdentity();
5159 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005160 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5162 getWhenToMakeWifiCallsDefaultPreference());
5163 } finally {
5164 Binder.restoreCallingIdentity(identity);
5165 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005166 }
5167
5168 /**
5169 * @see android.telephony.TelephonyManager.WifiCallingChoices
5170 */
5171 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 final long identity = Binder.clearCallingIdentity();
5173 try {
5174 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005175 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005176 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5177 } finally {
5178 Binder.restoreCallingIdentity(identity);
5179 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005180 }
5181
Sailesh Nepald1e68152013-12-12 19:08:02 -08005182 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005183 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005184 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005185 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005186
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005187 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5188 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5189 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005190 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005191 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5192 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005193 }
5194 return PhoneFactory.getPhone(phoneId);
5195 }
5196
Shishir Agrawal566b7612013-10-28 14:41:00 -07005197 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005198 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005199 @NonNull IccLogicalChannelRequest request) {
5200 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5201 /*message=*/ "iccOpenLogicalChannel");
5202
5203 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5204 // Verify that the callingPackage in the request belongs to the calling UID
5205 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5206
5207 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005208 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005209
Rambo Wanga1782702021-11-10 20:15:19 -08005210 private Phone getPhoneFromValidIccLogicalChannelRequest(
5211 @NonNull IccLogicalChannelRequest request, String message) {
5212 Phone phone;
5213 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5215 mApp, request.subId, message);
5216 phone = getPhoneFromSubId(request.subId);
5217 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5218 enforceModifyPermission();
5219 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5220 } else {
5221 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005222 }
Rambo Wanga1782702021-11-10 20:15:19 -08005223 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005224 }
5225
5226 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005227 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 final long identity = Binder.clearCallingIdentity();
5229 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005230 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005232 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5233 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005234 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5235 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236 loge("The calling package is not allowed to access ISD-R.");
5237 throw new SecurityException(
5238 "The calling package is not allowed to access ISD-R.");
5239 }
Derek Tan740e1672017-06-27 14:56:27 -07005240 }
Derek Tan740e1672017-06-27 14:56:27 -07005241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005243 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5244 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 return response;
5246 } finally {
5247 Binder.restoreCallingIdentity(identity);
5248 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005249 }
5250
5251 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005252 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5253 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5254 /*message=*/"iccCloseLogicalChannel");
5255
5256 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5257
5258 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005259 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005260
Rambo Wanga1782702021-11-10 20:15:19 -08005261 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5262 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005263 // before this feature is enabled, this API should only return false if
5264 // the operation fails instead of throwing runtime exception for
5265 // backward-compatibility.
5266 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5267 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 final long identity = Binder.clearCallingIdentity();
5269 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005270 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005271 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005272 }
Chen Xue9d737e2022-01-01 23:41:31 -08005273 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005274 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005275 Boolean success = false;
5276 if (result instanceof RuntimeException) {
5277 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005278 if (shouldThrowExceptionOnFailure) {
5279 throw (RuntimeException) result;
5280 } else {
5281 return false;
5282 }
Chen Xue9d737e2022-01-01 23:41:31 -08005283 } else if (result instanceof Boolean) {
5284 success = (Boolean) result;
5285 } else {
5286 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5287 }
Rambo Wanga1782702021-11-10 20:15:19 -08005288 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 return success;
5290 } finally {
5291 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005292 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005293 }
5294
5295 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005296 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005297 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5299 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005300 if (DBG) {
5301 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5302 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5303 + p3 + " data=" + data);
5304 }
5305 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5306 command, p1, p2, p3, data);
5307 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005308
Jordan Liu4c733742019-02-28 12:03:40 -08005309 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005310 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5311 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005312 enforceModifyPermission();
5313 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005314 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5315 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5316 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005317 }
5318 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005319 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5320 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005321 }
5322
5323 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5324 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 final long identity = Binder.clearCallingIdentity();
5326 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005327 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005328 return "";
5329 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005332 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5333 null /* workSource */);
5334 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 // Append the returned status code to the end of the response payload.
5337 String s = Integer.toHexString(
5338 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5339 if (response.payload != null) {
5340 s = IccUtils.bytesToHexString(response.payload) + s;
5341 }
5342 return s;
5343 } finally {
5344 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005345 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005346 }
Jake Hambye994d462014-02-03 13:10:13 -08005347
Evan Charltonc66da362014-05-16 14:06:40 -07005348 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005349 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5350 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5352 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005354 if (DBG) {
5355 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5356 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5357 }
5358 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5359 cla, command, p1, p2, p3, data);
5360 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005361
Jordan Liu4c733742019-02-28 12:03:40 -08005362 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005363 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5364 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005365 enforceModifyPermission();
5366 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5367 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005368 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5369 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5370 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005371 }
5372
5373 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005374 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5375 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005376 }
5377
5378 // open APDU basic channel assuming the caller has sufficient permissions
5379 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5380 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005381 final long identity = Binder.clearCallingIdentity();
5382 try {
5383 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5384 && TextUtils.equals(ISDR_AID, data)) {
5385 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005386 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5387 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388 if (bestComponent == null
5389 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5390 loge("The calling package is not allowed to select ISD-R.");
5391 throw new SecurityException(
5392 "The calling package is not allowed to select ISD-R.");
5393 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005394 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005397 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5398 null /* workSource */);
5399 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401 // Append the returned status code to the end of the response payload.
5402 String s = Integer.toHexString(
5403 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5404 if (response.payload != null) {
5405 s = IccUtils.bytesToHexString(response.payload) + s;
5406 }
5407 return s;
5408 } finally {
5409 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005410 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005411 }
5412
5413 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005414 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005415 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5417 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 final long identity = Binder.clearCallingIdentity();
5420 try {
5421 if (DBG) {
5422 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5423 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5424 }
5425
5426 IccIoResult response =
5427 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5428 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5429 subId);
5430
5431 if (DBG) {
5432 log("Exchange SIM_IO [R]" + response);
5433 }
5434
5435 byte[] result = null;
5436 int length = 2;
5437 if (response.payload != null) {
5438 length = 2 + response.payload.length;
5439 result = new byte[length];
5440 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5441 } else {
5442 result = new byte[length];
5443 }
5444
5445 result[length - 1] = (byte) response.sw2;
5446 result[length - 2] = (byte) response.sw1;
5447 return result;
5448 } finally {
5449 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005450 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005451 }
5452
Nathan Haroldb3014052017-01-25 15:57:32 -08005453 /**
5454 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5455 * on a particular subscription
5456 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005457 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5458 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005460 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005461 return null;
5462 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005463
5464 final long identity = Binder.clearCallingIdentity();
5465 try {
5466 if (appType != TelephonyManager.APPTYPE_USIM
5467 && appType != TelephonyManager.APPTYPE_SIM) {
5468 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5469 return null;
5470 }
5471 Object response = sendRequest(
5472 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5473 if (response instanceof String[]) {
5474 return (String[]) response;
5475 }
yincheng zhao2737e882019-09-06 17:06:54 -07005476 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005478 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479 } finally {
5480 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005481 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005482 }
5483
yincheng zhao2737e882019-09-06 17:06:54 -07005484 /**
5485 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5486 * subscription.
5487 *
5488 * @param subId the id of the subscription.
5489 * @param appType the uicc app type, must be USIM or SIM.
5490 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5491 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005492 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005493 * @return number of fplmns that is successfully written to the SIM.
5494 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005495 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5496 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5498 mApp, subId, "setForbiddenPlmns");
5499
yincheng zhao2737e882019-09-06 17:06:54 -07005500 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5501 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5502 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5503 }
5504 if (fplmns == null) {
5505 throw new IllegalArgumentException("Fplmn List provided is null");
5506 }
5507 for (String fplmn : fplmns) {
5508 if (!CellIdentity.isValidPlmn(fplmn)) {
5509 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5510 }
5511 }
5512 final long identity = Binder.clearCallingIdentity();
5513 try {
5514 Object response = sendRequest(
5515 CMD_SET_FORBIDDEN_PLMNS,
5516 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5517 subId);
5518 return (int) response;
5519 } finally {
5520 Binder.restoreCallingIdentity(identity);
5521 }
5522 }
5523
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005524 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005525 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5527 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 final long identity = Binder.clearCallingIdentity();
5530 try {
5531 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5532 if (response.payload == null) {
5533 return "";
5534 }
Evan Charltonc66da362014-05-16 14:06:40 -07005535
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536 // Append the returned status code to the end of the response payload.
5537 String s = Integer.toHexString(
5538 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5539 s = IccUtils.bytesToHexString(response.payload) + s;
5540 return s;
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
5543 }
Evan Charltonc66da362014-05-16 14:06:40 -07005544 }
5545
Jake Hambye994d462014-02-03 13:10:13 -08005546 /**
5547 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5548 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5549 *
5550 * @param itemID the ID of the item to read
5551 * @return the NV item as a String, or null on error.
5552 */
5553 @Override
5554 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005555 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5557 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558
5559 final long identity = Binder.clearCallingIdentity();
5560 try {
5561 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005562 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005563 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5564 return value;
5565 } finally {
5566 Binder.restoreCallingIdentity(identity);
5567 }
Jake Hambye994d462014-02-03 13:10:13 -08005568 }
5569
5570 /**
5571 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5572 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5573 *
5574 * @param itemID the ID of the item to read
5575 * @param itemValue the value to write, as a String
5576 * @return true on success; false on any failure
5577 */
5578 @Override
5579 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005580 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5582 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583
5584 final long identity = Binder.clearCallingIdentity();
5585 try {
5586 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5587 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005588 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5590 return success;
5591 } finally {
5592 Binder.restoreCallingIdentity(identity);
5593 }
Jake Hambye994d462014-02-03 13:10:13 -08005594 }
5595
5596 /**
5597 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5598 * Used for device configuration by some CDMA operators.
5599 *
5600 * @param preferredRoamingList byte array containing the new PRL
5601 * @return true on success; false on any failure
5602 */
5603 @Override
5604 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5606 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607
5608 final long identity = Binder.clearCallingIdentity();
5609 try {
5610 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5611 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5612 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5613 return success;
5614 } finally {
5615 Binder.restoreCallingIdentity(identity);
5616 }
Jake Hambye994d462014-02-03 13:10:13 -08005617 }
5618
5619 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005620 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005621 * Used for device configuration by some CDMA operators.
5622 *
chen xu6dac5ab2018-10-26 17:39:23 -07005623 * @param slotIndex - device slot.
5624 *
Jake Hambye994d462014-02-03 13:10:13 -08005625 * @return true on success; false on any failure
5626 */
5627 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005628 public boolean resetModemConfig(int slotIndex) {
5629 Phone phone = PhoneFactory.getPhone(slotIndex);
5630 if (phone != null) {
5631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5632 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633
chen xu6dac5ab2018-10-26 17:39:23 -07005634 final long identity = Binder.clearCallingIdentity();
5635 try {
5636 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5637 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5638 return success;
5639 } finally {
5640 Binder.restoreCallingIdentity(identity);
5641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 }
chen xu6dac5ab2018-10-26 17:39:23 -07005643 return false;
5644 }
5645
5646 /**
5647 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5648 *
5649 * @param slotIndex - device slot.
5650 *
5651 * @return true on success; false on any failure
5652 */
5653 @Override
5654 public boolean rebootModem(int slotIndex) {
5655 Phone phone = PhoneFactory.getPhone(slotIndex);
5656 if (phone != null) {
5657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5658 mApp, phone.getSubId(), "rebootModem");
5659
5660 final long identity = Binder.clearCallingIdentity();
5661 try {
5662 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5663 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5664 return success;
5665 } finally {
5666 Binder.restoreCallingIdentity(identity);
5667 }
5668 }
5669 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005670 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005671
Brad Ebinger51f743a2017-01-23 13:50:20 -08005672 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005673 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5674 * {@link #disableIms(int)}.
5675 * @param slotIndex device slot.
5676 */
5677 public void resetIms(int slotIndex) {
5678 enforceModifyPermission();
5679
5680 final long identity = Binder.clearCallingIdentity();
5681 try {
5682 if (mImsResolver == null) {
5683 // may happen if the does not support IMS.
5684 return;
5685 }
5686 mImsResolver.disableIms(slotIndex);
5687 mImsResolver.enableIms(slotIndex);
5688 } finally {
5689 Binder.restoreCallingIdentity(identity);
5690 }
5691 }
5692
5693 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005694 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5695 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005696 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005697 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005698 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699
5700 final long identity = Binder.clearCallingIdentity();
5701 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005702 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005703 // may happen if the device does not support IMS.
5704 return;
5705 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005706 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707 } finally {
5708 Binder.restoreCallingIdentity(identity);
5709 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005710 }
5711
5712 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005713 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5714 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005715 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005716 public void disableIms(int slotId) {
5717 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718
5719 final long identity = Binder.clearCallingIdentity();
5720 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005721 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005722 // may happen if the device does not support IMS.
5723 return;
5724 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005725 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 } finally {
5727 Binder.restoreCallingIdentity(identity);
5728 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005729 }
5730
5731 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005732 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5733 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005734 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005735 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005736 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005737 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738
5739 final long identity = Binder.clearCallingIdentity();
5740 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005741 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005742 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5743 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005744 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005745 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746 } finally {
5747 Binder.restoreCallingIdentity(identity);
5748 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005749 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005750 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005751 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5752 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005753 @Override
5754 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005755 enforceModifyPermission();
5756
5757 final long identity = Binder.clearCallingIdentity();
5758 try {
5759 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005760 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005761 } finally {
5762 Binder.restoreCallingIdentity(identity);
5763 }
5764 }
5765
5766 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005767 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005768 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005769 */
5770 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5771 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772
5773 final long identity = Binder.clearCallingIdentity();
5774 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005775 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005776 // may happen if the device does not support IMS.
5777 return null;
5778 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005779 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780 } finally {
5781 Binder.restoreCallingIdentity(identity);
5782 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005783 }
5784
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005785 /**
5786 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005787 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005788 */
5789 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5790 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791
5792 final long identity = Binder.clearCallingIdentity();
5793 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005794 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005795 // may happen if the device does not support IMS.
5796 return null;
5797 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005798 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799 } finally {
5800 Binder.restoreCallingIdentity(identity);
5801 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005802 }
5803
Brad Ebinger884c07b2018-02-15 16:17:40 -08005804 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005805 * Sets the ImsService Package Name that Telephony will bind to.
5806 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005807 * @param slotIndex the slot ID that the ImsService should bind for.
5808 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005809 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005810 * @param featureTypes An integer array of feature types associated with a packageName.
5811 * @param packageName The name of the package that the current configuration will be replaced
5812 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005813 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005814 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005815 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5816 int[] featureTypes, String packageName) {
5817 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5818 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5820 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005821 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005822
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 final long identity = Binder.clearCallingIdentity();
5824 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005825 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005826 // may happen if the device does not support IMS.
5827 return false;
5828 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005829 Map<Integer, String> featureConfig = new HashMap<>();
5830 for (int featureType : featureTypes) {
5831 featureConfig.put(featureType, packageName);
5832 }
5833 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5834 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005835 } finally {
5836 Binder.restoreCallingIdentity(identity);
5837 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005838 }
5839
5840 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005841 * Clears any carrier ImsService overrides for the slot index specified that were previously
5842 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5843 *
5844 * This should only be used for testing.
5845 *
5846 * @param slotIndex the slot ID that the ImsService should bind for.
5847 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5848 */
5849 @Override
5850 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5851 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5852 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5853 "clearCarrierImsServiceOverride");
5854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5855 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5856 "clearCarrierImsServiceOverride");
5857
5858 final long identity = Binder.clearCallingIdentity();
5859 try {
5860 if (mImsResolver == null) {
5861 // may happen if the device does not support IMS.
5862 return false;
5863 }
5864 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5865 } finally {
5866 Binder.restoreCallingIdentity(identity);
5867 }
5868 }
5869
5870 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005871 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005872 *
5873 * @param slotId The slot that the ImsService is associated with.
5874 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5875 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005876 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005877 * @return the package name of the ImsService configuration.
5878 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005879 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5880 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005881 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005882 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005883 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005884 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5885 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 final long identity = Binder.clearCallingIdentity();
5888 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005889 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005890 // may happen if the device does not support IMS.
5891 return "";
5892 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005893 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005894 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5895 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896 } finally {
5897 Binder.restoreCallingIdentity(identity);
5898 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005899 }
5900
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005901 /**
5902 * Get the MmTelFeature state associated with the requested subscription id.
5903 * @param subId The subscription that the MmTelFeature is associated with.
5904 * @param callback A callback with an integer containing the
5905 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5906 */
5907 @Override
5908 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5909 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005910 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5911 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5912 "IMS not available on device.");
5913 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005914 final long token = Binder.clearCallingIdentity();
5915 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005916 int slotId = getSlotIndex(subId);
5917 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5918 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5919 + subId + "'");
5920 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5921 }
5922 verifyImsMmTelConfiguredOrThrow(slotId);
5923 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5924 try {
5925 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5926 } catch (RemoteException e) {
5927 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5928 + "Ignore");
5929 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005930 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005931 } catch (ImsException e) {
5932 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005933 } finally {
5934 Binder.restoreCallingIdentity(token);
5935 }
5936 }
5937
Daniel Brightbb5840b2021-01-12 15:48:18 -08005938 /**
5939 * Sets the ims registration state on all valid {@link Phone}s.
5940 */
5941 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005942 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943
5944 final long identity = Binder.clearCallingIdentity();
5945 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005946 // NOTE: Before S, this method only set the default phone.
5947 for (final Phone phone : PhoneFactory.getPhones()) {
5948 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5949 phone.setImsRegistrationState(registered);
5950 }
5951 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952 } finally {
5953 Binder.restoreCallingIdentity(identity);
5954 }
Wink Saville36469e72014-06-11 15:17:00 -07005955 }
5956
5957 /**
Stuart Scott54788802015-03-30 13:18:01 -07005958 * Set the network selection mode to automatic.
5959 *
5960 */
5961 @Override
5962 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5964 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965
5966 final long identity = Binder.clearCallingIdentity();
5967 try {
shilufc958392020-01-20 11:36:01 -08005968 if (!isActiveSubscription(subId)) {
5969 return;
5970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005972 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5973 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005974 } finally {
5975 Binder.restoreCallingIdentity(identity);
5976 }
Stuart Scott54788802015-03-30 13:18:01 -07005977 }
5978
Jack Yud10cdd42020-09-28 20:28:01 -07005979 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005980 * Ask the radio to connect to the input network and change selection mode to manual.
5981 *
5982 * @param subId the id of the subscription.
5983 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5984 * the operator to attach to.
5985 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5986 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5987 * normal network selection next time.
5988 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005989 */
5990 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005991 public boolean setNetworkSelectionModeManual(
5992 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5994 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005995
5996 if (!isActiveSubscription(subId)) {
5997 return false;
5998 }
5999
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 final long identity = Binder.clearCallingIdentity();
6001 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006002 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006004 if (DBG) {
6005 log("setNetworkSelectionModeManual: subId: " + subId
6006 + " operator: " + operatorInfo);
6007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6009 } finally {
6010 Binder.restoreCallingIdentity(identity);
6011 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006012 }
shilu84f6e8b2019-12-19 13:58:01 -08006013 /**
6014 * Get the manual network selection
6015 *
6016 * @param subId the id of the subscription.
6017 *
6018 * @return the previously saved user selected PLMN
6019 */
6020 @Override
6021 public String getManualNetworkSelectionPlmn(int subId) {
6022 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006023 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006024 mApp, subId, "getManualNetworkSelectionPlmn");
6025
6026 final long identity = Binder.clearCallingIdentity();
6027 try {
6028 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006029 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006030 }
6031
6032 final Phone phone = getPhone(subId);
6033 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006034 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006035 }
6036 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6037 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6038 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6039 } finally {
6040 Binder.restoreCallingIdentity(identity);
6041 }
6042 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006043
6044 /**
6045 * Scans for available networks.
6046 */
6047 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006048 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6049 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6051 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006052 LocationAccessPolicy.LocationPermissionResult locationResult =
6053 LocationAccessPolicy.checkLocationPermission(mApp,
6054 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6055 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006056 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006057 .setCallingPid(Binder.getCallingPid())
6058 .setCallingUid(Binder.getCallingUid())
6059 .setMethod("getCellNetworkScanResults")
6060 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006061 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6062 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006063 .build());
6064 switch (locationResult) {
6065 case DENIED_HARD:
6066 throw new SecurityException("Not allowed to access scan results -- location");
6067 case DENIED_SOFT:
6068 return null;
6069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070
Pengquan Menga1bb6272018-09-06 09:59:22 -07006071 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 try {
6073 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006074 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076 } finally {
6077 Binder.restoreCallingIdentity(identity);
6078 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006079 }
6080
6081 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006082 * Get the call forwarding info, given the call forwarding reason.
6083 */
6084 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006085 public void getCallForwarding(int subId, int callForwardingReason,
6086 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006087 enforceReadPrivilegedPermission("getCallForwarding");
6088 long identity = Binder.clearCallingIdentity();
6089 try {
6090 if (DBG) {
6091 log("getCallForwarding: subId " + subId
6092 + " callForwardingReason" + callForwardingReason);
6093 }
Hall Liu27d24262020-09-18 19:04:59 -07006094
6095 Phone phone = getPhone(subId);
6096 if (phone == null) {
6097 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006098 callback.onError(
6099 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006100 } catch (RemoteException e) {
6101 // ignore
6102 }
6103 return;
6104 }
6105
6106 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6107 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6108 @Override
6109 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6110 try {
6111 callback.onCallForwardingInfoAvailable(info);
6112 } catch (RemoteException e) {
6113 // ignore
6114 }
6115 }
6116
6117 @Override
6118 public void onError(int error) {
6119 try {
6120 callback.onError(error);
6121 } catch (RemoteException e) {
6122 // ignore
6123 }
6124 }
6125 });
6126 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006127 } finally {
6128 Binder.restoreCallingIdentity(identity);
6129 }
6130 }
6131
6132 /**
6133 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6134 * reason, the number to forward, and the timeout before the forwarding is attempted.
6135 */
6136 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006137 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6138 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006139 enforceModifyPermission();
6140 long identity = Binder.clearCallingIdentity();
6141 try {
6142 if (DBG) {
6143 log("setCallForwarding: subId " + subId
6144 + " callForwardingInfo" + callForwardingInfo);
6145 }
Hall Liu27d24262020-09-18 19:04:59 -07006146
6147 Phone phone = getPhone(subId);
6148 if (phone == null) {
6149 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006150 callback.accept(
6151 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006152 } catch (RemoteException e) {
6153 // ignore
6154 }
6155 return;
6156 }
6157
6158 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6159 FunctionalUtils.ignoreRemoteException(callback::accept));
6160
6161 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006162 } finally {
6163 Binder.restoreCallingIdentity(identity);
6164 }
6165 }
6166
6167 /**
Hall Liu27d24262020-09-18 19:04:59 -07006168 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006169 */
6170 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006171 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006172 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006173 long identity = Binder.clearCallingIdentity();
6174 try {
Hall Liu27d24262020-09-18 19:04:59 -07006175 Phone phone = getPhone(subId);
6176 if (phone == null) {
6177 try {
6178 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6179 } catch (RemoteException e) {
6180 // ignore
6181 }
6182 return;
6183 }
SongFerngWang0e767992021-03-31 22:08:45 +08006184 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6185 PersistableBundle c = configManager.getConfigForSubId(subId);
6186 boolean requireUssd = c.getBoolean(
6187 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006188
Shuo Qian4a594052020-01-23 11:59:30 -08006189 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006190 if (requireUssd) {
6191 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6192 getSubscriptionCarrierId(subId));
6193 String newUssdCommand = "";
6194 try {
6195 newUssdCommand = carrierXmlParser.getFeature(
6196 CarrierXmlParser.FEATURE_CALL_WAITING)
6197 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6198 } catch (NullPointerException e) {
6199 loge("Failed to generate USSD number" + e);
6200 }
6201 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6202 mMainThreadHandler, callback, carrierXmlParser,
6203 CarrierXmlParser.SsEntry.SSAction.QUERY);
6204 final String ussdCommand = newUssdCommand;
6205 Executors.newSingleThreadExecutor().execute(() -> {
6206 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6207 });
6208 } else {
6209 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6210 callback::accept);
6211 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6212 }
Shuo Qian4a594052020-01-23 11:59:30 -08006213 } finally {
6214 Binder.restoreCallingIdentity(identity);
6215 }
6216 }
6217
6218 /**
Hall Liu27d24262020-09-18 19:04:59 -07006219 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006220 */
6221 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006222 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006223 enforceModifyPermission();
6224 long identity = Binder.clearCallingIdentity();
6225 try {
Hall Liu27d24262020-09-18 19:04:59 -07006226 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6227
6228 Phone phone = getPhone(subId);
6229 if (phone == null) {
6230 try {
6231 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6232 } catch (RemoteException e) {
6233 // ignore
6234 }
6235 return;
6236 }
6237
SongFerngWang0e767992021-03-31 22:08:45 +08006238 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6239 PersistableBundle c = configManager.getConfigForSubId(subId);
6240 boolean requireUssd = c.getBoolean(
6241 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006242
SongFerngWang0e767992021-03-31 22:08:45 +08006243 if (DBG) log("getCallWaitingStatus: subId " + subId);
6244 if (requireUssd) {
6245 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6246 getSubscriptionCarrierId(subId));
6247 CarrierXmlParser.SsEntry.SSAction ssAction =
6248 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6249 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6250 String newUssdCommand = "";
6251 try {
6252 newUssdCommand = carrierXmlParser.getFeature(
6253 CarrierXmlParser.FEATURE_CALL_WAITING)
6254 .makeCommand(ssAction, null);
6255 } catch (NullPointerException e) {
6256 loge("Failed to generate USSD number" + e);
6257 }
6258 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6259 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6260 final String ussdCommand = newUssdCommand;
6261 Executors.newSingleThreadExecutor().execute(() -> {
6262 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6263 });
6264 } else {
6265 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6266 FunctionalUtils.ignoreRemoteException(callback::accept));
6267
6268 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6269 }
Shuo Qian4a594052020-01-23 11:59:30 -08006270 } finally {
6271 Binder.restoreCallingIdentity(identity);
6272 }
6273 }
6274
6275 /**
yinxub1bed742017-04-17 11:45:04 -07006276 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006277 *
yinxub1bed742017-04-17 11:45:04 -07006278 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006279 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6280 * location related information which will be sent if the caller already possess
6281 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006282 * @param request contains the radio access networks with bands/channels to scan
6283 * @param messenger callback messenger for scan results or errors
6284 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006285 * @return the id of the requested scan which can be used to stop the scan.
6286 */
6287 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006288 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6289 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006290 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6292 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006293 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006294 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6295 if (!renounceFineLocationAccess) {
6296 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6297 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6298 .setCallingPackage(callingPackage)
6299 .setCallingFeatureId(callingFeatureId)
6300 .setCallingPid(Binder.getCallingPid())
6301 .setCallingUid(Binder.getCallingUid())
6302 .setMethod("requestNetworkScan")
6303 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6304 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6305 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6306 .build());
6307 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006308 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006309 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6310 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006311 if (e != null) {
6312 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6313 throw e;
6314 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006315 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006316 return TelephonyScanManager.INVALID_SCAN_ID;
6317 }
6318 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319 }
Hall Liu912dfd32019-04-25 14:02:26 -07006320 int callingUid = Binder.getCallingUid();
6321 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006322 final long identity = Binder.clearCallingIdentity();
6323 try {
6324 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006325 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006326 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006327 } finally {
6328 Binder.restoreCallingIdentity(identity);
6329 }
yinxu504e1392017-04-12 16:03:22 -07006330 }
6331
Hall Liub2ac8ef2019-02-28 15:56:23 -08006332 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006333 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wangaccdabf2022-10-20 16:52:29 +00006334 boolean hasCarrierPriv;
6335 final long identity = Binder.clearCallingIdentity();
6336 try {
6337 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6338 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6339 } finally {
6340 Binder.restoreCallingIdentity(identity);
6341 }
Hall Liu558027f2019-05-15 19:14:05 -07006342 boolean hasNetworkScanPermission =
6343 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6344 == PERMISSION_GRANTED;
6345
6346 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6347 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6348 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006349 }
6350
6351 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6352 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006353 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6354 return new SecurityException("Specific channels must not be"
6355 + " scanned without location access.");
6356 }
6357 }
6358 }
6359
Hall Liub2ac8ef2019-02-28 15:56:23 -08006360 return null;
6361 }
6362
yinxu504e1392017-04-12 16:03:22 -07006363 /**
6364 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006365 *
6366 * @param subId id of the subscription
6367 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006368 */
6369 @Override
6370 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6372 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006373
Hall Liu912dfd32019-04-25 14:02:26 -07006374 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375 final long identity = Binder.clearCallingIdentity();
6376 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006377 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378 } finally {
6379 Binder.restoreCallingIdentity(identity);
6380 }
yinxu504e1392017-04-12 16:03:22 -07006381 }
6382
6383 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006384 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006385 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006386 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006387 */
6388 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006389 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006390 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006391 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006392 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006393
6394 final long identity = Binder.clearCallingIdentity();
6395 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006396 if (DBG) log("getAllowedNetworkTypesBitmask");
6397 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6398 int networkTypesBitmask = (result != null ? result[0] : -1);
6399 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6400 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 } finally {
6402 Binder.restoreCallingIdentity(identity);
6403 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006404 }
6405
6406 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006407 * Get the allowed network types for certain reason.
6408 *
6409 * @param subId the id of the subscription.
6410 * @param reason the reason the allowed network type change is taking place
6411 * @return the allowed network types.
6412 */
6413 @Override
6414 public long getAllowedNetworkTypesForReason(int subId,
6415 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006416 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006417 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006418 final long identity = Binder.clearCallingIdentity();
6419 try {
6420 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6421 } finally {
6422 Binder.restoreCallingIdentity(identity);
6423 }
6424 }
6425
6426 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006427 * Enable/Disable E-UTRA-NR Dual Connectivity
6428 * @param subId subscription id of the sim card
6429 * @param nrDualConnectivityState expected NR dual connectivity state
6430 * This can be passed following states
6431 * <ol>
6432 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6433 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6434 * <li>Disable NR dual connectivity and force secondary cell to be released
6435 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6436 * </ol>
6437 * @return operation result.
6438 */
6439 @Override
6440 public int setNrDualConnectivityState(int subId,
6441 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6443 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006444 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006445 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6446 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6447 }
6448
Sooraj Sasindran37444802020-08-11 10:40:43 -07006449 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6450 final long identity = Binder.clearCallingIdentity();
6451 try {
6452 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6453 nrDualConnectivityState, subId,
6454 workSource);
6455 if (DBG) log("enableNRDualConnectivity result: " + result);
6456 return result;
6457 } finally {
6458 Binder.restoreCallingIdentity(identity);
6459 }
6460 }
6461
6462 /**
6463 * Is E-UTRA-NR Dual Connectivity enabled
6464 * @return true if dual connectivity is enabled else false
6465 */
6466 @Override
6467 public boolean isNrDualConnectivityEnabled(int subId) {
6468 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006469 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006470 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006471 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006472 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6473 return false;
6474 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006475 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6476 final long identity = Binder.clearCallingIdentity();
6477 try {
6478 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6479 null, subId, workSource);
6480 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6481 return isEnabled;
6482 } finally {
6483 Binder.restoreCallingIdentity(identity);
6484 }
6485 }
6486
6487 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006488 * Set the allowed network types of the device and
6489 * provide the reason triggering the allowed network change.
6490 *
6491 * @param subId the id of the subscription.
6492 * @param reason the reason the allowed network type change is taking place
6493 * @param allowedNetworkTypes the allowed network types.
6494 * @return true on success; false on any failure.
6495 */
6496 @Override
6497 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006498 @TelephonyManager.AllowedNetworkTypesReason int reason,
6499 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6501 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006502 // If the caller only has carrier privileges, then they should not be able to override
6503 // any network types which were set for security reasons.
6504 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6505 != PERMISSION_GRANTED
6506 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6507 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6508 throw new SecurityException(
6509 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6510 + " reason "
6511 + reason);
6512 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006513 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006514 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6515 return false;
6516 }
6517 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6518 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006519 return false;
6520 }
6521
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006522 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6523 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6524
6525
6526 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6527 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6528 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006529 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006530
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006531 final long identity = Binder.clearCallingIdentity();
6532 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006533 Boolean success = (Boolean) sendRequest(
6534 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6535 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6536
6537 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6538 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006539 } finally {
6540 Binder.restoreCallingIdentity(identity);
6541 }
6542 }
6543
6544 /**
Miaoa84611c2019-03-15 09:21:10 +08006545 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006546 *
Miaoa84611c2019-03-15 09:21:10 +08006547 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006548 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006549 * @hide
6550 */
6551 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006552 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006553 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006555 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556 try {
Miaoa84611c2019-03-15 09:21:10 +08006557 if (phone != null) {
6558 return phone.hasMatchedTetherApnSetting();
6559 } else {
6560 return false;
6561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 } finally {
6563 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006564 }
Junda Liu475951f2014-11-07 16:45:03 -08006565 }
6566
6567 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006568 * Get the user enabled state of Mobile Data.
6569 *
6570 * TODO: remove and use isUserDataEnabled.
6571 * This can't be removed now because some vendor codes
6572 * calls through ITelephony directly while they should
6573 * use TelephonyManager.
6574 *
6575 * @return true on enabled
6576 */
6577 @Override
6578 public boolean getDataEnabled(int subId) {
6579 return isUserDataEnabled(subId);
6580 }
6581
6582 /**
6583 * Get whether mobile data is enabled per user setting.
6584 *
6585 * There are other factors deciding whether mobile data is actually enabled, but they are
6586 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006587 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006588 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6589 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006590 *
6591 * @return {@code true} if data is enabled else {@code false}
6592 */
6593 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006594 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006595 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006596 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006597 try {
6598 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6599 functionName);
6600 } catch (Exception e) {
6601 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6602 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006603 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006605 mApp, subId, functionName);
6606
Robert Greenwalt646120a2014-05-23 11:54:03 -07006607 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006608
6609 final long identity = Binder.clearCallingIdentity();
6610 try {
6611 int phoneId = mSubscriptionController.getPhoneId(subId);
6612 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6613 Phone phone = PhoneFactory.getPhone(phoneId);
6614 if (phone != null) {
6615 boolean retVal = phone.isUserDataEnabled();
6616 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6617 return retVal;
6618 } else {
6619 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6620 return false;
6621 }
6622 } finally {
6623 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006624 }
6625 }
6626
6627 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006628 * Checks if the device is capable of mobile data by considering whether whether the
6629 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6630 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006631 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006632 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006633 */
6634 @Override
6635 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006636 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006637 try {
6638 try {
6639 mApp.enforceCallingOrSelfPermission(
6640 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006641 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006642 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006643 try {
6644 mApp.enforceCallingOrSelfPermission(
6645 android.Manifest.permission.READ_PHONE_STATE,
6646 functionName);
6647 } catch (Exception e2) {
6648 mApp.enforceCallingOrSelfPermission(
6649 permission.READ_BASIC_PHONE_STATE, functionName);
6650 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006651 }
6652 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006653 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006654 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006655
6656 final long identity = Binder.clearCallingIdentity();
6657 try {
6658 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659 Phone phone = PhoneFactory.getPhone(phoneId);
6660 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006661 boolean retVal;
Jack Yud7b8d372022-07-31 00:43:21 -07006662 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006663 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006664 return retVal;
6665 } else {
6666 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6667 return false;
6668 }
6669 } finally {
6670 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006671 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006672 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006673
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006674 /**
6675 * Check if data is enabled for a specific reason
6676 * @param subId Subscription index
6677 * @param reason the reason the data enable change is taking place
6678 * @return {@code true} if the overall data is enabled; {@code false} if not.
6679 */
6680 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006681 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006682 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006683 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006684 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006685 try {
6686 mApp.enforceCallingOrSelfPermission(
6687 android.Manifest.permission.ACCESS_NETWORK_STATE,
6688 functionName);
6689 } catch (Exception e) {
6690 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6691 functionName);
6692 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006693 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006694 try {
6695 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006696 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006697 } catch (Exception e2) {
6698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006699 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006700 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006701 }
6702
6703
6704 final long identity = Binder.clearCallingIdentity();
6705 try {
6706 int phoneId = mSubscriptionController.getPhoneId(subId);
6707 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006708 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006709 + " reason=" + reason);
6710 }
6711 Phone phone = PhoneFactory.getPhone(phoneId);
6712 if (phone != null) {
6713 boolean retVal;
Jack Yud7b8d372022-07-31 00:43:21 -07006714 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006715 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006716 return retVal;
6717 } else {
6718 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006719 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006720 + subId + " retVal=false");
6721 }
6722 return false;
6723 }
6724 } finally {
6725 Binder.restoreCallingIdentity(identity);
6726 }
6727 }
6728
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006729 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006730 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006731 // No permission needed; this only lets the caller inspect their own status.
6732 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006733 }
Junda Liu29340342014-07-10 15:23:27 -07006734
6735 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006736 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006737 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006738 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6739 }
6740
6741 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6742 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006743 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006744 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006745 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6746 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006747 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6748 if (cpt == null) {
6749 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006750 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6751 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006752 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006753 }
6754
6755 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006756 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006757 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006758 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006759 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006760 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006761 Phone phone = getPhone(subId);
6762 if (phone == null) {
6763 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6764 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6765 }
6766 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6767 if (cpt == null) {
6768 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006769 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6770 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006771 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006772 }
6773
6774 @Override
6775 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006776 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006777 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6778 }
6779
6780 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006781 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006782 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006783 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006784 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006785 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6786 Phone phone = PhoneFactory.getPhone(phoneId);
6787 if (phone == null) {
6788 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006789 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006790 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6791 if (cpt == null) {
6792 continue;
6793 }
6794 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006795 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6796 break;
6797 }
6798 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006799 return result;
Junda Liu29340342014-07-10 15:23:27 -07006800 }
Derek Tan89e89d42014-07-08 17:00:10 -07006801
6802 @Override
Junda Liue64de782015-04-16 17:19:16 -07006803 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006804 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006805 Phone phone = PhoneFactory.getPhone(phoneId);
6806 if (phone == null) {
6807 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006808 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006809 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6810 if (cpt == null) {
6811 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006812 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006813 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006814 }
6815
Amith Yamasani6e118872016-02-19 12:53:51 -08006816 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006817 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006818 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006819 Phone phone = PhoneFactory.getPhone(phoneId);
6820 if (phone == null) {
6821 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006822 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006823 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6824 if (cpt == null) {
6825 return Collections.emptyList();
6826 }
6827 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006828 }
6829
chen xuf7e9fe82019-05-09 19:31:02 -07006830 @Override
6831 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006832 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006833 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006834 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006835 try {
6836 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6837 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6838 }
6839 } finally {
6840 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006841 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006842 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006843 }
6844
Rambo Wang6812ffb2022-03-15 16:54:17 -07006845 @Override
6846 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6847 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6848
6849 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6850 if (phone == null) {
6851 return null;
6852 }
6853 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6854 if (cpt == null) {
6855 return null;
6856 }
6857 return cpt.getCarrierServicePackageName();
6858 }
6859
Wink Savilleb564aae2014-10-23 10:18:09 -07006860 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006861 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006862 UiccPort port = phone == null ? null : phone.getUiccPort();
6863 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006864 return null;
6865 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006866 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006867 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006868 return null;
6869 }
6870 return iccId;
6871 }
6872
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006873 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006874 public void setCallComposerStatus(int subId, int status) {
6875 enforceModifyPermission();
6876
6877 final long identity = Binder.clearCallingIdentity();
6878 try {
6879 Phone phone = getPhone(subId);
6880 if (phone != null) {
6881 Phone defaultPhone = phone.getImsPhone();
6882 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6883 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6884 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006885 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6886 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006887 }
6888 }
Shuo Qian284ae752020-12-22 19:10:14 -08006889 } catch (ImsException e) {
6890 throw new ServiceSpecificException(e.getCode());
6891 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006892 Binder.restoreCallingIdentity(identity);
6893 }
6894 }
6895
6896 @Override
6897 public int getCallComposerStatus(int subId) {
6898 enforceReadPrivilegedPermission("getCallComposerStatus");
6899
6900 final long identity = Binder.clearCallingIdentity();
6901 try {
6902 Phone phone = getPhone(subId);
6903 if (phone != null) {
6904 Phone defaultPhone = phone.getImsPhone();
6905 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6906 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6907 return imsPhone.getCallComposerStatus();
6908 }
6909 }
6910 } finally {
6911 Binder.restoreCallingIdentity(identity);
6912 }
6913 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6914 }
6915
6916 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006917 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6918 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006919 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006920 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006922 final long identity = Binder.clearCallingIdentity();
6923 try {
6924 final String iccId = getIccId(subId);
6925 final Phone phone = getPhone(subId);
6926 if (phone == null) {
6927 return false;
6928 }
6929 final String subscriberId = phone.getSubscriberId();
6930
6931 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006932 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006933 + subscriberId + " to " + number);
6934 }
6935
6936 if (TextUtils.isEmpty(iccId)) {
6937 return false;
6938 }
6939
6940 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6941
6942 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6943 if (alphaTag == null) {
6944 editor.remove(alphaTagPrefKey);
6945 } else {
6946 editor.putString(alphaTagPrefKey, alphaTag);
6947 }
6948
6949 // Record both the line number and IMSI for this ICCID, since we need to
6950 // track all merged IMSIs based on line number
6951 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6952 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6953 if (number == null) {
6954 editor.remove(numberPrefKey);
6955 editor.remove(subscriberPrefKey);
6956 } else {
6957 editor.putString(numberPrefKey, number);
6958 editor.putString(subscriberPrefKey, subscriberId);
6959 }
6960
6961 editor.commit();
6962 return true;
6963 } finally {
6964 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006965 }
Derek Tan7226c842014-07-02 17:42:23 -07006966 }
6967
6968 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006969 public String getLine1NumberForDisplay(int subId, String callingPackage,
6970 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006971 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006973 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006974 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006975 return null;
6976 }
Derek Tan97ebb422014-09-05 16:55:38 -07006977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 final long identity = Binder.clearCallingIdentity();
6979 try {
6980 String iccId = getIccId(subId);
6981 if (iccId != null) {
6982 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6983 if (DBG_MERGE) {
6984 log("getLine1NumberForDisplay returning "
6985 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6986 }
6987 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006988 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006989 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6990 return null;
6991 } finally {
6992 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006993 }
Derek Tan7226c842014-07-02 17:42:23 -07006994 }
6995
6996 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006997 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6998 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006999 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007000 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
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 alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7009 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7010 }
7011 return null;
7012 } finally {
7013 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007014 }
Derek Tan7226c842014-07-02 17:42:23 -07007015 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007016
7017 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007018 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7019 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007020 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7021 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007023 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007024 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007025 return null;
7026 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007027
Jordan Liub49b04b2019-05-06 14:45:15 -07007028 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7029 // the process, where TelephonyManager was instantiated.
7030 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007031 final long identity = Binder.clearCallingIdentity();
7032 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007033 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034 final TelephonyManager tele = TelephonyManager.from(context);
7035 final SubscriptionManager sub = SubscriptionManager.from(context);
7036
7037 // Figure out what subscribers are currently active
7038 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007039
Jordan Liub49b04b2019-05-06 14:45:15 -07007040 // Only consider subs which match the current subId
7041 // This logic can be simplified. See b/131189269 for progress.
7042 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007043 activeSubscriberIds.add(tele.getSubscriberId(subId));
7044 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007045
7046 // First pass, find a number override for an active subscriber
7047 String mergeNumber = null;
7048 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7049 for (String key : prefs.keySet()) {
7050 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7051 final String subscriberId = (String) prefs.get(key);
7052 if (activeSubscriberIds.contains(subscriberId)) {
7053 final String iccId = key.substring(
7054 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7055 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7056 mergeNumber = (String) prefs.get(numberKey);
7057 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007058 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059 + " for active subscriber " + subscriberId);
7060 }
7061 if (!TextUtils.isEmpty(mergeNumber)) {
7062 break;
7063 }
7064 }
7065 }
7066 }
7067
7068 // Shortcut when no active merged subscribers
7069 if (TextUtils.isEmpty(mergeNumber)) {
7070 return null;
7071 }
7072
7073 // Second pass, find all subscribers under that line override
7074 final ArraySet<String> result = new ArraySet<>();
7075 for (String key : prefs.keySet()) {
7076 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7077 final String number = (String) prefs.get(key);
7078 if (mergeNumber.equals(number)) {
7079 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7080 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7081 final String subscriberId = (String) prefs.get(subscriberKey);
7082 if (!TextUtils.isEmpty(subscriberId)) {
7083 result.add(subscriberId);
7084 }
7085 }
7086 }
7087 }
7088
7089 final String[] resultArray = result.toArray(new String[result.size()]);
7090 Arrays.sort(resultArray);
7091 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007092 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007093 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7094 }
7095 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007096 } finally {
7097 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007098 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007099 }
7100
7101 @Override
zoey chen38003472019-12-13 17:16:31 +08007102 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7103 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007104
7105 final long identity = Binder.clearCallingIdentity();
7106 try {
7107 final TelephonyManager telephonyManager = mApp.getSystemService(
7108 TelephonyManager.class);
7109 String subscriberId = telephonyManager.getSubscriberId(subId);
7110 if (subscriberId == null) {
7111 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007112 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007113 + subId);
7114 }
7115 return null;
7116 }
7117
7118 final SubscriptionInfo info = SubscriptionController.getInstance()
7119 .getSubscriptionInfo(subId);
7120 final ParcelUuid groupUuid = info.getGroupUuid();
7121 // If it doesn't belong to any group, return just subscriberId of itself.
7122 if (groupUuid == null) {
7123 return new String[]{subscriberId};
7124 }
7125
7126 // Get all subscriberIds from the group.
7127 final List<String> mergedSubscriberIds = new ArrayList<>();
7128 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007129 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007130 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007131 for (SubscriptionInfo subInfo : groupInfos) {
7132 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7133 if (subscriberId != null) {
7134 mergedSubscriberIds.add(subscriberId);
7135 }
7136 }
7137
7138 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7139 } finally {
7140 Binder.restoreCallingIdentity(identity);
7141
7142 }
7143 }
7144
7145 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007146 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007147 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007148 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149
7150 final long identity = Binder.clearCallingIdentity();
7151 try {
7152 final Phone phone = getPhone(subId);
7153 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7154 } finally {
7155 Binder.restoreCallingIdentity(identity);
7156 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007157 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007158
7159 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007160 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007161 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7162 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007163 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7164 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007165
7166 final long identity = Binder.clearCallingIdentity();
7167 try {
7168 final Phone phone = getPhone(subId);
7169 if (phone == null) {
7170 return false;
7171 }
7172 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7173 cdmaNonRoamingList);
7174 } finally {
7175 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007176 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007177 }
7178
7179 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007180 @Deprecated
7181 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7182 enforceModifyPermission();
7183
7184 int returnValue = 0;
7185 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007186 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007187 if(result.exception == null) {
7188 if (result.result != null) {
7189 byte[] responseData = (byte[])(result.result);
7190 if(responseData.length > oemResp.length) {
7191 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7192 responseData.length + "bytes. Buffer Size is " +
7193 oemResp.length + "bytes.");
7194 }
7195 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7196 returnValue = responseData.length;
7197 }
7198 } else {
7199 CommandException ex = (CommandException) result.exception;
7200 returnValue = ex.getCommandError().ordinal();
7201 if(returnValue > 0) returnValue *= -1;
7202 }
7203 } catch (RuntimeException e) {
7204 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7205 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7206 if(returnValue > 0) returnValue *= -1;
7207 }
7208
7209 return returnValue;
7210 }
7211
7212 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007213 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007214 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007215 try {
7216 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007217 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007218 mApp, phone.getSubId(), "getRadioAccessFamily");
7219 } catch (SecurityException e) {
7220 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7221 throw e;
7222 }
chen xub97461a2018-10-26 14:17:57 -07007223 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007224 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007225 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007226 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 final long identity = Binder.clearCallingIdentity();
7228 try {
chen xub97461a2018-10-26 14:17:57 -07007229 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007230 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007231 mApp, phone.getSubId(), "getRadioAccessFamily");
7232 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007233 } finally {
7234 Binder.restoreCallingIdentity(identity);
7235 }
chen xub97461a2018-10-26 14:17:57 -07007236 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007237 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007238
7239 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007240 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007241 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007242 try {
7243 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7244 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007245 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007246 }
7247 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007248 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007249 }
7250 RoleManager rm = mApp.getSystemService(RoleManager.class);
7251 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7252 if (!dialerRoleHolders.contains(callingPackage)) {
7253 throw new SecurityException("App must be the dialer role holder to"
7254 + " upload a call composer pic");
7255 }
7256
7257 Executors.newSingleThreadExecutor().execute(() -> {
7258 ByteArrayOutputStream output = new ByteArrayOutputStream(
7259 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7260 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7261 boolean readUntilEnd = false;
7262 int totalBytesRead = 0;
7263 byte[] buffer = new byte[16 * 1024];
7264 while (true) {
7265 int numRead;
7266 try {
7267 numRead = input.read(buffer);
7268 } catch (IOException e) {
7269 try {
7270 fd.checkError();
7271 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7272 null);
7273 } catch (IOException e1) {
7274 // This means that the other side closed explicitly with an error. If this
7275 // happens, log and ignore.
7276 loge("Remote end of call composer picture pipe closed: " + e1);
7277 }
7278 break;
7279 }
7280 if (numRead == -1) {
7281 readUntilEnd = true;
7282 break;
7283 }
7284 totalBytesRead += numRead;
7285 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7286 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7287 try {
7288 input.close();
7289 } catch (IOException e) {
7290 // ignore
7291 }
7292 break;
7293 }
7294 output.write(buffer, 0, numRead);
7295 }
7296 // Generally, the remote end will close the file descriptors. The only case where we
7297 // close is above, where the picture size is too big.
7298
7299 try {
7300 fd.checkError();
7301 } catch (IOException e) {
7302 loge("Remote end for call composer closed with an error: " + e);
7303 return;
7304 }
7305
Hall Liuaa4211e2021-01-20 15:43:39 -08007306 if (!readUntilEnd) {
7307 loge("Did not finish reading entire image; aborting");
7308 return;
7309 }
Hall Liu82694d52020-12-11 18:22:04 -08007310
Hall Liuaa4211e2021-01-20 15:43:39 -08007311 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7312 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7313 new CallComposerPictureTransfer.Factory() {},
7314 imageData,
7315 (result) -> {
7316 if (result.first != null) {
7317 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7318 Bundle outputResult = new Bundle();
7319 outputResult.putParcelable(
7320 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7321 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7322 outputResult);
7323 } else {
7324 callback.send(result.second, null);
7325 }
7326 }
7327 );
Hall Liu82694d52020-12-11 18:22:04 -08007328 });
7329 }
7330
7331 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007332 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007333 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007334 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335
7336 final long identity = Binder.clearCallingIdentity();
7337 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007338 ImsManager.getInstance(defaultPhone.getContext(),
7339 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007340 } finally {
7341 Binder.restoreCallingIdentity(identity);
7342 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007343 }
7344
7345 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007346 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007347 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007348 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7349 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007350 return false;
7351 }
Svet Ganovb320e182015-04-16 12:30:10 -07007352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007353 final long identity = Binder.clearCallingIdentity();
7354 try {
7355 // Check the user preference and the system-level IMS setting. Even if the user has
7356 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7357 // In the long run, we may instead need to check if there exists a connection service
7358 // which can support video calling.
7359 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007360 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007361 return imsManager.isVtEnabledByPlatform()
7362 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7363 && imsManager.isVtEnabledByUser();
7364 } finally {
7365 Binder.restoreCallingIdentity(identity);
7366 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007367 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007368
Andrew Leea1239f22015-03-02 17:44:07 -08007369 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007370 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7371 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007373 mApp, subId, callingPackage, callingFeatureId,
7374 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 return false;
7376 }
7377
7378 final long identity = Binder.clearCallingIdentity();
7379 try {
7380 CarrierConfigManager configManager =
7381 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007382 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7384 } finally {
7385 Binder.restoreCallingIdentity(identity);
7386 }
Andrew Leea1239f22015-03-02 17:44:07 -08007387 }
7388
7389 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007390 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007392 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393 return false;
7394 }
7395
7396 final long identity = Binder.clearCallingIdentity();
7397 try {
7398 CarrierConfigManager configManager =
7399 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007400 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007401 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7402 } finally {
7403 Binder.restoreCallingIdentity(identity);
7404 }
Andrew Leea1239f22015-03-02 17:44:07 -08007405 }
7406
Andrew Lee9431b832015-03-09 18:46:45 -07007407 @Override
7408 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007409 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007410 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007411 }
7412
7413 @Override
7414 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 final long identity = Binder.clearCallingIdentity();
7416 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007417 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007418 } finally {
7419 Binder.restoreCallingIdentity(identity);
7420 }
Andrew Lee9431b832015-03-09 18:46:45 -07007421 }
7422
Hall Liuf6668912018-10-31 17:05:23 -07007423 /**
7424 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7425 * support for the feature and device firmware support.
7426 *
7427 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7428 */
7429 @Override
7430 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007431 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007432 final Phone phone = getPhone(subscriptionId);
7433 if (phone == null) {
7434 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7435 return false;
7436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007438 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7440 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007441 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442 return isCarrierSupported && isDeviceSupported;
7443 } finally {
7444 Binder.restoreCallingIdentity(identity);
7445 }
Hall Liu98187582018-01-22 19:15:32 -08007446 }
7447
Hall Liuf6668912018-10-31 17:05:23 -07007448 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007449 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7450 * RTT setting, will return true if the device and carrier both support RTT.
7451 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007452 */
7453 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007454 final long identity = Binder.clearCallingIdentity();
7455 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007456 boolean isRttSupported = isRttSupported(subscriptionId);
7457 boolean isUserRttSettingOn = Settings.Secure.getInt(
7458 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7459 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7460 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7461 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462 } finally {
7463 Binder.restoreCallingIdentity(identity);
7464 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007465 }
7466
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007467 @Deprecated
7468 @Override
7469 public String getDeviceId(String callingPackage) {
7470 return getDeviceIdWithFeature(callingPackage, null);
7471 }
7472
Sanket Padawe7310cc72015-01-14 09:53:20 -08007473 /**
7474 * Returns the unique device ID of phone, for example, the IMEI for
7475 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7476 *
7477 * <p>Requires Permission:
7478 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7479 */
7480 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007481 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007482 try {
7483 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7484 } catch (SecurityException se) {
7485 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7486 throw new SecurityException("Package " + callingPackage + " does not belong to "
7487 + Binder.getCallingUid());
7488 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007489 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007490 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007491 return null;
7492 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007493 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007494 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007495 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007496 return null;
7497 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007498
7499 final long identity = Binder.clearCallingIdentity();
7500 try {
7501 return phone.getDeviceId();
7502 } finally {
7503 Binder.restoreCallingIdentity(identity);
7504 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007505 }
7506
Ping Sunc67b7c22016-03-02 19:16:45 +08007507 /**
7508 * {@hide}
7509 * Returns the IMS Registration Status on a particular subid
7510 *
7511 * @param subId
7512 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007513 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007514 Phone phone = getPhone(subId);
7515 if (phone != null) {
7516 return phone.isImsRegistered();
7517 } else {
7518 return false;
7519 }
7520 }
7521
Santos Cordon7a1885b2015-02-03 11:15:19 -08007522 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007523 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007524 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007525 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007526 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007527 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7528 }
7529 final long identity = Binder.clearCallingIdentity();
7530 try {
7531 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7532 } finally {
7533 Binder.restoreCallingIdentity(identity);
7534 }
7535 }
7536
7537 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007538 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007539 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007540 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007541 mApp,
7542 subscriptionId,
7543 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007544 final long identity = Binder.clearCallingIdentity();
7545 try {
7546 Phone phone = getPhone(subscriptionId);
7547 if (phone == null) {
7548 return null;
7549 }
7550 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7551 } finally {
7552 Binder.restoreCallingIdentity(identity);
7553 }
7554 }
7555
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007556 /**
7557 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007558 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007559 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560 final long identity = Binder.clearCallingIdentity();
7561 try {
7562 Phone phone = getPhone(subId);
7563 if (phone != null) {
7564 return phone.isWifiCallingEnabled();
7565 } else {
7566 return false;
7567 }
7568 } finally {
7569 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007570 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007571 }
7572
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007573 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007574 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007575 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007576 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577 final long identity = Binder.clearCallingIdentity();
7578 try {
7579 Phone phone = getPhone(subId);
7580 if (phone != null) {
7581 return phone.isVideoEnabled();
7582 } else {
7583 return false;
7584 }
7585 } finally {
7586 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007587 }
7588 }
7589
7590 /**
7591 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7592 * defined in {@link ImsRegistrationImplBase}.
7593 */
7594 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595 final long identity = Binder.clearCallingIdentity();
7596 try {
7597 Phone phone = getPhone(subId);
7598 if (phone != null) {
7599 return phone.getImsRegistrationTech();
7600 } else {
7601 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7602 }
7603 } finally {
7604 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007605 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007606 }
7607
Stuart Scott8eef64f2015-04-08 15:13:54 -07007608 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007609 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007610 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007611 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7612 return;
7613 }
Kai Shif70f46f2021-03-03 13:59:46 -08007614 Phone defaultPhone = getDefaultPhone();
7615 if (defaultPhone != null) {
7616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7617 mApp, getDefaultPhone().getSubId(), "factoryReset");
7618 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007619 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007620
Svet Ganovcc087f82015-05-12 20:35:54 -07007621 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007622 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7623 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007624 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007625 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007626 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007627 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007628 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007629 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007630 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007631 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007632 // There has been issues when Sms raw table somehow stores orphan
7633 // fragments. They lead to garbled message when new fragments come
7634 // in and combined with those stale ones. In case this happens again,
7635 // user can reset all network settings which will clean up this table.
7636 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007637 // Clean up IMS settings as well here.
7638 int slotId = getSlotIndex(subId);
7639 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7640 ImsManager.getInstance(mApp, slotId).factoryReset();
7641 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007642
Kai Shif70f46f2021-03-03 13:59:46 -08007643 if (defaultPhone == null) {
7644 return;
7645 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007646 // Erase modem config if erase modem on network setting is enabled.
7647 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7648 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7649 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007650 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007651 }
Kai Shif70f46f2021-03-03 13:59:46 -08007652
7653 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007654 } finally {
7655 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007656 }
7657 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007658
SongFerngWangfd89b102021-05-27 22:44:54 +08007659 @VisibleForTesting
7660 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7661 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7662 return;
7663 }
7664 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7665 RILConstants.PREFERRED_NETWORK_MODE);
7666 SubscriptionManager.setSubscriptionProperty(subId,
7667 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7668 "user=" + defaultNetworkType);
7669 phone.loadAllowedNetworksFromSubscriptionDatabase();
7670 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7671 defaultNetworkType, null);
7672 }
7673
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007674 private void cleanUpSmsRawTable(Context context) {
7675 ContentResolver resolver = context.getContentResolver();
7676 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7677 resolver.delete(uri, null, null);
7678 }
7679
Narayan Kamath1c496c22015-04-16 14:40:19 +01007680 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007681 public String getSimLocaleForSubscriber(int subId) {
7682 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7683 final Phone phone = getPhone(subId);
7684 if (phone == null) {
7685 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007686 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007688 final long identity = Binder.clearCallingIdentity();
7689 try {
chen xu5d3637b2019-01-21 23:31:38 -08007690 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007691 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007692 if (info == null) {
7693 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7694 return null;
7695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007696 // Try and fetch the locale from the carrier properties or from the SIM language
7697 // preferences (EF-PL and EF-LI)...
7698 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007700 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7701 if (localeFromDefaultSim != null) {
7702 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7703 if (DBG) log("Using locale from subId: " + subId + " locale: "
7704 + localeFromDefaultSim);
tom hsu0b59d292022-09-29 23:49:21 +08007705 return matchLocaleFromSupportedLocaleList(localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007706 } else {
7707 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708 }
7709 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007711 // The SIM language preferences only store a language (e.g. fr = French), not an
7712 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7713 // the SIM and carrier preferences does not include a country we add the country
7714 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007715 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007717 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu0b59d292022-09-29 23:49:21 +08007718 return matchLocaleFromSupportedLocaleList(mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007719 }
7720
7721 if (DBG) log("No locale found - returning null");
7722 return null;
7723 } finally {
7724 Binder.restoreCallingIdentity(identity);
7725 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007726 }
7727
tom hsu0b59d292022-09-29 23:49:21 +08007728 @VisibleForTesting
7729 String matchLocaleFromSupportedLocaleList(@NonNull Locale inputLocale) {
7730 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
7731 getDefaultPhone().getContext());
7732 for (String localeTag : supportedLocale) {
7733 if (LocaleList.matchesLanguageAndScript(
7734 inputLocale, Locale.forLanguageTag(localeTag))
7735 && inputLocale.getCountry().equals(
7736 Locale.forLanguageTag(localeTag).getCountry())) {
7737 return localeTag;
7738 }
7739 }
7740 return inputLocale.toLanguageTag();
7741 }
7742
Narayan Kamath1c496c22015-04-16 14:40:19 +01007743 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007744 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007745 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007746 }
7747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007748 /**
7749 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7750 */
7751 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007752 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007753 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007754 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007755
Gary Jian3aa9a762022-01-24 16:41:19 +08007756 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7757 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007758
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007759 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007760 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7761 * representing the state of the modem.
7762 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007763 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7764 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007765 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007766 */
7767 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007768 public void requestModemActivityInfo(ResultReceiver result) {
7769 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007770 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007771
7772 final long identity = Binder.clearCallingIdentity();
7773 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007774 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007775 } finally {
7776 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007777 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007778 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007779
Siddharth Rayb8114062018-06-17 15:02:38 -07007780 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7781 // less than total activity duration.
7782 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7783 if (info == null) {
7784 return false;
7785 }
7786 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007787 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7788 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7789
Siddharth Rayb8114062018-06-17 15:02:38 -07007790 return (info.isValid()
7791 && (info.getSleepTimeMillis() <= activityDurationMs)
7792 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007793 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007794 && (totalTxTimeMs <= activityDurationMs));
7795 }
7796
Gary Jian3aa9a762022-01-24 16:41:19 +08007797 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7798 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7799 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7800 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7801
7802 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7803 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7804 }
7805
7806 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7807 mLastModemActivityInfo.setReceiveTimeMillis(
7808 rat,
7809 freq,
7810 info.getReceiveTimeMillis(rat, freq)
7811 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7812 }
7813
7814 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7815 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7816 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7817 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7818
7819 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7820 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7821 }
7822 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7823 mLastModemActivityInfo.setReceiveTimeMillis(
7824 rat,
7825 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7826 }
7827
7828 /**
7829 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7830 * @param info recent ModemActivityInfo
7831 */
7832 private void mergeModemActivityInfo(ModemActivityInfo info) {
7833 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08007834 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08007835 boolean matched;
7836 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7837 matched = false;
7838 int rat = info.getSpecificInfoRat(i);
7839 int freq = info.getSpecificInfoFrequencyRange(i);
7840 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7841 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7842 //if it already exists
7843 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7844 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7845 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7846 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7847 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7848 updateLastModemActivityInfo(info, rat, freq);
7849 matched = true;
7850 }
7851 } else {
7852 updateLastModemActivityInfo(info, rat);
7853 matched = true;
7854 }
7855 }
7856 }
7857
7858 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08007859 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08007860 new ActivityStatsTechSpecificInfo(
7861 rat,
7862 freq,
7863 info.getTransmitTimeMillis(rat, freq),
7864 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08007865 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08007866 }
7867 }
7868 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7869 mLastModemActivitySpecificInfo =
7870 new ActivityStatsTechSpecificInfo[merged.size()];
7871 merged.toArray(mLastModemActivitySpecificInfo);
7872
7873 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7874 mLastModemActivityInfo.setSleepTimeMillis(
7875 info.getSleepTimeMillis()
7876 + mLastModemActivityInfo.getSleepTimeMillis());
7877 mLastModemActivityInfo.setIdleTimeMillis(
7878 info.getIdleTimeMillis()
7879 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08007880
7881 mLastModemActivityInfo =
7882 new ModemActivityInfo(
7883 mLastModemActivityInfo.getTimestampMillis(),
7884 mLastModemActivityInfo.getSleepTimeMillis(),
7885 mLastModemActivityInfo.getIdleTimeMillis(),
7886 mLastModemActivitySpecificInfo);
7887 }
7888
7889 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
7890 ActivityStatsTechSpecificInfo[] info) {
7891 int infoSize = info.length;
7892 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
7893 for (int i = 0; i < infoSize; i++) {
7894 ret[i] = new ActivityStatsTechSpecificInfo(
7895 info[i].getRat(), info[i].getFrequencyRange(),
7896 info[i].getTransmitTimeMillis(),
7897 (int) info[i].getReceiveTimeMillis());
7898 }
7899 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08007900 }
7901
Jack Yu85bd38a2015-11-09 11:34:32 -08007902 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007903 * Returns the service state information on specified subscription.
7904 */
7905 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007906 public ServiceState getServiceStateForSubscriber(int subId,
7907 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7908 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007909 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007910 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007911 return null;
7912 }
7913
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007914 boolean hasFinePermission = false;
7915 boolean hasCoarsePermission = false;
7916 if (!renounceFineLocationAccess) {
7917 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7918 LocationAccessPolicy.checkLocationPermission(mApp,
7919 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7920 .setCallingPackage(callingPackage)
7921 .setCallingFeatureId(callingFeatureId)
7922 .setCallingPid(Binder.getCallingPid())
7923 .setCallingUid(Binder.getCallingUid())
7924 .setMethod("getServiceStateForSubscriber")
7925 .setLogAsInfo(true)
7926 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7927 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7928 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7929 .build());
7930 hasFinePermission =
7931 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7932 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007933
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007934 if (!renounceCoarseLocationAccess) {
7935 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7936 LocationAccessPolicy.checkLocationPermission(mApp,
7937 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7938 .setCallingPackage(callingPackage)
7939 .setCallingFeatureId(callingFeatureId)
7940 .setCallingPid(Binder.getCallingPid())
7941 .setCallingUid(Binder.getCallingUid())
7942 .setMethod("getServiceStateForSubscriber")
7943 .setLogAsInfo(true)
7944 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7945 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7946 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7947 .build());
7948 hasCoarsePermission =
7949 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7950 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007951
Jack Yu479f40e2020-10-27 21:29:25 -07007952 final Phone phone = getPhone(subId);
7953 if (phone == null) {
7954 return null;
7955 }
7956
Jordan Liu0f2bc442020-11-18 16:47:37 -08007957 final long identity = Binder.clearCallingIdentity();
7958
Jack Yu479f40e2020-10-27 21:29:25 -07007959 boolean isCallingPackageDataService = phone.getDataServicePackages()
7960 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007962 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7963 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7964 Rlog.d(LOG_TAG,
7965 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7966 return null;
7967 }
7968
Hall Liuf19c44f2018-11-27 14:38:17 -08007969 ServiceState ss = phone.getServiceState();
7970
7971 // Scrub out the location info in ServiceState depending on what level of access
7972 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007973 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007974 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7975 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007976 } finally {
7977 Binder.restoreCallingIdentity(identity);
7978 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007979 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007980
7981 /**
7982 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7983 *
7984 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7985 * voicemail ringtone.
7986 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7987 * PhoneAccount.
7988 */
7989 @Override
7990 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007991 final long identity = Binder.clearCallingIdentity();
7992 try {
7993 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7994 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007995 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007997
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007998 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7999 } finally {
8000 Binder.restoreCallingIdentity(identity);
8001 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008002 }
8003
8004 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008005 * Sets the per-account voicemail ringtone.
8006 *
8007 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8008 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8009 *
8010 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8011 * voicemail ringtone.
8012 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8013 * PhoneAccount.
8014 */
8015 @Override
8016 public void setVoicemailRingtoneUri(String callingPackage,
8017 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008018 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008019 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008020 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8021 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8023 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8024 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008025 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026
8027 final long identity = Binder.clearCallingIdentity();
8028 try {
8029 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8030 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008031 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008032 }
8033 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8034 } finally {
8035 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008036 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008037 }
8038
8039 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008040 * Returns whether vibration is set for voicemail notification in Phone settings.
8041 *
8042 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8043 * voicemail vibration setting.
8044 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8045 */
8046 @Override
8047 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008048 final long identity = Binder.clearCallingIdentity();
8049 try {
8050 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8051 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008052 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008053 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8056 } finally {
8057 Binder.restoreCallingIdentity(identity);
8058 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008059 }
8060
Youhan Wange64578a2016-05-02 15:32:42 -07008061 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008062 * Sets the per-account voicemail vibration.
8063 *
8064 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8065 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8066 *
8067 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8068 * voicemail vibration setting.
8069 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8070 * specific PhoneAccount.
8071 */
8072 @Override
8073 public void setVoicemailVibrationEnabled(String callingPackage,
8074 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008075 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008076 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008077 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8078 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8080 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8081 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008082 }
8083
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008084 final long identity = Binder.clearCallingIdentity();
8085 try {
8086 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8087 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008088 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008089 }
8090 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8091 } finally {
8092 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008093 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008094 }
8095
8096 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008097 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8098 *
8099 * @throws SecurityException if the caller does not have the required permission
8100 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008101 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008102 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008103 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008104 }
8105
8106 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008107 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8108 * permission.
8109 *
8110 * @throws SecurityException if the caller does not have the required permission
8111 */
8112 private void enforceSendSmsPermission() {
8113 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8114 }
8115
8116 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008117 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008118 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008119 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008120 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008121 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008122 final long identity = Binder.clearCallingIdentity();
8123 try {
8124 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008125 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008126 if (componentName == null) {
8127 throw new SecurityException(
8128 "Caller not current active visual voicemail package[null]");
8129 }
8130 String vvmPackage = componentName.getPackageName();
8131 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008132 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133 }
8134 } finally {
8135 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008136 }
8137 }
8138
8139 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008140 * Return the application ID for the app type.
8141 *
8142 * @param subId the subscription ID that this request applies to.
8143 * @param appType the uicc app type.
8144 * @return Application ID for specificied app type, or null if no uicc.
8145 */
8146 @Override
8147 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008148 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008149 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008150
8151 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008152 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153 if (phone == null) {
8154 return null;
8155 }
8156 String aid = null;
8157 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008158 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008159 .getApplicationByType(appType).getAid();
8160 } catch (Exception e) {
8161 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8162 }
8163 return aid;
8164 } finally {
8165 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008166 }
Youhan Wange64578a2016-05-02 15:32:42 -07008167 }
8168
Youhan Wang4001d252016-05-11 10:29:41 -07008169 /**
8170 * Return the Electronic Serial Number.
8171 *
8172 * @param subId the subscription ID that this request applies to.
8173 * @return ESN or null if error.
8174 */
8175 @Override
8176 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008177 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008178 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008179
8180 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008181 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008182 if (phone == null) {
8183 return null;
8184 }
8185 String esn = null;
8186 try {
8187 esn = phone.getEsn();
8188 } catch (Exception e) {
8189 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8190 }
8191 return esn;
8192 } finally {
8193 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008194 }
Youhan Wang4001d252016-05-11 10:29:41 -07008195 }
8196
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008197 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008198 * Return the Preferred Roaming List Version.
8199 *
8200 * @param subId the subscription ID that this request applies to.
8201 * @return PRLVersion or null if error.
8202 */
8203 @Override
8204 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008205 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008206 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008207
8208 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008209 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008210 if (phone == null) {
8211 return null;
8212 }
8213 String cdmaPrlVersion = null;
8214 try {
8215 cdmaPrlVersion = phone.getCdmaPrlVersion();
8216 } catch (Exception e) {
8217 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8218 }
8219 return cdmaPrlVersion;
8220 } finally {
8221 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008222 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008223 }
8224
8225 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008226 * Get snapshot of Telephony histograms
8227 * @return List of Telephony histograms
8228 * @hide
8229 */
8230 @Override
8231 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8233 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008234
8235 final long identity = Binder.clearCallingIdentity();
8236 try {
8237 return RIL.getTelephonyRILTimingHistograms();
8238 } finally {
8239 Binder.restoreCallingIdentity(identity);
8240 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008241 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008242
8243 /**
8244 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008245 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8246 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008247 * Require system privileges. In the future we may add this to carrier APIs.
8248 *
Michele Berionne482f8202018-11-27 18:57:59 -08008249 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008250 */
8251 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008252 @TelephonyManager.SetCarrierRestrictionResult
8253 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008254 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008255 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008256
Michele Berionne482f8202018-11-27 18:57:59 -08008257 if (carrierRestrictionRules == null) {
8258 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008259 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008261 final long identity = Binder.clearCallingIdentity();
8262 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008263 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008264 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008265 } finally {
8266 Binder.restoreCallingIdentity(identity);
8267 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008268 }
8269
8270 /**
8271 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008272 * Get the allowed carrier list and the excluded carrier list, including the priority between
8273 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008274 * Require system privileges. In the future we may add this to carrier APIs.
8275 *
Michele Berionne482f8202018-11-27 18:57:59 -08008276 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008277 */
8278 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008279 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008280 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008281 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008282
8283 final long identity = Binder.clearCallingIdentity();
8284 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008285 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8286 if (response instanceof CarrierRestrictionRules) {
8287 return (CarrierRestrictionRules) response;
8288 }
8289 // Response is an Exception of some kind,
8290 // which is signalled to the user as a NULL retval
8291 return null;
8292 } catch (Exception e) {
8293 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8294 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008295 } finally {
8296 Binder.restoreCallingIdentity(identity);
8297 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008298 }
8299
fionaxu59545b42016-05-25 15:53:37 -07008300 /**
fionaxu59545b42016-05-25 15:53:37 -07008301 * Action set from carrier signalling broadcast receivers to enable/disable radio
8302 * @param subId the subscription ID that this action applies to.
8303 * @param enabled control enable or disable radio.
8304 * {@hide}
8305 */
8306 @Override
8307 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8308 enforceModifyPermission();
8309 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008310
8311 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008312 if (phone == null) {
8313 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8314 return;
8315 }
8316 try {
8317 phone.carrierActionSetRadioEnabled(enabled);
8318 } catch (Exception e) {
8319 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008320 } finally {
8321 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008322 }
8323 }
8324
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008325 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008326 * Enable or disable Voice over NR (VoNR)
8327 * @param subId the subscription ID that this action applies to.
8328 * @param enabled enable or disable VoNR.
8329 * @return operation result.
8330 */
8331 @Override
8332 public int setVoNrEnabled(int subId, boolean enabled) {
8333 enforceModifyPermission();
8334 final Phone phone = getPhone(subId);
8335
8336 final long identity = Binder.clearCallingIdentity();
8337 if (phone == null) {
8338 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8339 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8340 }
8341
8342 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8343 try {
8344 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8345 workSource);
8346 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008347
8348 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8349 if (DBG) {
8350 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8351 }
8352 SubscriptionManager.setSubscriptionProperty(
8353 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8354 (enabled ? "1" : "0"));
8355 }
8356
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008357 return result;
8358 } finally {
8359 Binder.restoreCallingIdentity(identity);
8360 }
8361 }
8362
8363 /**
8364 * Is voice over NR enabled
8365 * @return true if VoNR is enabled else false
8366 */
8367 @Override
8368 public boolean isVoNrEnabled(int subId) {
8369 enforceReadPrivilegedPermission("isVoNrEnabled");
8370 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8371 final long identity = Binder.clearCallingIdentity();
8372 try {
8373 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8374 null, subId, workSource);
8375 if (DBG) log("isVoNrEnabled: " + isEnabled);
8376 return isEnabled;
8377 } finally {
8378 Binder.restoreCallingIdentity(identity);
8379 }
8380 }
8381
8382 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008383 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8384 * network status based on which carrier apps could apply actions accordingly,
8385 * enable/disable default url handler for example.
8386 *
8387 * @param subId the subscription ID that this action applies to.
8388 * @param report control start/stop reporting the default network status.
8389 * {@hide}
8390 */
8391 @Override
8392 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8393 enforceModifyPermission();
8394 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008395
8396 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008397 if (phone == null) {
8398 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8399 return;
8400 }
8401 try {
8402 phone.carrierActionReportDefaultNetworkStatus(report);
8403 } catch (Exception e) {
8404 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008405 } finally {
8406 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008407 }
8408 }
8409
8410 /**
fionaxud9622282017-07-17 17:51:30 -07008411 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8412 * @param subId the subscription ID that this action applies to.
8413 * {@hide}
8414 */
8415 @Override
8416 public void carrierActionResetAll(int subId) {
8417 enforceModifyPermission();
8418 final Phone phone = getPhone(subId);
8419 if (phone == null) {
8420 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8421 return;
8422 }
8423 try {
8424 phone.carrierActionResetAll();
8425 } catch (Exception e) {
8426 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8427 }
8428 }
8429
8430 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008431 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8432 * bug report is being generated.
8433 */
8434 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008435 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008436 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8437 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008438 writer.println("Permission Denial: can't dump Phone from pid="
8439 + Binder.getCallingPid()
8440 + ", uid=" + Binder.getCallingUid()
8441 + "without permission "
8442 + android.Manifest.permission.DUMP);
8443 return;
8444 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008445 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008446 }
Jack Yueb89b242016-06-22 13:27:47 -07008447
Brad Ebingerdac2f002018-04-03 15:17:52 -07008448 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008449 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8450 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8451 @NonNull String[] args) {
8452 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8453 this, in.getFileDescriptor(), out.getFileDescriptor(),
8454 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008455 }
8456
Jack Yueb89b242016-06-22 13:27:47 -07008457 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008458 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008459 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008460 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008461 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008462 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008463 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008464 */
8465 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008466 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008467 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008468 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8469 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8470 try {
8471 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008472 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008473 } catch (SecurityException se) {
8474 enforceModifyPermission();
8475 }
8476 } else {
8477 enforceModifyPermission();
8478 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008479
8480 final long identity = Binder.clearCallingIdentity();
8481 try {
8482 Phone phone = getPhone(subId);
8483 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008484 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8485 phone.carrierActionSetMeteredApnsEnabled(enabled);
8486 } else {
Jack Yud7b8d372022-07-31 00:43:21 -07008487 phone.getDataSettingsManager().setDataEnabled(
8488 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008490 }
8491 } finally {
8492 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008493 }
8494 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008495
8496 /**
8497 * Get Client request stats
8498 * @return List of Client Request Stats
8499 * @hide
8500 */
8501 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008502 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8503 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008504 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008505 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008506 return null;
8507 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008508 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008510 final long identity = Binder.clearCallingIdentity();
8511 try {
8512 if (phone != null) {
8513 return phone.getClientRequestStats();
8514 }
8515
8516 return null;
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
8519 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008520 }
8521
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008522 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008523 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008524 if (uid == Process.ROOT_UID && packageName == null) {
8525 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8526 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8527 // exception. ROOT_UID seems not to have a valid package name returned by
8528 // PackageManager, so just fake it here to avoid issues when running telephony shell
8529 // commands that plumb through the RIL as root, like so:
8530 // $ adb root
8531 // $ adb shell cmd phone ...
8532 packageName = "root";
8533 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008534 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008535 }
Jack Yueb4124c2017-02-16 15:32:43 -08008536
8537 /**
Grace Chen70990072017-03-24 17:21:30 -07008538 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008539 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008540 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008541 * @param state State of SIM (power down, power up, pass through)
8542 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8543 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8544 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008545 *
8546 **/
8547 @Override
Grace Chen70990072017-03-24 17:21:30 -07008548 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008549 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008550 Phone phone = PhoneFactory.getPhone(slotIndex);
8551
vagdeviaf9a5b92018-08-15 16:01:53 -07008552 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008554 final long identity = Binder.clearCallingIdentity();
8555 try {
8556 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008557 phone.setSimPowerState(state, null, workSource);
8558 }
8559 } finally {
8560 Binder.restoreCallingIdentity(identity);
8561 }
8562 }
8563
8564 /**
8565 * Set SIM card power state.
8566 *
8567 * @param slotIndex SIM slot id.
8568 * @param state State of SIM (power down, power up, pass through)
8569 * @param callback callback to trigger after success or failure
8570 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8571 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8572 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8573 *
8574 **/
8575 @Override
8576 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8577 IIntegerConsumer callback) {
8578 enforceModifyPermission();
8579 Phone phone = PhoneFactory.getPhone(slotIndex);
8580
8581 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8582
8583 final long identity = Binder.clearCallingIdentity();
8584 try {
8585 if (phone != null) {
8586 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8587 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008588 }
8589 } finally {
8590 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008591 }
8592 }
Shuo Qiandd210312017-04-12 22:11:33 +00008593
Tyler Gunn65d45c22017-06-05 11:22:26 -07008594 private boolean isUssdApiAllowed(int subId) {
8595 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008596 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008597 if (configManager == null) {
8598 return false;
8599 }
8600 PersistableBundle pb = configManager.getConfigForSubId(subId);
8601 if (pb == null) {
8602 return false;
8603 }
8604 return pb.getBoolean(
8605 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8606 }
8607
Shuo Qiandd210312017-04-12 22:11:33 +00008608 /**
8609 * Check if phone is in emergency callback mode
8610 * @return true if phone is in emergency callback mode
8611 * @param subId sub id
8612 */
goneil9c5f4872017-12-05 14:07:56 -08008613 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008614 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008615 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008616 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008617
8618 final long identity = Binder.clearCallingIdentity();
8619 try {
8620 if (phone != null) {
8621 return phone.isInEcm();
8622 } else {
8623 return false;
8624 }
8625 } finally {
8626 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008627 }
8628 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008629
8630 /**
8631 * Get the current signal strength information for the given subscription.
8632 * Because this information is not updated when the device is in a low power state
8633 * it should not be relied-upon to be current.
8634 * @param subId Subscription index
8635 * @return the most recent cached signal strength info from the modem
8636 */
8637 @Override
8638 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008639 final long identity = Binder.clearCallingIdentity();
8640 try {
8641 Phone p = getPhone(subId);
8642 if (p == null) {
8643 return null;
8644 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008646 return p.getSignalStrength();
8647 } finally {
8648 Binder.restoreCallingIdentity(identity);
8649 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008650 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008651
Pengquan Meng77b7f132018-08-22 14:49:57 -07008652 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008653 * Get the current modem radio state for the given slot.
8654 * @param slotIndex slot index.
8655 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008656 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008657 * @return the current radio power state from the modem
8658 */
8659 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008660 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008661 Phone phone = PhoneFactory.getPhone(slotIndex);
8662 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008663 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8664 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008665 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8666 }
8667
8668 final long identity = Binder.clearCallingIdentity();
8669 try {
8670 return phone.getRadioPowerState();
8671 } finally {
8672 Binder.restoreCallingIdentity(identity);
8673 }
8674 }
8675 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8676 }
8677
8678 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008679 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8680 *
8681 * <p>Requires one of the following permissions:
8682 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008683 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008684 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8685 * privileges.
8686 *
8687 * @param subId subscription id
8688 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8689 * {@code false}.
8690 */
8691 @Override
8692 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008693 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008694 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008695 try {
8696 mApp.enforceCallingOrSelfPermission(
8697 android.Manifest.permission.ACCESS_NETWORK_STATE,
8698 functionName);
8699 } catch (Exception e) {
8700 mApp.enforceCallingOrSelfPermission(
8701 permission.READ_BASIC_PHONE_STATE, functionName);
8702 }
Shuo Qian093013d2020-08-13 15:42:55 -07008703 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008704 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008705 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008706 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008707
Pengquan Menga1bb6272018-09-06 09:59:22 -07008708 boolean isEnabled = false;
8709 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008710 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008711 Phone phone = getPhone(subId);
8712 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008713 } finally {
8714 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008716 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008717 }
8718
8719
8720 /**
8721 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8722 *
8723 * <p> Requires permission:
8724 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8725 * privileges.
8726 *
8727 * @param subId subscription id
8728 * @param isEnabled {@code true} means enable, {@code false} means disable.
8729 */
8730 @Override
8731 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8733 mApp, subId, "setDataRoamingEnabled");
8734
Pengquan Menga1bb6272018-09-06 09:59:22 -07008735 final long identity = Binder.clearCallingIdentity();
8736 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008737 Phone phone = getPhone(subId);
8738 if (phone != null) {
8739 phone.setDataRoamingEnabled(isEnabled);
8740 }
8741 } finally {
8742 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008743 }
8744 }
8745
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008746 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008747 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008748 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008749 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008750 mApp, subId, "isManualNetworkSelectionAllowed");
8751
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008752 boolean isAllowed = true;
8753 final long identity = Binder.clearCallingIdentity();
8754 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008755 Phone phone = getPhone(subId);
8756 if (phone != null) {
8757 isAllowed = phone.isCspPlmnEnabled();
8758 }
8759 } finally {
8760 Binder.restoreCallingIdentity(identity);
8761 }
8762 return isAllowed;
8763 }
8764
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008765 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8766 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008767 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008768 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008769 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008770 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8771 if (phone == null) {
8772 return false;
8773 }
8774 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8775 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8776 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008777 }
8778
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008779 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008780 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008781 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008782 mApp.getSystemService(AppOpsManager.class)
8783 .checkPackage(Binder.getCallingUid(), callingPackage);
8784
Jordan Liu1e142fc2019-04-22 15:10:43 -07008785 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008786 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008787 try {
8788 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008789 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008790 } catch (SecurityException e) {
8791 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8792 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008793 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008794 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008795 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008796 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008797 }
sandeepjsb6c87872021-09-27 15:34:44 +00008798 // checking compatibility, if calling app's target SDK is T and beyond.
8799 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8800 Binder.getCallingUid())) {
8801 isIccIdAccessRestricted = true;
8802 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008803 final long identity = Binder.clearCallingIdentity();
8804 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008805 UiccController uiccController = UiccController.getInstance();
8806 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008807 if (hasReadPermission) {
8808 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008809 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008810
8811 // Remove private info if the caller doesn't have access
8812 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8813 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008814 //setting the value after compatibility check
8815 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008816 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8817 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008818 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008819 if (card == null) {
8820 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008821 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008822 continue;
8823 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008824 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8825 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008826 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008827 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008828 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008829 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8830 for (UiccPortInfo portInfo : portInfos) {
8831 UiccPort port = uiccController.getUiccPortForSlot(
8832 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8833 if (port == null) {
8834 // assume no access if port is null
8835 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8836 continue;
8837 }
8838 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8839 uiccPortInfos.add(portInfo);
8840 } else {
8841 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8842 }
8843 }
8844 filteredInfos.add(new UiccCardInfo(
8845 cardInfo.isEuicc(),
8846 cardInfo.getCardId(),
8847 null,
8848 cardInfo.getPhysicalSlotIndex(),
8849 cardInfo.isRemovable(),
8850 cardInfo.isMultipleEnabledProfilesSupported(),
8851 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008852 }
8853 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008854 } finally {
8855 Binder.restoreCallingIdentity(identity);
8856 }
8857 }
8858
sandeepjsb6c87872021-09-27 15:34:44 +00008859 /**
8860 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8861 * generally private and require carrier privileges to view.
8862 *
8863 * @hide
8864 */
8865 @NonNull
8866 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8867 List<UiccPortInfo> portinfo = new ArrayList<>();
8868 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8869 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8870 }
8871 return new UiccCardInfo(
8872 cardInfo.isEuicc(),
8873 cardInfo.getCardId(),
8874 null,
8875 cardInfo.getPhysicalSlotIndex(),
8876 cardInfo.isRemovable(),
8877 cardInfo.isMultipleEnabledProfilesSupported(),
8878 portinfo
8879 );
8880 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008881
sandeepjsb6c87872021-09-27 15:34:44 +00008882 /**
8883 * @hide
8884 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8885 * These values are generally private and require carrier privileges to view.
8886 */
8887 @NonNull
8888 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8889 return new UiccPortInfo(
8890 UiccPortInfo.ICCID_REDACTED,
8891 portInfo.getPortIndex(),
8892 portInfo.getLogicalSlotIndex(),
8893 portInfo.isActive()
8894 );
8895 }
8896 @Override
8897 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008898 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008899 mApp.getSystemService(AppOpsManager.class)
8900 .checkPackage(Binder.getCallingUid(), callingPackage);
8901
sandeepjsb6c87872021-09-27 15:34:44 +00008902 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008903
Aman Guptaf3c90b32022-03-17 04:54:16 +00008904 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8905 // we are reading iccId which is PII data.
8906 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008907
8908 // checking compatibility, if calling app's target SDK is T and beyond.
8909 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8910 Binder.getCallingUid())) {
8911 isLogicalSlotAccessRestricted = true;
8912 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008913 final long identity = Binder.clearCallingIdentity();
8914 try {
8915 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008916 if (slots == null || slots.length == 0) {
8917 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008918 return null;
8919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008920 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8921 for (int i = 0; i < slots.length; i++) {
8922 UiccSlot slot = slots[i];
8923 if (slot == null) {
8924 continue;
8925 }
8926
Jordan Liu7be7e652019-05-06 18:55:02 +00008927 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008928 UiccCard card = slot.getUiccCard();
8929 if (card != null) {
8930 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008931 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008932 cardId = slot.getEid();
8933 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00008934 // If cardId is null, use iccId of default port as cardId.
8935 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07008936 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008937 }
8938
Jordan Liu857451f2019-05-09 16:35:35 -07008939 if (cardId != null) {
8940 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8941 // if cardId is an EID, it's all digits so this is fine
8942 cardId = IccUtils.stripTrailingFs(cardId);
8943 }
8944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008945 int cardState = 0;
8946 switch (slot.getCardState()) {
8947 case CARDSTATE_ABSENT:
8948 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8949 break;
8950 case CARDSTATE_PRESENT:
8951 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8952 break;
8953 case CARDSTATE_ERROR:
8954 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8955 break;
8956 case CARDSTATE_RESTRICTED:
8957 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8958 break;
8959 default:
8960 break;
8961
8962 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008963 List<UiccPortInfo> portInfos = new ArrayList<>();
8964 int[] portIndexes = slot.getPortList();
8965 for (int portIdx : portIndexes) {
8966 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00008967 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008968 portInfos.add(new UiccPortInfo(iccId, portIdx,
8969 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008971 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008972 slot.isEuicc(),
8973 cardId,
8974 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008975 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008976 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008977 //setting the value after compatibility check
8978 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008979 }
8980 return infos;
8981 } finally {
8982 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008983 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008984 }
8985
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008986 /* Returns null if doesn't have read permission or carrier privilege access. */
8987 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8988 boolean hasReadPermission) {
8989 String iccId = slot.getIccId(portIndex);
8990 if (hasReadPermission) { // if has read permission
8991 return iccId;
8992 } else {
8993 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8994 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8995 // if no read permission, checking carrier privilege access
8996 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8997 return iccId;
8998 }
8999 }
9000 }
9001 // No read permission or carrier privilege access.
9002 return UiccPortInfo.ICCID_REDACTED;
9003 }
9004
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009005 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009006 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009007 public boolean switchSlots(int[] physicalSlots) {
9008 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009009
9010 final long identity = Binder.clearCallingIdentity();
9011 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009012 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9013 for (int i = 0; i < physicalSlots.length; i++) {
9014 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9015 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9016 physicalSlots[i], i));
9017 }
9018 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009019 } finally {
9020 Binder.restoreCallingIdentity(identity);
9021 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009022 }
Jack Yu4c988042018-02-27 15:30:01 -08009023
9024 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009025 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9026 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9027 enforceModifyPermission();
9028
9029 final long identity = Binder.clearCallingIdentity();
9030 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009031 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009032 } finally {
9033 Binder.restoreCallingIdentity(identity);
9034 }
9035 }
9036
9037 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009038 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009039 final long identity = Binder.clearCallingIdentity();
9040 try {
9041 return UiccController.getInstance().getCardIdForDefaultEuicc();
9042 } finally {
9043 Binder.restoreCallingIdentity(identity);
9044 }
9045 }
9046
Pengquan Meng85728fb2018-03-12 16:31:21 -07009047 /**
goneil47ffb6e2018-04-06 15:40:58 -07009048 * A test API to reload the UICC profile.
9049 *
9050 * <p>Requires that the calling app has permission
9051 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9052 * @hide
9053 */
9054 @Override
9055 public void refreshUiccProfile(int subId) {
9056 enforceModifyPermission();
9057
9058 final long identity = Binder.clearCallingIdentity();
9059 try {
9060 Phone phone = getPhone(subId);
9061 if (phone == null) {
9062 return;
9063 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009064 UiccPort uiccPort = phone.getUiccPort();
9065 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009066 return;
9067 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009068 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009069 if (uiccProfile == null) {
9070 return;
9071 }
9072 uiccProfile.refresh();
9073 } finally {
9074 Binder.restoreCallingIdentity(identity);
9075 }
9076 }
9077
9078 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009079 * Returns false if the mobile data is disabled by default, otherwise return true.
9080 */
9081 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009082 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009083 }
9084
9085 /**
9086 * Returns true if the data roaming is enabled by default, i.e the system property
9087 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9088 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9089 */
9090 private boolean getDefaultDataRoamingEnabled(int subId) {
9091 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009092 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009093 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009094 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9095 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9096 return isDataRoamingEnabled;
9097 }
9098
9099 /**
9100 * Returns the default network type for the given {@code subId}, if the default network type is
9101 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9102 */
9103 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009104 List<Integer> list = TelephonyProperties.default_network();
9105 int phoneId = mSubscriptionController.getPhoneId(subId);
9106 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9107 return list.get(phoneId);
9108 }
9109 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009110 }
fionaxua13278b2018-03-21 00:08:13 -07009111
9112 @Override
9113 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009114 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009115 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009116
9117 final long identity = Binder.clearCallingIdentity();
9118 try {
9119 final Phone phone = getPhone(subId);
9120 if (phone == null) {
9121 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9122 return;
9123 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009124 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9125 if (cpt != null) {
9126 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9127 }
9128 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009129 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9130 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009131 if (carrierPrivilegeRules == null) {
9132 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9133 } else {
9134 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9135 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009136 } finally {
9137 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009138 }
fionaxua13278b2018-03-21 00:08:13 -07009139 }
9140
9141 @Override
9142 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009143 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009144
9145 final long identity = Binder.clearCallingIdentity();
9146 try {
9147 final Phone phone = getPhone(subId);
9148 if (phone == null) {
9149 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9150 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9151 }
9152 return phone.getCarrierIdListVersion();
9153 } finally {
9154 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009155 }
fionaxua13278b2018-03-21 00:08:13 -07009156 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009157
9158 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009159 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9160 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009162 mApp, subId, callingPackage, callingFeatureId,
9163 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009164 return -1;
9165 }
9166
9167 final long identity = Binder.clearCallingIdentity();
9168 try {
9169 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9170 } finally {
9171 Binder.restoreCallingIdentity(identity);
9172 }
9173 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009174
9175 @Override
9176 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009177 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009178 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009179 mApp, subId, "getCdmaRoamingMode");
9180
9181 final long identity = Binder.clearCallingIdentity();
9182 try {
9183 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9184 } finally {
9185 Binder.restoreCallingIdentity(identity);
9186 }
9187 }
9188
9189 @Override
9190 public boolean setCdmaRoamingMode(int subId, int mode) {
9191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9192 mApp, subId, "setCdmaRoamingMode");
9193
9194 final long identity = Binder.clearCallingIdentity();
9195 try {
9196 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9197 } finally {
9198 Binder.restoreCallingIdentity(identity);
9199 }
9200 }
9201
9202 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009203 public int getCdmaSubscriptionMode(int subId) {
9204 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009205 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009206 mApp, subId, "getCdmaSubscriptionMode");
9207
9208 final long identity = Binder.clearCallingIdentity();
9209 try {
9210 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9211 } finally {
9212 Binder.restoreCallingIdentity(identity);
9213 }
9214 }
9215
9216 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009217 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9219 mApp, subId, "setCdmaSubscriptionMode");
9220
9221 final long identity = Binder.clearCallingIdentity();
9222 try {
9223 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9224 } finally {
9225 Binder.restoreCallingIdentity(identity);
9226 }
9227 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009228
sqianc5eccab2018-10-19 18:46:41 -07009229 @Override
sqian8c685422019-02-22 15:55:18 -08009230 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009231 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009233 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9234 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009235 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9236 }
9237 final long identity = Binder.clearCallingIdentity();
9238 try {
sqian854d44b2018-12-12 16:48:18 -08009239 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9240 for (Phone phone: PhoneFactory.getPhones()) {
9241 if (phone.getEmergencyNumberTracker() != null
9242 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9243 emergencyNumberListInternal.put(
9244 phone.getSubId(),
9245 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9246 }
sqian11b7a0e2018-12-05 18:48:28 -08009247 }
sqian854d44b2018-12-12 16:48:18 -08009248 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009249 } finally {
9250 Binder.restoreCallingIdentity(identity);
9251 }
sqianc5eccab2018-10-19 18:46:41 -07009252 }
9253
9254 @Override
sqian8c685422019-02-22 15:55:18 -08009255 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009256 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009257 if (!exactMatch) {
9258 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009259 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009260 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009261 }
9262 final long identity = Binder.clearCallingIdentity();
9263 try {
sqian854d44b2018-12-12 16:48:18 -08009264 for (Phone phone: PhoneFactory.getPhones()) {
9265 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009266 && phone.getEmergencyNumberTracker()
9267 .isEmergencyNumber(number, exactMatch)) {
9268 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009269 }
sqian11b7a0e2018-12-05 18:48:28 -08009270 }
9271 return false;
9272 } finally {
9273 Binder.restoreCallingIdentity(identity);
9274 }
9275 }
9276
sqianf4ca7ed2019-01-15 18:32:07 -08009277 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009278 * Start emergency callback mode for GsmCdmaPhone for testing.
9279 */
9280 @Override
9281 public void startEmergencyCallbackMode() {
9282 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9283 "startEmergencyCallbackMode");
9284 enforceModifyPermission();
9285 final long identity = Binder.clearCallingIdentity();
9286 try {
9287 for (Phone phone : PhoneFactory.getPhones()) {
9288 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9289 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9290 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9291 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9292 gsmCdmaPhone.obtainMessage(
9293 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9294 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9295 }
9296 }
9297 } finally {
9298 Binder.restoreCallingIdentity(identity);
9299 }
9300 }
9301
9302 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009303 * Update emergency number list for test mode.
9304 */
9305 @Override
9306 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9307 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9308 "updateEmergencyNumberListTestMode");
9309
9310 final long identity = Binder.clearCallingIdentity();
9311 try {
9312 for (Phone phone: PhoneFactory.getPhones()) {
9313 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9314 if (tracker != null) {
9315 tracker.executeEmergencyNumberTestModeCommand(action, num);
9316 }
9317 }
9318 } finally {
9319 Binder.restoreCallingIdentity(identity);
9320 }
9321 }
9322
9323 /**
9324 * Get the full emergency number list for test mode.
9325 */
9326 @Override
9327 public List<String> getEmergencyNumberListTestMode() {
9328 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9329 "getEmergencyNumberListTestMode");
9330
9331 final long identity = Binder.clearCallingIdentity();
9332 try {
9333 Set<String> emergencyNumbers = new HashSet<>();
9334 for (Phone phone: PhoneFactory.getPhones()) {
9335 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9336 if (tracker != null) {
9337 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9338 emergencyNumbers.add(num.getNumber());
9339 }
9340 }
9341 }
9342 return new ArrayList<>(emergencyNumbers);
9343 } finally {
9344 Binder.restoreCallingIdentity(identity);
9345 }
9346 }
9347
chen xud6b45bd2018-10-30 22:27:10 -07009348 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009349 public int getEmergencyNumberDbVersion(int subId) {
9350 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9351
9352 final long identity = Binder.clearCallingIdentity();
9353 try {
9354 final Phone phone = getPhone(subId);
9355 if (phone == null) {
9356 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9357 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9358 }
9359 return phone.getEmergencyNumberDbVersion();
9360 } finally {
9361 Binder.restoreCallingIdentity(identity);
9362 }
9363 }
9364
9365 @Override
9366 public void notifyOtaEmergencyNumberDbInstalled() {
9367 enforceModifyPermission();
9368
9369 final long identity = Binder.clearCallingIdentity();
9370 try {
9371 for (Phone phone: PhoneFactory.getPhones()) {
9372 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9373 if (tracker != null) {
9374 tracker.updateOtaEmergencyNumberDatabase();
9375 }
9376 }
9377 } finally {
9378 Binder.restoreCallingIdentity(identity);
9379 }
9380 }
9381
9382 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009383 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009384 enforceActiveEmergencySessionPermission();
9385
9386 final long identity = Binder.clearCallingIdentity();
9387 try {
9388 for (Phone phone: PhoneFactory.getPhones()) {
9389 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9390 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009391 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9392 }
9393 }
9394 } finally {
9395 Binder.restoreCallingIdentity(identity);
9396 }
9397 }
9398
9399 @Override
9400 public void resetOtaEmergencyNumberDbFilePath() {
9401 enforceActiveEmergencySessionPermission();
9402
9403 final long identity = Binder.clearCallingIdentity();
9404 try {
9405 for (Phone phone: PhoneFactory.getPhones()) {
9406 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9407 if (tracker != null) {
9408 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009409 }
9410 }
9411 } finally {
9412 Binder.restoreCallingIdentity(identity);
9413 }
9414 }
9415
9416 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009417 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9418 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9419 Phone phone = getPhone(subId);
9420 if (phone == null) {
9421 return null;
9422 }
9423 final long identity = Binder.clearCallingIdentity();
9424 try {
9425 UiccProfile profile = UiccController.getInstance()
9426 .getUiccProfileForPhone(phone.getPhoneId());
9427 if (profile != null) {
9428 return profile.getCertsFromCarrierPrivilegeAccessRules();
9429 }
9430 } finally {
9431 Binder.restoreCallingIdentity(identity);
9432 }
9433 return null;
9434 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009435
9436 /**
9437 * Enable or disable a modem stack.
9438 */
9439 @Override
9440 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9441 enforceModifyPermission();
9442
9443 final long identity = Binder.clearCallingIdentity();
9444 try {
9445 Phone phone = PhoneFactory.getPhone(slotIndex);
9446 if (phone == null) {
9447 return false;
9448 } else {
9449 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9450 }
9451 } finally {
9452 Binder.restoreCallingIdentity(identity);
9453 }
9454 }
Michelecea4cf22018-12-21 15:00:11 -08009455
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009456 /**
9457 * Whether a modem stack is enabled or not.
9458 */
9459 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009460 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9461 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009462 Phone phone = PhoneFactory.getPhone(slotIndex);
9463 if (phone == null) return false;
9464
9465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009466 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9467 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009468 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9469 }
9470
9471 final long identity = Binder.clearCallingIdentity();
9472 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009473 try {
9474 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9475 } catch (NoSuchElementException ex) {
9476 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9477 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009478 } finally {
9479 Binder.restoreCallingIdentity(identity);
9480 }
9481 }
9482
Michelecea4cf22018-12-21 15:00:11 -08009483 @Override
Michele0ea7d782019-03-19 14:58:42 -07009484 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009485 enforceModifyPermission();
9486
9487 final long identity = Binder.clearCallingIdentity();
9488 try {
9489 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009490 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009491 .commit();
9492 } finally {
9493 Binder.restoreCallingIdentity(identity);
9494 }
9495 }
9496
9497 @Override
Michele0ea7d782019-03-19 14:58:42 -07009498 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009499 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009500 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009501 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9502 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009503 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009504 }
Michelecea4cf22018-12-21 15:00:11 -08009505
9506 final long identity = Binder.clearCallingIdentity();
9507 try {
Michele0ea7d782019-03-19 14:58:42 -07009508 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009509 } finally {
9510 Binder.restoreCallingIdentity(identity);
9511 }
9512 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009513
Michele0ea7d782019-03-19 14:58:42 -07009514 @TelephonyManager.IsMultiSimSupportedResult
9515 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009516 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9517 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9518 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009519 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9520 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009521 }
9522 // Check if the hardware supports multisim functionality. If usage of multisim is not
9523 // supported by the modem, indicate that it is restricted.
9524 PhoneCapability staticCapability =
9525 mPhoneConfigurationManager.getStaticPhoneCapability();
9526 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009527 loge("isMultiSimSupportedInternal: no static configuration available");
9528 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009529 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009530 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009531 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9532 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009533 }
9534 // Check if support of multiple SIMs is restricted by carrier
9535 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009536 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009537 }
9538
Michele0ea7d782019-03-19 14:58:42 -07009539 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009540 }
9541
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009542 /**
9543 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009544 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9545 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9546 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009547 * @param numOfSims number of active sims we want to switch to
9548 */
9549 @Override
9550 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009551 if (numOfSims == 1) {
9552 enforceModifyPermission();
9553 } else {
9554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9555 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9556 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009557 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009558
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009559 try {
Michele30b57b22019-03-01 12:01:14 -08009560 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009561 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009562 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9563 return;
9564 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009565 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9566 } finally {
9567 Binder.restoreCallingIdentity(identity);
9568 }
9569 }
9570
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009571 @Override
9572 public boolean isApplicationOnUicc(int subId, int appType) {
9573 enforceReadPrivilegedPermission("isApplicationOnUicc");
9574 Phone phone = getPhone(subId);
9575 if (phone == null) {
9576 return false;
9577 }
9578 final long identity = Binder.clearCallingIdentity();
9579 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009580 UiccPort uiccPort = phone.getUiccPort();
9581 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009582 return false;
9583 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009584 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009585 if (uiccProfile == null) {
9586 return false;
9587 }
9588 if (TelephonyManager.APPTYPE_SIM <= appType
9589 && appType <= TelephonyManager.APPTYPE_ISIM) {
9590 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9591 }
9592 return false;
9593 } finally {
9594 Binder.restoreCallingIdentity(identity);
9595 }
9596 }
9597
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009598 /**
chen xub4baa772019-04-03 10:23:41 -07009599 * Get whether making changes to modem configurations will trigger reboot.
9600 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009601 */
9602 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009603 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9604 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009605 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009606 mApp, subId, callingPackage, callingFeatureId,
9607 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009608 return false;
9609 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009610 final long identity = Binder.clearCallingIdentity();
9611 try {
9612 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9613 } finally {
9614 Binder.restoreCallingIdentity(identity);
9615 }
9616 }
9617
Nathan Harold29f5f052019-02-15 13:41:57 -08009618 private void updateModemStateMetrics() {
9619 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9620 // TODO: check the state for each modem if the api is ready.
9621 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9622 }
9623
Pengquan Meng3889a572019-01-23 11:16:29 -08009624 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009625 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009626 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009627 // Verify that the callingPackage belongs to the calling UID
9628 mApp.getSystemService(AppOpsManager.class)
9629 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009630 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009631 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009632 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009633 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9634 if (slotInfos != null) {
9635 for (int i = 0; i < slotInfos.length; i++) {
9636 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9637 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9638 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9639 portInfo.getLogicalSlotIndex()));
9640 }
9641 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009642 }
9643 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009644 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009645 } finally {
9646 Binder.restoreCallingIdentity(identity);
9647 }
9648 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009649
9650 /**
9651 * Get the IRadio HAL Version
9652 */
9653 @Override
9654 public int getRadioHalVersion() {
9655 Phone phone = getDefaultPhone();
9656 if (phone == null) return -1;
9657 HalVersion hv = phone.getHalVersion();
9658 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9659 return hv.major * 100 + hv.minor;
9660 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009661
9662 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009663 * Get the current calling package name.
9664 * @return the current calling package name
9665 */
9666 @Override
9667 public String getCurrentPackageName() {
9668 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9669 }
9670
9671 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009672 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9673 * corresponding network requests on a subId.
9674 *
9675 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009676 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009677 * 2) APN is un-metered for this subscription, or
9678 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009679 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009680 *
9681 * @return whether data is allowed for a apn type.
9682 *
9683 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009684 */
9685 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009686 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009687 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9688 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009689
9690 // Now that all security checks passes, perform the operation as ourselves.
9691 final long identity = Binder.clearCallingIdentity();
9692 try {
9693 Phone phone = getPhone(subId);
9694 if (phone == null) return false;
9695
Jack Yu27422a52022-03-21 10:38:05 -07009696 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009697 boolean isDataEnabled;
Jack Yud7b8d372022-07-31 00:43:21 -07009698 isMetered = phone.getDataNetworkController().getDataConfigManager()
9699 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9700 phone.getServiceState().getDataRoaming());
9701 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009702 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009703 } finally {
9704 Binder.restoreCallingIdentity(identity);
9705 }
9706 }
9707
9708 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009709 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009710 enforceReadPrivilegedPermission("isApnMetered");
9711
9712 // Now that all security checks passes, perform the operation as ourselves.
9713 final long identity = Binder.clearCallingIdentity();
9714 try {
9715 Phone phone = getPhone(subId);
9716 if (phone == null) return true; // By default return true.
Jack Yud7b8d372022-07-31 00:43:21 -07009717 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9718 DataUtils.apnTypeToNetworkCapability(apnType),
9719 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009720 } finally {
9721 Binder.restoreCallingIdentity(identity);
9722 }
9723 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009724
9725 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009726 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9727 int subscriptionId, IBooleanConsumer resultCallback) {
9728 enforceModifyPermission();
9729 long token = Binder.clearCallingIdentity();
9730 try {
9731 Phone phone = getPhone(subscriptionId);
9732 if (phone == null) {
9733 try {
9734 if (resultCallback != null) {
9735 resultCallback.accept(false);
9736 }
9737 } catch (RemoteException e) {
9738 // ignore
9739 }
9740 return;
9741 }
9742 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9743 Pair.create(specifiers, (x) -> {
9744 try {
9745 if (resultCallback != null) {
9746 resultCallback.accept(x);
9747 }
9748 } catch (RemoteException e) {
9749 // ignore
9750 }
9751 });
9752 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9753 } finally {
9754 Binder.restoreCallingIdentity(token);
9755 }
9756 }
9757
9758 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009759 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9760 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009761 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009762 mApp, subId, "getSystemSelectionChannels");
9763 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9764 final long identity = Binder.clearCallingIdentity();
9765 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009766 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9767 if (result instanceof IllegalStateException) {
9768 throw (IllegalStateException) result;
9769 }
9770 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009771 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9772 return specifiers;
9773 } finally {
9774 Binder.restoreCallingIdentity(identity);
9775 }
9776 }
9777
9778 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009779 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009780 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009781 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009782 }
9783
9784 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009785 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9786 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009787 if (callingPackage == null) {
9788 callingPackage = getCurrentPackageName();
9789 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009790 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9791 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009792 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9793 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009794 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9795 }
9796 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9797 Intent intent = new Intent();
9798 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9799 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9800 // Bring up choose default SMS subscription dialog right now
9801 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9802 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9803 mApp.startActivity(intent);
9804 }
chen xud5ca2d52019-05-28 15:20:57 -07009805
9806 @Override
9807 public String getMmsUAProfUrl(int subId) {
9808 //TODO investigate if this API should require proper permission check in R b/133791609
9809 final long identity = Binder.clearCallingIdentity();
9810 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009811 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9812 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9813 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9814 return carrierUAProfUrl;
9815 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009816 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9817 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009818 } finally {
9819 Binder.restoreCallingIdentity(identity);
9820 }
9821 }
9822
9823 @Override
9824 public String getMmsUserAgent(int subId) {
9825 //TODO investigate if this API should require proper permission check in R b/133791609
9826 final long identity = Binder.clearCallingIdentity();
9827 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009828 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9829 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9830 if (!TextUtils.isEmpty(carrierUserAgent)) {
9831 return carrierUserAgent;
9832 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009833 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9834 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009835 } finally {
9836 Binder.restoreCallingIdentity(identity);
9837 }
9838 }
Jack Yub07d4972019-05-28 16:12:25 -07009839
9840 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009841 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9842 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009843
Jack Yub07d4972019-05-28 16:12:25 -07009844 final long identity = Binder.clearCallingIdentity();
9845 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009846 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009847 if (phone == null) return false;
9848
Hall Liua62f5da2020-09-25 10:42:19 -07009849 switch (policy) {
9850 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yud7b8d372022-07-31 00:43:21 -07009851 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
Hall Liua62f5da2020-09-25 10:42:19 -07009852 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yud7b8d372022-07-31 00:43:21 -07009853 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
Hall Liua62f5da2020-09-25 10:42:19 -07009854 default:
9855 throw new IllegalArgumentException(policy + " is not a valid policy");
9856 }
Jack Yub07d4972019-05-28 16:12:25 -07009857 } finally {
9858 Binder.restoreCallingIdentity(identity);
9859 }
9860 }
9861
9862 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009863 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009864 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009865 enforceModifyPermission();
9866
changbettyd5c246e2019-12-24 15:40:37 +08009867 final long identity = Binder.clearCallingIdentity();
9868 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009869 Phone phone = getPhone(subscriptionId);
9870 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009871
Hall Liua62f5da2020-09-25 10:42:19 -07009872 switch (policy) {
9873 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yud7b8d372022-07-31 00:43:21 -07009874 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
Hall Liua62f5da2020-09-25 10:42:19 -07009875 break;
9876 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yud7b8d372022-07-31 00:43:21 -07009877 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
Hall Liua62f5da2020-09-25 10:42:19 -07009878 break;
9879 default:
9880 throw new IllegalArgumentException(policy + " is not a valid policy");
9881 }
changbettyd5c246e2019-12-24 15:40:37 +08009882 } finally {
9883 Binder.restoreCallingIdentity(identity);
9884 }
9885 }
9886
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009887 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009888 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009889 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9890 * otherwise.
9891 */
9892 @Override
9893 public void setCepEnabled(boolean isCepEnabled) {
9894 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9895
9896 final long identity = Binder.clearCallingIdentity();
9897 try {
9898 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9899 for (Phone phone : PhoneFactory.getPhones()) {
9900 Phone defaultPhone = phone.getImsPhone();
9901 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9902 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9903 ImsPhoneCallTracker imsPhoneCallTracker =
9904 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9905 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9906 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9907 + imsPhone.getMsisdn());
9908 }
9909 }
9910 } finally {
9911 Binder.restoreCallingIdentity(identity);
9912 }
9913 }
allenwtsu46dcc572020-01-08 18:24:03 +08009914
9915 /**
9916 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9917 *
9918 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9919 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9920 * before being read.
9921 */
9922 @Override
9923 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9924 isCompressed) {
9925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9926 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9928 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9929 }
9930 if (!isImsAvailableOnDevice()) {
9931 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9932 "IMS not available on device.");
9933 }
9934
9935 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009936 try {
Hui Wang761a6682020-10-31 05:12:53 +00009937 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9938 } finally {
9939 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009940 }
9941 }
zoey chene02881a2019-12-30 16:11:23 +08009942
9943 @Override
9944 public boolean isIccLockEnabled(int subId) {
9945 enforceReadPrivilegedPermission("isIccLockEnabled");
9946
9947 // Now that all security checks passes, perform the operation as ourselves.
9948 final long identity = Binder.clearCallingIdentity();
9949 try {
9950 Phone phone = getPhone(subId);
9951 if (phone != null && phone.getIccCard() != null) {
9952 return phone.getIccCard().getIccLockEnabled();
9953 } else {
9954 return false;
9955 }
9956 } finally {
9957 Binder.restoreCallingIdentity(identity);
9958 }
9959 }
9960
9961 /**
9962 * Set the ICC pin lock enabled or disabled.
9963 *
9964 * @return an integer representing the status of IccLock enabled or disabled in the following
9965 * three cases:
9966 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9967 * successfully.
9968 * - Positive number and zero for remaining password attempts.
9969 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9970 *
9971 */
9972 @Override
9973 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9974 enforceModifyPermission();
9975
9976 Phone phone = getPhone(subId);
9977 if (phone == null) {
9978 return 0;
9979 }
9980 // Now that all security checks passes, perform the operation as ourselves.
9981 final long identity = Binder.clearCallingIdentity();
9982 try {
9983 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9984 new Pair<Boolean, String>(enabled, password), phone, null);
9985 return attemptsRemaining;
9986
9987 } catch (Exception e) {
9988 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9989 } finally {
9990 Binder.restoreCallingIdentity(identity);
9991 }
9992 return 0;
9993 }
9994
9995 /**
9996 * Change the ICC password used in ICC pin lock.
9997 *
9998 * @return an integer representing the status of IccLock changed in the following three cases:
9999 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10000 * - Positive number and zero for remaining password attempts.
10001 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10002 *
10003 */
10004 @Override
10005 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10006 enforceModifyPermission();
10007
10008 Phone phone = getPhone(subId);
10009 if (phone == null) {
10010 return 0;
10011 }
10012 // Now that all security checks passes, perform the operation as ourselves.
10013 final long identity = Binder.clearCallingIdentity();
10014 try {
10015 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10016 new Pair<String, String>(oldPassword, newPassword), phone, null);
10017 return attemptsRemaining;
10018
10019 } catch (Exception e) {
10020 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10021 } finally {
10022 Binder.restoreCallingIdentity(identity);
10023 }
10024 return 0;
10025 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010026
10027 /**
10028 * Request for receiving user activity notification
10029 */
10030 @Override
10031 public void requestUserActivityNotification() {
10032 if (!mNotifyUserActivity.get()
10033 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10034 mNotifyUserActivity.set(true);
10035 }
10036 }
10037
10038 /**
10039 * Called when userActivity is signalled in the power manager.
10040 * This is safe to call from any thread, with any window manager locks held or not.
10041 */
10042 @Override
10043 public void userActivity() {
10044 // ***************************************
10045 // * Inherited from PhoneWindowManager *
10046 // ***************************************
10047 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10048 // WITH ITS LOCKS HELD.
10049 //
10050 // This code must be VERY careful about the locks
10051 // it acquires.
10052 // In fact, the current code acquires way too many,
10053 // and probably has lurking deadlocks.
10054
10055 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10056 throw new SecurityException("Only the OS may call notifyUserActivity()");
10057 }
10058
10059 if (mNotifyUserActivity.getAndSet(false)) {
10060 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10061 USER_ACTIVITY_NOTIFICATION_DELAY);
10062 }
10063 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010064
10065 @Override
10066 public boolean canConnectTo5GInDsdsMode() {
10067 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10068 }
Jack Yud10cdd42020-09-28 20:28:01 -070010069
10070 @Override
10071 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10072 String callingFeatureId) {
10073 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10074 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10075 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10076 }
10077
10078 Phone phone = getPhone(subId);
10079 if (phone == null) {
10080 throw new RuntimeException("phone is not available");
10081 }
10082 // Now that all security checks passes, perform the operation as ourselves.
10083 final long identity = Binder.clearCallingIdentity();
10084 try {
10085 return phone.getEquivalentHomePlmns();
10086 } finally {
10087 Binder.restoreCallingIdentity(identity);
10088 }
10089 }
Daniel Bright59e67312020-11-13 11:49:37 -080010090
10091 @Override
10092 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010093 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10094 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010095 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010096 if (radioInterfaceCapabilities == null) {
10097 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010098 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010099 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010100 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010101
Hui Wang641e81c2020-10-12 12:14:23 -070010102 @Override
10103 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10104 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010105 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10106 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10107 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10108 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10109 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010110 if (DBG) {
10111 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10112 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10113 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10114 }
10115
10116 if (!SubscriptionManager.isValidSubscriptionId(subId)
10117 || appType < TelephonyManager.APPTYPE_UNKNOWN
10118 || appType > TelephonyManager.APPTYPE_ISIM
10119 || nafUrl == null || securityProtocol == null || callback == null) {
10120 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10121 if (callback != null) {
10122 try {
10123 callback.onAuthenticationFailure(
10124 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10125 } catch (RemoteException exception) {
10126 log("Fail to notify onAuthenticationFailure due to " + exception);
10127 }
10128 return;
10129 }
10130 }
10131
10132 final long token = Binder.clearCallingIdentity();
10133 try {
10134 getGbaManager(subId).bootstrapAuthenticationRequest(
10135 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10136 forceBootStrapping, callback));
10137 } finally {
10138 Binder.restoreCallingIdentity(token);
10139 }
10140 }
10141
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010142 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010143 * Attempts to set the radio power state for all phones for thermal reason.
10144 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010145 * requested radio power state will actually be set. See {@link
10146 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10147 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010148 * @param enable {@code true} if trying to turn radio on.
10149 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10150 * false}.
10151 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010152 private boolean setRadioPowerForThermal(boolean enable) {
10153 boolean isPhoneAvailable = false;
10154 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10155 Phone phone = PhoneFactory.getPhone(i);
10156 if (phone != null) {
10157 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10158 isPhoneAvailable = true;
10159 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010160 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010161
10162 // return true if successfully informed the phone object about the thermal radio power
10163 // request.
10164 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010165 }
10166
10167 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010168 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010169 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10170 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10171 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10172 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10173 throw new IllegalArgumentException("modem does not support data throttling");
10174 }
10175
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010176 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10177 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010178 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010179 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10180 }
10181
Sarah Chinecc78c42022-03-31 21:16:48 -070010182 setDataEnabledForReason(
10183 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010184
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010185 if (isDataThrottlingSupported) {
10186 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010187 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010188 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10189 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10190 } else if (thermalMitigationResult
10191 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010192 log("Modem likely does not support data throttling on secondary carrier. Data " +
10193 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10194 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010195 }
10196 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010197 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010198
10199 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010200 }
10201
Jack Nudelman644b91a2021-03-12 14:09:48 -080010202 private static List<String> getThermalMitigationAllowlist(Context context) {
10203 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10204 for (String pckg : context.getResources()
10205 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10206 sThermalMitigationAllowlistedPackages.add(pckg);
10207 }
10208 }
10209
10210 return sThermalMitigationAllowlistedPackages;
10211 }
10212
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010213 private boolean isAnyPhoneInEmergencyState() {
10214 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10215 if (tm.isInEmergencyCall()) {
10216 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10217 return true;
10218 }
10219 for (Phone phone : PhoneFactory.getPhones()) {
10220 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10221 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10222 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10223 + phone.isInEcm());
10224 return true;
10225 }
10226 }
10227
10228 return false;
10229 }
10230
Jack Nudelman644b91a2021-03-12 14:09:48 -080010231 /**
10232 * Used by shell commands to add an authorized package name for thermal mitigation.
10233 * @param packageName name of package to be allowlisted
10234 * @param context
10235 */
10236 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10237 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10238 sThermalMitigationAllowlistedPackages.add(packageName);
10239 }
10240
10241 /**
10242 * Used by shell commands to remove an authorized package name for thermal mitigation.
10243 * @param packageName name of package to remove from allowlist
10244 * @param context
10245 */
10246 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10247 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10248 sThermalMitigationAllowlistedPackages.remove(packageName);
10249 }
10250
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010251 /**
10252 * Thermal mitigation request to control functionalities at modem.
10253 *
10254 * @param subId the id of the subscription.
10255 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010256 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010257 *
10258 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10259 */
10260 @Override
10261 @ThermalMitigationResult
10262 public int sendThermalMitigationRequest(
10263 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010264 ThermalMitigationRequest thermalMitigationRequest,
10265 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010266 enforceModifyPermission();
10267
Jack Nudelman644b91a2021-03-12 14:09:48 -080010268 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10269 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10270 .contains(callingPackage)) {
10271 throw new SecurityException("Calling package must be configured in the device config. "
10272 + "calling package: " + callingPackage);
10273 }
10274
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010275 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10276 final long identity = Binder.clearCallingIdentity();
10277
10278 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10279 try {
10280 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10281 switch (thermalMitigationAction) {
10282 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10283 thermalMitigationResult =
10284 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010285 thermalMitigationRequest.getDataThrottlingRequest(),
10286 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010287 break;
10288 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10289 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10290 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10291 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10292 }
10293
10294 // Ensure that radio is on. If not able to power on due to phone being
10295 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010296 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010297 thermalMitigationResult =
10298 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10299 break;
10300 }
10301
10302 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010303 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010304 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10305 break;
10306 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10307 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10308 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10309 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10310 }
10311
10312 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10313 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010314 Phone phone = getPhone(subId);
10315 if (phone == null) {
10316 thermalMitigationResult =
10317 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10318 break;
10319 }
10320
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010321 TelephonyConnectionService service =
10322 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010323 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010324 Log.e(LOG_TAG, "An emergency call is pending");
10325 thermalMitigationResult =
10326 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10327 break;
10328 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010329 thermalMitigationResult =
10330 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10331 break;
10332 }
10333 } else {
10334 thermalMitigationResult =
10335 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10336 break;
10337 }
10338
10339 // Turn radio off. If not able to power off due to phone being unavailable,
10340 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010341 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010342 thermalMitigationResult =
10343 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10344 break;
10345 }
10346 thermalMitigationResult =
10347 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10348 break;
10349 default:
10350 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10351 + "not exist. Requested action: " + thermalMitigationAction);
10352 }
10353 } catch (IllegalArgumentException e) {
10354 throw e;
10355 } catch (Exception e) {
10356 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10357 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10358 } finally {
10359 Binder.restoreCallingIdentity(identity);
10360 }
10361
10362 if (DBG) {
10363 log("thermalMitigationRequest returning with thermalMitigationResult: "
10364 + thermalMitigationResult);
10365 }
10366
10367 return thermalMitigationResult;
10368 }
Hui Wang641e81c2020-10-12 12:14:23 -070010369
10370 /**
10371 * Set the GbaService Package Name that Telephony will bind to.
10372 *
10373 * @param subId The sim that the GbaService is associated with.
10374 * @param packageName The name of the package to be replaced with.
10375 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10376 */
10377 @Override
10378 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10379 enforceModifyPermission();
10380
10381 final long identity = Binder.clearCallingIdentity();
10382 try {
10383 return getGbaManager(subId).overrideServicePackage(packageName);
10384 } finally {
10385 Binder.restoreCallingIdentity(identity);
10386 }
10387 }
10388
10389 /**
10390 * Return the package name of the currently bound GbaService.
10391 *
10392 * @param subId The sim that the GbaService is associated with.
10393 * @return the package name of the GbaService configuration, null if GBA is not supported.
10394 */
10395 @Override
10396 public String getBoundGbaService(int subId) {
10397 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10398
10399 final long identity = Binder.clearCallingIdentity();
10400 try {
10401 return getGbaManager(subId).getServicePackage();
10402 } finally {
10403 Binder.restoreCallingIdentity(identity);
10404 }
10405 }
10406
10407 /**
10408 * Set the release time for telephony to unbind GbaService.
10409 *
10410 * @param subId The sim that the GbaService is associated with.
10411 * @param interval The release time to unbind GbaService by millisecond.
10412 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10413 */
10414 @Override
10415 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10416 enforceModifyPermission();
10417
10418 final long identity = Binder.clearCallingIdentity();
10419 try {
10420 return getGbaManager(subId).overrideReleaseTime(interval);
10421 } finally {
10422 Binder.restoreCallingIdentity(identity);
10423 }
10424 }
10425
10426 /**
10427 * Return the release time for telephony to unbind GbaService.
10428 *
10429 * @param subId The sim that the GbaService is associated with.
10430 * @return The release time to unbind GbaService by millisecond.
10431 */
10432 @Override
10433 public int getGbaReleaseTime(int subId) {
10434 enforceReadPrivilegedPermission("getGbaReleaseTime");
10435
10436 final long identity = Binder.clearCallingIdentity();
10437 try {
10438 return getGbaManager(subId).getReleaseTime();
10439 } finally {
10440 Binder.restoreCallingIdentity(identity);
10441 }
10442 }
10443
10444 private GbaManager getGbaManager(int subId) {
10445 GbaManager instance = GbaManager.getInstance(subId);
10446 if (instance == null) {
10447 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10448 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10449 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10450 }
10451 return instance;
10452 }
Hui Wang761a6682020-10-31 05:12:53 +000010453
10454 /**
10455 * indicate whether the device and the carrier can support
10456 * RCS VoLTE single registration.
10457 */
10458 @Override
10459 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010460 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10461 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10462 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10463 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010464
10465 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10466 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10467 }
10468
10469 final long identity = Binder.clearCallingIdentity();
10470 try {
10471 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10472 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010473 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10474 if (isCapable != null) {
10475 return isCapable;
10476 }
Hui Wang761a6682020-10-31 05:12:53 +000010477 }
Hui Wang67af90e2021-06-04 16:57:15 -070010478 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10479 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010480 } finally {
10481 Binder.restoreCallingIdentity(identity);
10482 }
10483 }
10484
10485 /**
10486 * Register RCS provisioning callback.
10487 */
10488 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010489 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010490 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010491 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010492 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010493 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10494 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010495
10496 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10497 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10498 }
10499 if (!isImsAvailableOnDevice()) {
10500 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10501 "IMS not available on device.");
10502 }
10503
10504 final long identity = Binder.clearCallingIdentity();
10505 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010506 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010507 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010508 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10509 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010510 }
Hui Wang761a6682020-10-31 05:12:53 +000010511 } finally {
10512 Binder.restoreCallingIdentity(identity);
10513 }
10514 }
10515
10516 /**
10517 * Unregister RCS provisioning callback.
10518 */
10519 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010520 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010521 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010522 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010523 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010524 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10525 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010526
10527 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10528 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10529 }
10530 if (!isImsAvailableOnDevice()) {
10531 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10532 "IMS not available on device.");
10533 }
10534
10535 final long identity = Binder.clearCallingIdentity();
10536 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010537 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010538 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010539 } finally {
10540 Binder.restoreCallingIdentity(identity);
10541 }
10542 }
10543
10544 /**
10545 * trigger RCS reconfiguration.
10546 */
10547 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010548 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10549 "triggerRcsReconfiguration",
10550 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010551
10552 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10553 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10554 }
10555 if (!isImsAvailableOnDevice()) {
10556 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10557 "IMS not available on device.");
10558 }
10559
10560 final long identity = Binder.clearCallingIdentity();
10561 try {
10562 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10563 } finally {
10564 Binder.restoreCallingIdentity(identity);
10565 }
10566 }
10567
10568 /**
10569 * Provide the client configuration parameters of the RCS application.
10570 */
10571 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010572 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10573 "setRcsClientConfiguration",
10574 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010575
10576 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10577 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10578 }
10579 if (!isImsAvailableOnDevice()) {
10580 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10581 "IMS not available on device.");
10582 }
10583
10584 final long identity = Binder.clearCallingIdentity();
10585
10586 try {
10587 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10588 if (configBinder == null) {
10589 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010590 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10591 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010592 } else {
10593 configBinder.setRcsClientConfiguration(rcc);
10594 }
joonhunshin3e154242021-09-17 06:33:39 +000010595
10596 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10597 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010598 } catch (RemoteException e) {
10599 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010600 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10601 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010602 } finally {
10603 Binder.restoreCallingIdentity(identity);
10604 }
10605 }
10606
10607 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010608 * Enables or disables the test mode for RCS VoLTE single registration.
10609 */
10610 @Override
10611 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10612 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10613 "setRcsSingleRegistrationTestModeEnabled");
10614
10615 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10616 }
10617
10618 /**
10619 * Gets the test mode for RCS VoLTE single registration.
10620 */
10621 @Override
10622 public boolean getRcsSingleRegistrationTestModeEnabled() {
10623 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10624 "getRcsSingleRegistrationTestModeEnabled");
10625
10626 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10627 }
10628
10629 /**
Hui Wang761a6682020-10-31 05:12:53 +000010630 * Overrides the config of RCS VoLTE single registration enabled for the device.
10631 */
10632 @Override
10633 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10634 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10635 "setDeviceSingleRegistrationEnabledOverride");
10636 enforceModifyPermission();
10637
10638 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10639 : Boolean.parseBoolean(enabledStr);
10640 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010641 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010642 }
10643
10644 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010645 * Sends a device to device communication message. Only usable via shell.
10646 * @param message message to send.
10647 * @param value message value.
10648 */
10649 @Override
10650 public void sendDeviceToDeviceMessage(int message, int value) {
10651 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010652 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010653 enforceModifyPermission();
10654
10655 final long identity = Binder.clearCallingIdentity();
10656 try {
10657 TelephonyConnectionService service =
10658 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10659 if (service == null) {
10660 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10661 return;
10662 }
10663 service.sendTestDeviceToDeviceMessage(message, value);
10664 } finally {
10665 Binder.restoreCallingIdentity(identity);
10666 }
10667 }
10668
Tyler Gunnbabbda02021-02-10 11:05:02 -080010669 /**
10670 * Sets the specified device to device transport active.
10671 * @param transport The transport to set active.
10672 */
10673 @Override
10674 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10675 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10676 "setActiveDeviceToDeviceTransport");
10677 enforceModifyPermission();
10678
10679 final long identity = Binder.clearCallingIdentity();
10680 try {
10681 TelephonyConnectionService service =
10682 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10683 if (service == null) {
10684 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10685 return;
10686 }
10687 service.setActiveDeviceToDeviceTransport(transport);
10688 } finally {
10689 Binder.restoreCallingIdentity(identity);
10690 }
10691 }
Tyler Gunn92479152021-01-20 16:30:10 -080010692
Tyler Gunnd4339262021-05-03 14:46:49 -070010693 @Override
10694 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10695 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10696 "setDeviceToDeviceForceEnabled");
10697
10698 final long identity = Binder.clearCallingIdentity();
10699 try {
10700 Arrays.stream(PhoneFactory.getPhones()).forEach(
10701 p -> {
10702 Phone thePhone = p.getImsPhone();
10703 if (thePhone != null && thePhone instanceof ImsPhone) {
10704 ImsPhone imsPhone = (ImsPhone) thePhone;
10705 CallTracker tracker = imsPhone.getCallTracker();
10706 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10707 ImsPhoneCallTracker imsPhoneCallTracker =
10708 (ImsPhoneCallTracker) tracker;
10709 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10710 }
10711 }
10712 }
10713 );
10714 } finally {
10715 Binder.restoreCallingIdentity(identity);
10716 }
10717 }
10718
Tyler Gunn92479152021-01-20 16:30:10 -080010719 /**
Hui Wang761a6682020-10-31 05:12:53 +000010720 * Gets the config of RCS VoLTE single registration enabled for the device.
10721 */
10722 @Override
10723 public boolean getDeviceSingleRegistrationEnabled() {
10724 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10725 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10726 }
10727
10728 /**
10729 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10730 */
10731 @Override
10732 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10733 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10734 "setCarrierSingleRegistrationEnabledOverride");
10735 enforceModifyPermission();
10736
10737 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10738 : Boolean.parseBoolean(enabledStr);
10739 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10740 subId, enabled);
10741 }
10742
10743 /**
10744 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10745 */
10746 @Override
10747 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10748 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10749 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10750 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010751
10752 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010753 * Overrides the ims feature validation result
10754 */
10755 @Override
10756 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10757 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10758 "setImsFeatureValidationOverride");
10759
10760 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10761 : Boolean.parseBoolean(enabledStr);
10762 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10763 subId, enabled);
10764 }
10765
10766 /**
10767 * Gets the ims feature validation override value
10768 */
10769 @Override
10770 public boolean getImsFeatureValidationOverride(int subId) {
10771 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10772 "getImsFeatureValidationOverride");
10773 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10774 }
10775
10776 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010777 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10778 * their mobile plan.
10779 */
10780 @Override
10781 public String getMobileProvisioningUrl() {
10782 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10783 final long identity = Binder.clearCallingIdentity();
10784 try {
10785 return getDefaultPhone().getMobileProvisioningUrl();
10786 } finally {
10787 Binder.restoreCallingIdentity(identity);
10788 }
10789 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010790
James.cf Linbcdf8b32021-01-14 16:44:13 +080010791 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010792 * Get the EAB contact from the EAB database.
10793 */
10794 @Override
10795 public String getContactFromEab(String contact) {
10796 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10797 enforceModifyPermission();
10798 final long identity = Binder.clearCallingIdentity();
10799 try {
10800 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10801 } finally {
10802 Binder.restoreCallingIdentity(identity);
10803 }
10804 }
10805
10806 /**
Calvin Pana1434322021-07-01 19:27:01 +080010807 * Get the EAB capability from the EAB database.
10808 */
10809 @Override
10810 public String getCapabilityFromEab(String contact) {
10811 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10812 enforceModifyPermission();
10813 final long identity = Binder.clearCallingIdentity();
10814 try {
10815 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10816 } finally {
10817 Binder.restoreCallingIdentity(identity);
10818 }
10819 }
10820
10821 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010822 * Remove the EAB contacts from the EAB database.
10823 */
10824 @Override
10825 public int removeContactFromEab(int subId, String contacts) {
10826 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10827 enforceModifyPermission();
10828 final long identity = Binder.clearCallingIdentity();
10829 try {
10830 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10831 } finally {
10832 Binder.restoreCallingIdentity(identity);
10833 }
10834 }
10835
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010836 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010837 public boolean getDeviceUceEnabled() {
10838 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10839 final long identity = Binder.clearCallingIdentity();
10840 try {
10841 return mApp.getDeviceUceEnabled();
10842 } finally {
10843 Binder.restoreCallingIdentity(identity);
10844 }
10845 }
10846
10847 @Override
10848 public void setDeviceUceEnabled(boolean isEnabled) {
10849 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10850 final long identity = Binder.clearCallingIdentity();
10851 try {
10852 mApp.setDeviceUceEnabled(isEnabled);
10853 } finally {
10854 Binder.restoreCallingIdentity(identity);
10855 }
10856 }
10857
Brad Ebinger14d467f2021-02-12 06:18:28 +000010858 /**
10859 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10860 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10861 */
10862 // Used for SHELL command only right now.
10863 @Override
10864 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10865 List<String> featureTags) {
10866 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10867 "addUceRegistrationOverrideShell");
10868 final long identity = Binder.clearCallingIdentity();
10869 try {
10870 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10871 new ArraySet<>(featureTags));
10872 } catch (ImsException e) {
10873 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10874 } finally {
10875 Binder.restoreCallingIdentity(identity);
10876 }
10877 }
10878
10879 /**
10880 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10881 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10882 */
10883 // Used for SHELL command only right now.
10884 @Override
10885 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10886 List<String> featureTags) {
10887 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10888 "removeUceRegistrationOverrideShell");
10889 final long identity = Binder.clearCallingIdentity();
10890 try {
10891 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10892 new ArraySet<>(featureTags));
10893 } catch (ImsException e) {
10894 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10895 } finally {
10896 Binder.restoreCallingIdentity(identity);
10897 }
10898 }
10899
10900 /**
10901 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10902 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10903 */
10904 // Used for SHELL command only right now.
10905 @Override
10906 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10907 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10908 "clearUceRegistrationOverrideShell");
10909 final long identity = Binder.clearCallingIdentity();
10910 try {
10911 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10912 } catch (ImsException e) {
10913 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10914 } finally {
10915 Binder.restoreCallingIdentity(identity);
10916 }
10917 }
10918
10919 /**
10920 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10921 */
10922 // Used for SHELL command only right now.
10923 @Override
10924 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10925 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10926 "getLatestRcsContactUceCapabilityShell");
10927 final long identity = Binder.clearCallingIdentity();
10928 try {
10929 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10930 } catch (ImsException e) {
10931 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10932 } finally {
10933 Binder.restoreCallingIdentity(identity);
10934 }
10935 }
10936
10937 /**
10938 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10939 * device does not have an active PUBLISH.
10940 */
10941 // Used for SHELL command only right now.
10942 @Override
10943 public String getLastUcePidfXmlShell(int subId) {
10944 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10945 final long identity = Binder.clearCallingIdentity();
10946 try {
10947 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10948 } catch (ImsException e) {
10949 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10950 } finally {
10951 Binder.restoreCallingIdentity(identity);
10952 }
10953 }
10954
James.cf Line8713a42021-04-29 16:04:26 +080010955 /**
10956 * Remove UCE requests cannot be sent to the network status.
10957 */
10958 // Used for SHELL command only right now.
10959 @Override
10960 public boolean removeUceRequestDisallowedStatus(int subId) {
10961 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10962 final long identity = Binder.clearCallingIdentity();
10963 try {
10964 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10965 } catch (ImsException e) {
10966 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10967 } finally {
10968 Binder.restoreCallingIdentity(identity);
10969 }
10970 }
10971
James.cf Lin18bb9002021-05-25 01:37:38 +080010972 /**
10973 * Remove UCE requests cannot be sent to the network status.
10974 */
10975 // Used for SHELL command only.
10976 @Override
10977 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10978 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10979 final long identity = Binder.clearCallingIdentity();
10980 try {
10981 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10982 } catch (ImsException e) {
10983 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10984 } finally {
10985 Binder.restoreCallingIdentity(identity);
10986 }
10987 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010988
James.cf Lin4b784aa2021-01-31 03:25:15 +080010989 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010990 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10991 String callingPackage) {
10992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10993 mApp, subId, "setSignalStrengthUpdateRequest");
10994
10995 final int callingUid = Binder.getCallingUid();
10996 // Verify that tha callingPackage belongs to the calling UID
10997 mApp.getSystemService(AppOpsManager.class)
10998 .checkPackage(callingUid, callingPackage);
10999
Rambo Wang3607f502021-02-01 21:51:40 -080011000 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011001
11002 final long identity = Binder.clearCallingIdentity();
11003 try {
11004 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11005 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11006
11007 if (result instanceof IllegalStateException) {
11008 throw (IllegalStateException) result;
11009 }
11010 } finally {
11011 Binder.restoreCallingIdentity(identity);
11012 }
11013 }
11014
11015 @Override
11016 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11017 String callingPackage) {
11018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11019 mApp, subId, "clearSignalStrengthUpdateRequest");
11020
11021 final int callingUid = Binder.getCallingUid();
11022 // Verify that tha callingPackage belongs to the calling UID
11023 mApp.getSystemService(AppOpsManager.class)
11024 .checkPackage(callingUid, callingPackage);
11025
11026 final long identity = Binder.clearCallingIdentity();
11027 try {
11028 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11029 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11030
11031 if (result instanceof IllegalStateException) {
11032 throw (IllegalStateException) result;
11033 }
11034 } finally {
11035 Binder.restoreCallingIdentity(identity);
11036 }
11037 }
11038
Rambo Wang3607f502021-02-01 21:51:40 -080011039 private static void validateSignalStrengthUpdateRequest(Context context,
11040 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011041 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11042 // phone/system process do not have further restriction on request
11043 return;
11044 }
11045
11046 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011047 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011048 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011049 context.enforceCallingOrSelfPermission(
11050 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11051 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011052 }
11053
11054 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11055 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11056 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11057 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11058 || info.isEnabled()) {
11059 throw new IllegalArgumentException(
11060 "Only system can set hide fields in SignalThresholdInfo");
11061 }
11062
11063 // Thresholds length for each RAN need in range. This has been validated in
11064 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11065 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11066 final int[] thresholds = info.getThresholds();
11067 Objects.requireNonNull(thresholds);
11068 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11069 || thresholds.length
11070 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11071 throw new IllegalArgumentException(
11072 "thresholds length is out of range: " + thresholds.length);
11073 }
11074 }
11075 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011076
11077 /**
11078 * Gets the current phone capability.
11079 *
11080 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11081 * @return the PhoneCapability which describes the data connection capability of modem.
11082 * It's used to evaluate possible phone config change, for example from single
11083 * SIM device to multi-SIM device.
11084 */
11085 @Override
11086 public PhoneCapability getPhoneCapability() {
11087 enforceReadPrivilegedPermission("getPhoneCapability");
11088 final long identity = Binder.clearCallingIdentity();
11089 try {
11090 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11091 } finally {
11092 Binder.restoreCallingIdentity(identity);
11093 }
11094 }
Michele Berionne5e411512020-11-13 02:36:59 +000011095
11096 /**
11097 * Prepare TelephonyManager for an unattended reboot. The reboot is
11098 * required to be done shortly after the API is invoked.
11099 */
11100 @Override
11101 @TelephonyManager.PrepareUnattendedRebootResult
11102 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011103 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011104 enforceRebootPermission();
11105
11106 final long identity = Binder.clearCallingIdentity();
11107 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011108 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011109 } finally {
11110 Binder.restoreCallingIdentity(identity);
11111 }
11112 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011113
11114 /**
11115 * Request to get the current slicing configuration including URSP rules and
11116 * NSSAIs (configured, allowed and rejected).
11117 *
11118 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11119 */
11120 @Override
11121 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011122 TelephonyPermissions
11123 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11124 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011125
11126 final long identity = Binder.clearCallingIdentity();
11127 try {
11128 Phone phone = getDefaultPhone();
11129 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11130 } finally {
11131 Binder.restoreCallingIdentity(identity);
11132 }
11133 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011134
11135 /**
11136 * Register an IMS connection state callback
11137 */
11138 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011139 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11140 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011141 if (feature == ImsFeature.FEATURE_MMTEL) {
11142 // ImsMmTelManager
11143 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11144 TelephonyPermissions
11145 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11146 mApp, subId, "registerImsStateCallback");
11147 } else if (feature == ImsFeature.FEATURE_RCS) {
11148 // ImsRcsManager or SipDelegateManager
11149 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11150 Binder.getCallingUid(), "registerImsStateCallback",
11151 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11152 Manifest.permission.READ_PRECISE_PHONE_STATE,
11153 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11154 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11155 }
11156
11157 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11158 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11159 "IMS not available on device.");
11160 }
11161
11162 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11163 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11164 }
11165
11166 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11167 if (controller == null) {
11168 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11169 "IMS not available on device.");
11170 }
11171
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011172 if (callingPackage == null) {
11173 callingPackage = getCurrentPackageName();
11174 }
11175
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011176 final long token = Binder.clearCallingIdentity();
11177 try {
11178 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011179 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011180 } catch (ImsException e) {
11181 throw new ServiceSpecificException(e.getCode());
11182 } finally {
11183 Binder.restoreCallingIdentity(token);
11184 }
11185 }
11186
11187 /**
11188 * Unregister an IMS connection state callback
11189 */
11190 @Override
11191 public void unregisterImsStateCallback(IImsStateCallback cb) {
11192 final long token = Binder.clearCallingIdentity();
11193 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11194 if (controller == null) {
11195 return;
11196 }
11197 try {
11198 controller.unregisterImsStateCallback(cb);
11199 } finally {
11200 Binder.restoreCallingIdentity(token);
11201 }
11202 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011203
11204 /**
11205 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11206 *
11207 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11208 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11209 * SecurityException.
11210 * If there is current registered network this value will be same as the registered cell
11211 * identity. If the device goes out of service the previous cell identity is cached and
11212 * will be returned. If the cache age of the Cell identity is more than 24 hours
11213 * it will be cleared and null will be returned.
11214 *
11215 */
11216 @Override
11217 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11218 String callingFeatureId) {
11219 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11220 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11221 LocationAccessPolicy.checkLocationPermission(mApp,
11222 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11223 .setCallingPackage(callingPackage)
11224 .setCallingFeatureId(callingFeatureId)
11225 .setCallingPid(Binder.getCallingPid())
11226 .setCallingUid(Binder.getCallingUid())
11227 .setMethod("getLastKnownCellIdentity")
11228 .setLogAsInfo(true)
11229 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11230 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11231 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11232 .build());
11233
11234 boolean hasFinePermission =
11235 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11236 if (!hasFinePermission
11237 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11238 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011239 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011240 }
11241
11242 final long identity = Binder.clearCallingIdentity();
11243 try {
11244 Phone phone = getPhone(subId);
11245 if (phone == null) return null;
11246 ServiceStateTracker sst = phone.getServiceStateTracker();
11247 if (sst == null) return null;
11248 return sst.getLastKnownCellIdentity();
11249 } finally {
11250 Binder.restoreCallingIdentity(identity);
11251 }
11252 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011253
jimsun3b9ccac2021-10-26 15:01:23 +080011254 /**
11255 * Sets the modem service class Name that Telephony will bind to.
11256 *
11257 * @param serviceName The class name of the modem service.
11258 * @return true if the operation is succeed, otherwise false.
11259 */
11260 public boolean setModemService(String serviceName) {
11261 Log.d(LOG_TAG, "setModemService - " + serviceName);
11262 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11264 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11265 "setModemService");
11266 return mPhoneConfigurationManager.setModemService(serviceName);
11267 }
11268
11269 /**
11270 * Return the class name of the currently bounded modem service.
11271 *
11272 * @return the class name of the modem service.
11273 */
11274 public String getModemService() {
11275 String result;
11276 Log.d(LOG_TAG, "getModemService");
11277 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11278 TelephonyPermissions
11279 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11280 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11281 "getModemService");
11282 result = mPhoneConfigurationManager.getModemService();
11283 Log.d(LOG_TAG, "result = " + result);
11284 return result;
11285 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011286
11287 @Override
11288 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11289 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11290 mApp.enforceCallingOrSelfPermission(
11291 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11292 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11293
11294 final long identity = Binder.clearCallingIdentity();
11295 try {
11296 Phone phone = getPhone(subId);
11297 if (phone == null) return;
11298 phone.setVoiceServiceStateOverride(hasService);
11299 } finally {
11300 Binder.restoreCallingIdentity(identity);
11301 }
11302 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011303
11304 /**
11305 * set removable eSIM as default eUICC.
11306 *
11307 * @hide
11308 */
11309 @Override
11310 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11311 enforceModifyPermission();
11312 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11313
11314 final long identity = Binder.clearCallingIdentity();
11315 try {
11316 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11317 } finally {
11318 Binder.restoreCallingIdentity(identity);
11319 }
11320 }
11321
11322 /**
11323 * Returns whether the removable eSIM is default eUICC or not.
11324 *
11325 * @hide
11326 */
11327 @Override
11328 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11329 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11330 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11331
11332 final long identity = Binder.clearCallingIdentity();
11333 try {
11334 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11335 } finally {
11336 Binder.restoreCallingIdentity(identity);
11337 }
11338 }
11339
11340
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011341}