blob: 92f49e781d83230d3cd6a502c19799544c3214ed [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070034import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000035import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080036import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
tom hsue9360cd2022-09-29 23:49:21 +080053import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.Looper;
55import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080057import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070058import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070059import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080060import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080061import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070062import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070063import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080064import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070066import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070067import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070068import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070069import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080070import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070071import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090072import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080073import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080074import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070075import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080076import android.telephony.AccessNetworkConstants;
77import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070078import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070079import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080080import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080081import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070082import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080083import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070084import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080085import android.telephony.CellIdentityCdma;
86import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070088import android.telephony.CellInfoGsm;
89import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070090import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080091import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070092import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070093import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070094import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080095import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070096import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080097import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070098import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080099import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800100import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700101import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800102import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800104import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800105import android.telephony.SignalStrengthUpdateRequest;
106import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800107import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800109import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700110import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700111import android.telephony.TelephonyManager;
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;
Gary Jian3aa9a762022-01-24 16:41:19 +08001418 if (mLastModemActivityInfo == null) {
1419 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1420 mLastModemActivitySpecificInfo[0] =
1421 new ActivityStatsTechSpecificInfo(
1422 0,
1423 0,
1424 new int[ModemActivityInfo.getNumTxPowerLevels()],
1425 0);
1426 mLastModemActivityInfo =
1427 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1428 }
1429
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001430 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001431 // Update the last modem activity info and the result of the request.
1432 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1433 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001434 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001435 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001436 mLastModemActivityInfo =
1437 new ModemActivityInfo(
1438 mLastModemActivityInfo.getTimestampMillis(),
1439 mLastModemActivityInfo.getSleepTimeMillis(),
1440 mLastModemActivityInfo.getIdleTimeMillis(),
1441 mLastModemActivitySpecificInfo);
1442
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001443 } else {
1444 if (ar.result == null) {
1445 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001446 error = TelephonyManager.ModemActivityInfoException
1447 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001448 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001449 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001450 error = TelephonyManager.ModemActivityInfoException
1451 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001452 } else {
1453 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001454 error = TelephonyManager.ModemActivityInfoException
1455 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001456 }
1457 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001458 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001459 if (mLastModemActivityInfo != null) {
1460 bundle.putParcelable(
1461 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1462 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001463 } else {
1464 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1465 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001466 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001467 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001468 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001469 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001470
Meng Wang1a7c35a2016-05-05 20:56:15 -07001471 case CMD_SET_ALLOWED_CARRIERS:
1472 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001473 CarrierRestrictionRules argument =
1474 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001475 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001476 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001477 break;
1478
1479 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1480 ar = (AsyncResult) msg.obj;
1481 request = (MainThreadRequest) ar.userObj;
1482 if (ar.exception == null && ar.result != null) {
1483 request.result = ar.result;
1484 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001485 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1486 if (ar.exception instanceof CommandException) {
1487 loge("setAllowedCarriers: CommandException: " + ar.exception);
1488 CommandException.Error error =
1489 ((CommandException) (ar.exception)).getCommandError();
1490 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1491 request.result =
1492 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1493 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001494 } else {
1495 loge("setAllowedCarriers: Unknown exception");
1496 }
1497 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001498 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001499 break;
1500
1501 case CMD_GET_ALLOWED_CARRIERS:
1502 request = (MainThreadRequest) msg.obj;
1503 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001504 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001505 break;
1506
1507 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1508 ar = (AsyncResult) msg.obj;
1509 request = (MainThreadRequest) ar.userObj;
1510 if (ar.exception == null && ar.result != null) {
1511 request.result = ar.result;
1512 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001513 request.result = new IllegalStateException(
1514 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001515 if (ar.result == null) {
1516 loge("getAllowedCarriers: Empty response");
1517 } else if (ar.exception instanceof CommandException) {
1518 loge("getAllowedCarriers: CommandException: " +
1519 ar.exception);
1520 } else {
1521 loge("getAllowedCarriers: Unknown exception");
1522 }
1523 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001524 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001525 break;
1526
Nathan Haroldb3014052017-01-25 15:57:32 -08001527 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1528 ar = (AsyncResult) msg.obj;
1529 request = (MainThreadRequest) ar.userObj;
1530 if (ar.exception == null && ar.result != null) {
1531 request.result = ar.result;
1532 } else {
1533 request.result = new IllegalArgumentException(
1534 "Failed to retrieve Forbidden Plmns");
1535 if (ar.result == null) {
1536 loge("getForbiddenPlmns: Empty response");
1537 } else {
1538 loge("getForbiddenPlmns: Unknown exception");
1539 }
1540 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001541 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001542 break;
1543
1544 case CMD_GET_FORBIDDEN_PLMNS:
1545 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001546 uiccPort = getUiccPortFromRequest(request);
1547 if (uiccPort == null) {
1548 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001549 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001550 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001551 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001552 break;
1553 }
1554 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001555 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001556 if (uiccApp == null) {
1557 loge("getForbiddenPlmns() no app with specified type -- "
1558 + appType);
1559 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001560 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001561 break;
1562 } else {
1563 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1564 + " specified type -- " + appType);
1565 }
1566 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1567 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1568 onCompleted);
1569 break;
1570
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001571 case CMD_SWITCH_SLOTS:
1572 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001573 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001574 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001575 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001576 break;
1577
1578 case EVENT_SWITCH_SLOTS_DONE:
1579 ar = (AsyncResult) msg.obj;
1580 request = (MainThreadRequest) ar.userObj;
1581 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001582 notifyRequester(request);
1583 break;
1584 case CMD_GET_NETWORK_SELECTION_MODE:
1585 request = (MainThreadRequest) msg.obj;
1586 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1587 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1588 break;
1589
1590 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1591 ar = (AsyncResult) msg.obj;
1592 request = (MainThreadRequest) ar.userObj;
1593 if (ar.exception != null) {
1594 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1595 } else {
1596 int mode = ((int[]) ar.result)[0];
1597 if (mode == 0) {
1598 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1599 } else {
1600 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1601 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001602 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001603 notifyRequester(request);
1604 break;
1605 case CMD_GET_CDMA_ROAMING_MODE:
1606 request = (MainThreadRequest) msg.obj;
1607 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1608 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1609 break;
1610 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1611 ar = (AsyncResult) msg.obj;
1612 request = (MainThreadRequest) ar.userObj;
1613 if (ar.exception != null) {
1614 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1615 } else {
1616 request.result = ((int[]) ar.result)[0];
1617 }
1618 notifyRequester(request);
1619 break;
1620 case CMD_SET_CDMA_ROAMING_MODE:
1621 request = (MainThreadRequest) msg.obj;
1622 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1623 int mode = (int) request.argument;
1624 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1625 break;
1626 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1627 ar = (AsyncResult) msg.obj;
1628 request = (MainThreadRequest) ar.userObj;
1629 request.result = ar.exception == null;
1630 notifyRequester(request);
1631 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001632 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1633 request = (MainThreadRequest) msg.obj;
1634 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1635 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1636 break;
1637 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1638 ar = (AsyncResult) msg.obj;
1639 request = (MainThreadRequest) ar.userObj;
1640 if (ar.exception != null) {
1641 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1642 } else {
1643 request.result = ((int[]) ar.result)[0];
1644 }
1645 notifyRequester(request);
1646 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001647 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1648 request = (MainThreadRequest) msg.obj;
1649 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1650 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001651 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1652 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001653 break;
1654 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1655 ar = (AsyncResult) msg.obj;
1656 request = (MainThreadRequest) ar.userObj;
1657 request.result = ar.exception == null;
1658 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001659 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001660 case CMD_GET_ALL_CELL_INFO:
1661 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001662 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001663 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001664 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001665 case EVENT_GET_ALL_CELL_INFO_DONE:
1666 ar = (AsyncResult) msg.obj;
1667 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001668 // If a timeout occurs, the response will be null
1669 request.result = (ar.exception == null && ar.result != null)
1670 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001671 synchronized (request) {
1672 request.notifyAll();
1673 }
1674 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001675 case CMD_REQUEST_CELL_INFO_UPDATE:
1676 request = (MainThreadRequest) msg.obj;
1677 request.phone.requestCellInfoUpdate(request.workSource,
1678 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1679 break;
1680 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1681 ar = (AsyncResult) msg.obj;
1682 request = (MainThreadRequest) ar.userObj;
1683 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1684 try {
1685 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001686 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001687 cb.onError(
1688 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1689 ar.exception.getClass().getName(),
1690 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001691 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001692 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001693 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001694 } else {
1695 // use the result as returned
1696 cb.onCellInfo((List<CellInfo>) ar.result);
1697 }
1698 } catch (RemoteException re) {
1699 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1700 }
1701 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001702 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001703 request = (MainThreadRequest) msg.obj;
1704 WorkSource ws = (WorkSource) request.argument;
1705 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001706 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001707 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001708 }
1709 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001710 ar = (AsyncResult) msg.obj;
1711 request = (MainThreadRequest) ar.userObj;
1712 if (ar.exception == null) {
1713 request.result = ar.result;
1714 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001715 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001716 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001717 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001718 }
1719
1720 synchronized (request) {
1721 request.notifyAll();
1722 }
1723 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001724 }
chen xu6dac5ab2018-10-26 17:39:23 -07001725 case CMD_MODEM_REBOOT:
1726 request = (MainThreadRequest) msg.obj;
1727 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001728 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001729 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001730 case EVENT_CMD_MODEM_REBOOT_DONE:
1731 handleNullReturnEvent(msg, "rebootModem");
1732 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001733 case CMD_REQUEST_ENABLE_MODEM:
1734 request = (MainThreadRequest) msg.obj;
1735 boolean enable = (boolean) request.argument;
1736 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001737 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001738 PhoneConfigurationManager.getInstance()
1739 .enablePhone(request.phone, enable, onCompleted);
1740 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001741 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001742 ar = (AsyncResult) msg.obj;
1743 request = (MainThreadRequest) ar.userObj;
1744 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001745 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001746 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001747 if ((boolean) request.result) {
1748 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1749 updateModemStateMetrics();
1750 } else {
1751 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1752 + ar.exception);
1753 }
1754 notifyRequester(request);
1755 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001756 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001757 case CMD_GET_MODEM_STATUS:
1758 request = (MainThreadRequest) msg.obj;
1759 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1760 PhoneConfigurationManager.getInstance()
1761 .getPhoneStatusFromModem(request.phone, onCompleted);
1762 break;
1763 case EVENT_GET_MODEM_STATUS_DONE:
1764 ar = (AsyncResult) msg.obj;
1765 request = (MainThreadRequest) ar.userObj;
1766 int id = request.phone.getPhoneId();
1767 if (ar.exception == null && ar.result != null) {
1768 request.result = ar.result;
1769 //update the cache as modem status has changed
1770 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1771 (boolean) request.result);
1772 } else {
1773 // Return true if modem status cannot be retrieved. For most cases,
1774 // modem status is on. And for older version modems, GET_MODEM_STATUS
1775 // and disable modem are not supported. Modem is always on.
1776 // TODO: this should be fixed in R to support a third
1777 // status UNKNOWN b/131631629
1778 request.result = true;
1779 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1780 + ar.exception);
1781 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001782 notifyRequester(request);
1783 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001784 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1785 request = (MainThreadRequest) msg.obj;
1786 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1787 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1788 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1789 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1790 break;
1791 }
1792 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1793 ar = (AsyncResult) msg.obj;
1794 request = (MainThreadRequest) ar.userObj;
1795 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1796 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1797 args.second.accept(ar.exception == null);
1798 notifyRequester(request);
1799 break;
1800 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001801 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1802 request = (MainThreadRequest) msg.obj;
1803 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1804 Phone phone = getPhoneFromRequest(request);
1805 if (phone != null) {
1806 phone.getSystemSelectionChannels(onCompleted);
1807 } else {
1808 loge("getSystemSelectionChannels: No phone object");
1809 request.result = new ArrayList<RadioAccessSpecifier>();
1810 notifyRequester(request);
1811 }
1812 break;
1813 }
1814 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1815 ar = (AsyncResult) msg.obj;
1816 request = (MainThreadRequest) ar.userObj;
1817 if (ar.exception == null && ar.result != null) {
1818 request.result = ar.result;
1819 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001820 request.result = new IllegalStateException(
1821 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001822 if (ar.result == null) {
1823 loge("getSystemSelectionChannels: Empty response");
1824 } else {
1825 loge("getSystemSelectionChannels: Unknown exception");
1826 }
1827 }
1828 notifyRequester(request);
1829 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001830 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1831 ar = (AsyncResult) msg.obj;
1832 request = (MainThreadRequest) ar.userObj;
1833 if (ar.exception == null && ar.result != null) {
1834 request.result = ar.result;
1835 } else {
1836 request.result = -1;
1837 loge("Failed to set Forbidden Plmns");
1838 if (ar.result == null) {
1839 loge("setForbidenPlmns: Empty response");
1840 } else if (ar.exception != null) {
1841 loge("setForbiddenPlmns: Exception: " + ar.exception);
1842 request.result = -1;
1843 } else {
1844 loge("setForbiddenPlmns: Unknown exception");
1845 }
1846 }
1847 notifyRequester(request);
1848 break;
1849 case CMD_SET_FORBIDDEN_PLMNS:
1850 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001851 uiccPort = getUiccPortFromRequest(request);
1852 if (uiccPort == null) {
1853 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001854 request.result = -1;
1855 notifyRequester(request);
1856 break;
1857 }
1858 Pair<Integer, List<String>> setFplmnsArgs =
1859 (Pair<Integer, List<String>>) request.argument;
1860 appType = setFplmnsArgs.first;
1861 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001862 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001863 if (uiccApp == null) {
1864 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1865 request.result = -1;
1866 loge("Failed to get UICC App");
1867 notifyRequester(request);
1868 } else {
1869 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1870 ((SIMRecords) uiccApp.getIccRecords())
1871 .setForbiddenPlmns(onCompleted, fplmns);
1872 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001873 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001874 case CMD_ERASE_MODEM_CONFIG:
1875 request = (MainThreadRequest) msg.obj;
1876 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1877 defaultPhone.eraseModemConfig(onCompleted);
1878 break;
1879 case EVENT_ERASE_MODEM_CONFIG_DONE:
1880 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001881 break;
zoey chene02881a2019-12-30 16:11:23 +08001882
Kai Shif70f46f2021-03-03 13:59:46 -08001883 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1884 request = (MainThreadRequest) msg.obj;
1885 request.result = defaultPhone.eraseDataInSharedPreferences();
1886 notifyRequester(request);
1887 break;
1888
zoey chene02881a2019-12-30 16:11:23 +08001889 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1890 request = (MainThreadRequest) msg.obj;
1891 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1892 Pair<String, String> changed = (Pair<String, String>) request.argument;
1893 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1894 changed.first, changed.second, onCompleted);
1895 break;
1896 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1897 ar = (AsyncResult) msg.obj;
1898 request = (MainThreadRequest) ar.userObj;
1899 if (ar.exception == null) {
1900 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001901 // If the operation is successful, update the PIN storage
1902 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1903 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001904 UiccController.getInstance().getPinStorage()
1905 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001906 } else {
1907 request.result = msg.arg1;
1908 }
1909 notifyRequester(request);
1910 break;
1911
Michele Berionne5e411512020-11-13 02:36:59 +00001912 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001913 request = (MainThreadRequest) msg.obj;
1914 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1915 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1916 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1917 enabled.first, enabled.second, onCompleted);
1918 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001919 }
zoey chene02881a2019-12-30 16:11:23 +08001920 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1921 ar = (AsyncResult) msg.obj;
1922 request = (MainThreadRequest) ar.userObj;
1923 if (ar.exception == null) {
1924 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001925 // If the operation is successful, update the PIN storage
1926 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1927 int phoneId = getPhoneFromRequest(request).getPhoneId();
1928 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001929 UiccController.getInstance().getPinStorage()
1930 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001931 } else {
1932 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1933 }
zoey chene02881a2019-12-30 16:11:23 +08001934 } else {
1935 request.result = msg.arg1;
1936 }
Michele Berionne5e411512020-11-13 02:36:59 +00001937
1938
zoey chene02881a2019-12-30 16:11:23 +08001939 notifyRequester(request);
1940 break;
1941
Peter Wangdafb9ac2020-01-15 14:13:38 -08001942 case MSG_NOTIFY_USER_ACTIVITY:
1943 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001944 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001945 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1946 getDefaultPhone().getContext().sendBroadcastAsUser(
1947 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1948 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001949
1950 case CMD_SET_DATA_THROTTLING: {
1951 request = (MainThreadRequest) msg.obj;
1952 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1953 DataThrottlingRequest dataThrottlingRequest =
1954 (DataThrottlingRequest) request.argument;
1955 Phone phone = getPhoneFromRequest(request);
1956 if (phone != null) {
1957 phone.setDataThrottling(onCompleted,
1958 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1959 dataThrottlingRequest.getCompletionDurationMillis());
1960 } else {
1961 loge("setDataThrottling: No phone object");
1962 request.result =
1963 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1964 notifyRequester(request);
1965 }
1966
1967 break;
1968 }
1969 case EVENT_SET_DATA_THROTTLING_DONE:
1970 ar = (AsyncResult) msg.obj;
1971 request = (MainThreadRequest) ar.userObj;
1972
1973 if (ar.exception == null) {
1974 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1975 } else if (ar.exception instanceof CommandException) {
1976 loge("setDataThrottling: CommandException: " + ar.exception);
1977 CommandException.Error error =
1978 ((CommandException) (ar.exception)).getCommandError();
1979
1980 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1981 request.result = TelephonyManager
1982 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1983 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1984 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001985 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1986 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001987 } else {
1988 request.result =
1989 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1990 }
1991 } else {
1992 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1993 }
1994 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1995 notifyRequester(request);
1996 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001997
1998 case CMD_SET_SIM_POWER: {
1999 request = (MainThreadRequest) msg.obj;
2000 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2001 request = (MainThreadRequest) msg.obj;
2002 int stateToSet =
2003 ((Pair<Integer, IIntegerConsumer>)
2004 request.argument).first;
2005 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2006 break;
2007 }
2008 case EVENT_SET_SIM_POWER_DONE: {
2009 ar = (AsyncResult) msg.obj;
2010 request = (MainThreadRequest) ar.userObj;
2011 IIntegerConsumer callback =
2012 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2013 if (ar.exception != null) {
2014 loge("setSimPower exception: " + ar.exception);
2015 int errorCode = TelephonyManager.CallForwardingInfoCallback
2016 .RESULT_ERROR_UNKNOWN;
2017 if (ar.exception instanceof CommandException) {
2018 CommandException.Error error =
2019 ((CommandException) (ar.exception)).getCommandError();
2020 if (error == CommandException.Error.SIM_ERR) {
2021 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2022 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2023 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2024 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2025 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2026 } else {
2027 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2028 }
2029 }
2030 try {
2031 callback.accept(errorCode);
2032 } catch (RemoteException e) {
2033 // Ignore if the remote process is no longer available to call back.
2034 Log.w(LOG_TAG, "setSimPower: callback not available.");
2035 }
2036 } else {
2037 try {
2038 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2039 } catch (RemoteException e) {
2040 // Ignore if the remote process is no longer available to call back.
2041 Log.w(LOG_TAG, "setSimPower: callback not available.");
2042 }
2043 }
2044 break;
2045 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002046 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2047 request = (MainThreadRequest) msg.obj;
2048
2049 final Phone phone = getPhoneFromRequest(request);
2050 if (phone == null || phone.getServiceStateTracker() == null) {
2051 request.result = new IllegalStateException("Phone or SST is null");
2052 notifyRequester(request);
2053 break;
2054 }
2055
2056 Pair<Integer, SignalStrengthUpdateRequest> pair =
2057 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2058 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2059 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002060 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002061 request.subId, pair.first /*callingUid*/,
2062 pair.second /*request*/, onCompleted);
2063 break;
2064 }
2065 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2066 ar = (AsyncResult) msg.obj;
2067 request = (MainThreadRequest) ar.userObj;
2068 // request.result will be the exception of ar if present, true otherwise.
2069 // Be cautious not to leave result null which will wait() forever
2070 request.result = ar.exception != null ? ar.exception : true;
2071 notifyRequester(request);
2072 break;
2073 }
2074 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2075 request = (MainThreadRequest) msg.obj;
2076
2077 Phone phone = getPhoneFromRequest(request);
2078 if (phone == null || phone.getServiceStateTracker() == null) {
2079 request.result = new IllegalStateException("Phone or SST is null");
2080 notifyRequester(request);
2081 break;
2082 }
2083
2084 Pair<Integer, SignalStrengthUpdateRequest> pair =
2085 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2086 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2087 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002088 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002089 request.subId, pair.first /*callingUid*/,
2090 pair.second /*request*/, onCompleted);
2091 break;
2092 }
2093 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2094 ar = (AsyncResult) msg.obj;
2095 request = (MainThreadRequest) ar.userObj;
2096 request.result = ar.exception != null ? ar.exception : true;
2097 notifyRequester(request);
2098 break;
2099 }
Jordan Liu109698e2020-11-24 14:50:34 -08002100
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002101 case CMD_GET_SLICING_CONFIG: {
2102 request = (MainThreadRequest) msg.obj;
2103 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2104 request.phone.getSlicingConfig(onCompleted);
2105 break;
2106 }
2107 case EVENT_GET_SLICING_CONFIG_DONE: {
2108 ar = (AsyncResult) msg.obj;
2109 request = (MainThreadRequest) ar.userObj;
2110 ResultReceiver result = (ResultReceiver) request.argument;
2111
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002112 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002113 Bundle bundle = new Bundle();
2114 int resultCode = 0;
2115 if (ar.exception != null) {
2116 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2117 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002118 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002119 } else if (ar.result == null) {
2120 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002121 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002122 } else {
2123 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002124 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2125 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002126 }
2127
2128 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002129 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002130 }
2131 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2132 result.send(resultCode, bundle);
2133 notifyRequester(request);
2134 break;
2135 }
2136
Michele Berionne5e411512020-11-13 02:36:59 +00002137 case CMD_PREPARE_UNATTENDED_REBOOT:
2138 request = (MainThreadRequest) msg.obj;
2139 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002140 UiccController.getInstance().getPinStorage()
2141 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002142 notifyRequester(request);
2143 break;
2144
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002145 default:
2146 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2147 break;
2148 }
2149 }
Jake Hambye994d462014-02-03 13:10:13 -08002150
Pengquan Menga1bb6272018-09-06 09:59:22 -07002151 private void notifyRequester(MainThreadRequest request) {
2152 synchronized (request) {
2153 request.notifyAll();
2154 }
2155 }
2156
Jake Hambye994d462014-02-03 13:10:13 -08002157 private void handleNullReturnEvent(Message msg, String command) {
2158 AsyncResult ar = (AsyncResult) msg.obj;
2159 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2160 if (ar.exception == null) {
2161 request.result = true;
2162 } else {
2163 request.result = false;
2164 if (ar.exception instanceof CommandException) {
2165 loge(command + ": CommandException: " + ar.exception);
2166 } else {
2167 loge(command + ": Unknown exception");
2168 }
2169 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002170 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 }
2173
2174 /**
2175 * Posts the specified command to be executed on the main thread,
2176 * waits for the request to complete, and returns the result.
2177 * @see #sendRequestAsync
2178 */
2179 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002180 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2181 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002182 }
2183
2184 /**
2185 * Posts the specified command to be executed on the main thread,
2186 * waits for the request to complete, and returns the result.
2187 * @see #sendRequestAsync
2188 */
2189 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2190 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002191 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002192 }
2193
2194 /**
2195 * Posts the specified command to be executed on the main thread,
2196 * waits for the request to complete, and returns the result.
2197 * @see #sendRequestAsync
2198 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002199 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002200 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2201 }
2202
2203 /**
2204 * Posts the specified command to be executed on the main thread,
2205 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2206 * if not timeout or null otherwise.
2207 * @see #sendRequestAsync
2208 */
2209 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2210 long timeoutInMs) {
2211 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002212 }
2213
2214 /**
2215 * Posts the specified command to be executed on the main thread,
2216 * waits for the request to complete, and returns the result.
2217 * @see #sendRequestAsync
2218 */
Nathan Harold92bed182018-10-12 18:16:49 -07002219 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002220 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002221 }
2222
2223 /**
2224 * Posts the specified command to be executed on the main thread,
2225 * waits for the request to complete, and returns the result.
2226 * @see #sendRequestAsync
2227 */
2228 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002229 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2230 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002231 }
2232
2233 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002234 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2235 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2236 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002237 * @see #sendRequestAsync
2238 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002239 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2240 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2242 throw new RuntimeException("This method will deadlock if called from the main thread.");
2243 }
2244
Nathan Harold92bed182018-10-12 18:16:49 -07002245 MainThreadRequest request = null;
2246 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2247 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2248 } else if (phone != null) {
2249 request = new MainThreadRequest(argument, phone, workSource);
2250 } else {
2251 request = new MainThreadRequest(argument, subId, workSource);
2252 }
2253
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 Message msg = mMainThreadHandler.obtainMessage(command, request);
2255 msg.sendToTarget();
2256
Rambo Wang0f050d82021-02-12 11:43:36 -08002257
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002259 if (timeoutInMs >= 0) {
2260 // Wait for at least timeoutInMs before returning null request result
2261 long now = SystemClock.elapsedRealtime();
2262 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002263 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002264 try {
2265 request.wait(deadline - now);
2266 } catch (InterruptedException e) {
2267 // Do nothing, go back and check if request is completed or timeout
2268 } finally {
2269 now = SystemClock.elapsedRealtime();
2270 }
2271 }
2272 } else {
2273 // Wait for the request to complete
2274 while (request.result == null) {
2275 try {
2276 request.wait();
2277 } catch (InterruptedException e) {
2278 // Do nothing, go back and wait until the request is complete
2279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 }
2281 }
2282 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002283 if (request.result == null) {
2284 Log.wtf(LOG_TAG,
2285 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 return request.result;
2288 }
2289
2290 /**
2291 * Asynchronous ("fire and forget") version of sendRequest():
2292 * Posts the specified command to be executed on the main thread, and
2293 * returns immediately.
2294 * @see #sendRequest
2295 */
2296 private void sendRequestAsync(int command) {
2297 mMainThreadHandler.sendEmptyMessage(command);
2298 }
2299
2300 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002301 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002302 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002303 */
2304 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002305 sendRequestAsync(command, argument, null, null);
2306 }
2307
2308 /**
2309 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2310 * @see {@link #sendRequest(int,Object)}
2311 */
2312 private void sendRequestAsync(
2313 int command, Object argument, Phone phone, WorkSource workSource) {
2314 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002315 Message msg = mMainThreadHandler.obtainMessage(command, request);
2316 msg.sendToTarget();
2317 }
2318
2319 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 * Initialize the singleton PhoneInterfaceManager instance.
2321 * This is only done once, at startup, from PhoneApp.onCreate().
2322 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002323 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 synchronized (PhoneInterfaceManager.class) {
2325 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002326 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 } else {
2328 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2329 }
2330 return sInstance;
2331 }
2332 }
2333
2334 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002335 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002338 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002339 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002341 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002343 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002344 mTelephonySharedPreferences =
2345 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002346 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002347 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002348 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002349 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002350 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukiermand6cae882022-12-29 12:02:31 -05002351 mTelephony2gUpdater = new Telephony2gUpdater(mApp);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002352 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 publish();
2354 }
2355
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002356 private Phone getDefaultPhone() {
2357 Phone thePhone = getPhone(getDefaultSubscription());
2358 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2359 }
2360
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 private void publish() {
2362 if (DBG) log("publish: " + this);
2363
Peter Wangc035ce42020-01-08 21:00:22 -08002364 TelephonyFrameworkInitializer
2365 .getTelephonyServiceManager()
2366 .getTelephonyServiceRegisterer()
2367 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 }
2369
Stuart Scott584921c2015-01-15 17:10:34 -08002370 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002371 if (request.phone != null) {
2372 return request.phone;
2373 } else {
2374 return getPhoneFromSubId(request.subId);
2375 }
2376 }
2377
2378 private Phone getPhoneFromSubId(int subId) {
2379 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2380 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002381 }
2382
Rambo Wange53e07d2022-05-10 13:01:13 -07002383 @Nullable
2384 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002385 Phone phone = getPhoneFromRequest(request);
2386 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002387 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002388 }
2389
Wink Saville36469e72014-06-11 15:17:00 -07002390 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002391 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002392 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002393 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394
Kai Shif70f46f2021-03-03 13:59:46 -08002395 private void sendEraseModemConfig(@NonNull Phone phone) {
2396 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2397 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2398 }
2399
2400 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2401 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2402 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002403 }
2404
Peter Wang44b186e2020-01-13 23:33:09 -08002405 private boolean isImsAvailableOnDevice() {
2406 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2407 if (pm == null) {
2408 // For some reason package manger is not available.. This will fail internally anyway,
2409 // so do not throw error and allow.
2410 return true;
2411 }
2412 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2413 }
2414
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002416 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002417 }
2418
Wink Savilleb564aae2014-10-23 10:18:09 -07002419 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420 if (DBG) log("dial: " + number);
2421 // No permission check needed here: This is just a wrapper around the
2422 // ACTION_DIAL intent, which is available to any app since it puts up
2423 // the UI before it does anything.
2424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002425 final long identity = Binder.clearCallingIdentity();
2426 try {
2427 String url = createTelUrl(number);
2428 if (url == null) {
2429 return;
2430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002432 // PENDING: should we just silently fail if phone is offhook or ringing?
2433 PhoneConstants.State state = mCM.getState(subId);
2434 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2435 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2436 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2437 mApp.startActivity(intent);
2438 }
2439 } finally {
2440 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 }
2442 }
2443
2444 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002445 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002446 }
2447
Wink Savilleb564aae2014-10-23 10:18:09 -07002448 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 if (DBG) log("call: " + number);
2450
2451 // This is just a wrapper around the ACTION_CALL intent, but we still
2452 // need to do a permission check since we're calling startActivity()
2453 // from the context of the phone app.
2454 enforceCallPermission();
2455
Jordan Liu1617b712019-07-10 15:06:26 -07002456 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 != AppOpsManager.MODE_ALLOWED) {
2458 return;
2459 }
2460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002461 final long identity = Binder.clearCallingIdentity();
2462 try {
2463 String url = createTelUrl(number);
2464 if (url == null) {
2465 return;
2466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002468 boolean isValid = false;
2469 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2470 if (slist != null) {
2471 for (SubscriptionInfo subInfoRecord : slist) {
2472 if (subInfoRecord.getSubscriptionId() == subId) {
2473 isValid = true;
2474 break;
2475 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002476 }
Wink Saville08874612014-08-31 19:19:58 -07002477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478 if (!isValid) {
2479 return;
2480 }
Wink Saville08874612014-08-31 19:19:58 -07002481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2483 intent.putExtra(SUBSCRIPTION_KEY, subId);
2484 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2485 mApp.startActivity(intent);
2486 } finally {
2487 Binder.restoreCallingIdentity(identity);
2488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
2490
Wink Savilleb564aae2014-10-23 10:18:09 -07002491 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002492 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002493 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2494 }
2495
Wink Savilleb564aae2014-10-23 10:18:09 -07002496 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002497 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002498 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2499 }
2500
Wink Savilleb564aae2014-10-23 10:18:09 -07002501 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503
2504 final long identity = Binder.clearCallingIdentity();
2505 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002506 Phone phone = getPhone(subId);
2507 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508 checkSimPin.start();
2509 return checkSimPin.unlockSim(null, pin);
2510 } finally {
2511 Binder.restoreCallingIdentity(identity);
2512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 }
2514
Wink Savilleb564aae2014-10-23 10:18:09 -07002515 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002517
2518 final long identity = Binder.clearCallingIdentity();
2519 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002520 Phone phone = getPhone(subId);
2521 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002522 checkSimPuk.start();
2523 return checkSimPuk.unlockSim(puk, pin);
2524 } finally {
2525 Binder.restoreCallingIdentity(identity);
2526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 }
2528
2529 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002530 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 * a synchronous one.
2532 */
2533 private static class UnlockSim extends Thread {
2534
2535 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002536 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537
2538 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002539 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2540 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541
2542 // For replies from SimCard interface
2543 private Handler mHandler;
2544
2545 // For async handler to identify request type
2546 private static final int SUPPLY_PIN_COMPLETE = 100;
2547
Michele Berionne5e411512020-11-13 02:36:59 +00002548 UnlockSim(int phoneId, IccCard simCard) {
2549 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002550 mSimCard = simCard;
2551 }
2552
2553 @Override
2554 public void run() {
2555 Looper.prepare();
2556 synchronized (UnlockSim.this) {
2557 mHandler = new Handler() {
2558 @Override
2559 public void handleMessage(Message msg) {
2560 AsyncResult ar = (AsyncResult) msg.obj;
2561 switch (msg.what) {
2562 case SUPPLY_PIN_COMPLETE:
2563 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2564 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002565 mRetryCount = msg.arg1;
2566 if (ar.exception != null) {
2567 if (ar.exception instanceof CommandException &&
2568 ((CommandException)(ar.exception)).getCommandError()
2569 == CommandException.Error.PASSWORD_INCORRECT) {
2570 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002571 } //When UiccCardApp dispose,handle message and return exception
2572 else if (ar.exception instanceof CommandException &&
2573 ((CommandException) (ar.exception)).getCommandError()
2574 == CommandException.Error.ABORTED) {
2575 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002576 } else {
2577 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2578 }
2579 } else {
2580 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 mDone = true;
2583 UnlockSim.this.notifyAll();
2584 }
2585 break;
2586 }
2587 }
2588 };
2589 UnlockSim.this.notifyAll();
2590 }
2591 Looper.loop();
2592 }
2593
2594 /*
2595 * Use PIN or PUK to unlock SIM card
2596 *
2597 * If PUK is null, unlock SIM card with PIN
2598 *
2599 * If PUK is not null, unlock SIM card with PUK and set PIN code
2600 */
Wink Saville9de0f752013-10-22 19:04:03 -07002601 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602
2603 while (mHandler == null) {
2604 try {
2605 wait();
2606 } catch (InterruptedException e) {
2607 Thread.currentThread().interrupt();
2608 }
2609 }
2610 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2611
2612 if (puk == null) {
2613 mSimCard.supplyPin(pin, callback);
2614 } else {
2615 mSimCard.supplyPuk(puk, pin, callback);
2616 }
2617
2618 while (!mDone) {
2619 try {
2620 Log.d(LOG_TAG, "wait for done");
2621 wait();
2622 } catch (InterruptedException e) {
2623 // Restore the interrupted status
2624 Thread.currentThread().interrupt();
2625 }
2626 }
2627 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002628 int[] resultArray = new int[2];
2629 resultArray[0] = mResult;
2630 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002631
2632 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002633 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002634 }
2635
Wink Saville9de0f752013-10-22 19:04:03 -07002636 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002637 }
2638 }
2639
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002640 /**
2641 * This method has been removed due to privacy and stability concerns.
2642 */
2643 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002644 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002645 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2646 return;
Wink Saville36469e72014-06-11 15:17:00 -07002647 }
2648
Nathan Harold1f889d82020-06-04 17:05:26 -07002649 @Override
2650 public void updateServiceLocationWithPackageName(String callingPackage) {
2651 mApp.getSystemService(AppOpsManager.class)
2652 .checkPackage(Binder.getCallingUid(), callingPackage);
2653
Nathan Haroldf096d982020-11-18 17:18:06 -08002654 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002655 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2656 // Callers targeting S have no business invoking this method.
2657 return;
2658 }
2659
2660 LocationAccessPolicy.LocationPermissionResult locationResult =
2661 LocationAccessPolicy.checkLocationPermission(mApp,
2662 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2663 .setCallingPackage(callingPackage)
2664 .setCallingFeatureId(null)
2665 .setCallingPid(Binder.getCallingPid())
2666 .setCallingUid(Binder.getCallingUid())
2667 .setMethod("updateServiceLocation")
2668 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2669 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2670 .build());
2671 // Apps that lack location permission have no business calling this method;
2672 // however, because no permission was declared in the public API, denials must
2673 // all be "soft".
2674 switch (locationResult) {
2675 case DENIED_HARD: /* fall through */
2676 case DENIED_SOFT:
2677 return;
2678 }
2679
2680 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681 final long identity = Binder.clearCallingIdentity();
2682 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002683 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002685 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 }
2687 } finally {
2688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 }
2691
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002692 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002693 @Override
2694 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002695 return isRadioOnWithFeature(callingPackage, null);
2696 }
2697
2698
2699 @Override
2700 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2701 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2702 callingFeatureId);
2703 }
2704
2705 @Deprecated
2706 @Override
2707 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2708 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002709 }
2710
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002711 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002712 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2713 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002714 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002715 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002716 return false;
2717 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718
2719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 return isRadioOnForSubscriber(subId);
2722 } finally {
2723 Binder.restoreCallingIdentity(identity);
2724 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002725 }
2726
2727 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002728 final long identity = Binder.clearCallingIdentity();
2729 try {
2730 final Phone phone = getPhone(subId);
2731 if (phone != null) {
2732 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2733 } else {
2734 return false;
2735 }
2736 } finally {
2737 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739 }
2740
2741 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002742 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 }
Wink Saville36469e72014-06-11 15:17:00 -07002744
Wink Savilleb564aae2014-10-23 10:18:09 -07002745 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747
2748 final long identity = Binder.clearCallingIdentity();
2749 try {
2750 final Phone phone = getPhone(subId);
2751 if (phone != null) {
2752 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2753 }
2754 } finally {
2755 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002756 }
Wink Saville36469e72014-06-11 15:17:00 -07002757 }
2758
2759 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002760 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002761 }
2762
Wink Savilleb564aae2014-10-23 10:18:09 -07002763 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002764 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765
2766 final long identity = Binder.clearCallingIdentity();
2767 try {
2768 final Phone phone = getPhone(subId);
2769 if (phone == null) {
2770 return false;
2771 }
2772 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2773 toggleRadioOnOffForSubscriber(subId);
2774 }
2775 return true;
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
Wink Saville36469e72014-06-11 15:17:00 -07002780
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002781 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002782 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002783 /*
2784 * If any of the Radios are available, it will need to be
2785 * shutdown. So return true if any Radio is available.
2786 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 final long identity = Binder.clearCallingIdentity();
2788 try {
2789 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2790 Phone phone = PhoneFactory.getPhone(i);
2791 if (phone != null && phone.isRadioAvailable()) return true;
2792 }
2793 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2794 return false;
2795 } finally {
2796 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002797 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002798 }
2799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002800 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002801 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802 enforceModifyPermission();
2803
2804 final long identity = Binder.clearCallingIdentity();
2805 try {
2806 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2807 logv("Shutting down Phone " + i);
2808 shutdownRadioUsingPhoneId(i);
2809 }
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002812 }
2813 }
2814
2815 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002816 Phone phone = PhoneFactory.getPhone(phoneId);
2817 if (phone != null && phone.isRadioAvailable()) {
2818 phone.shutdownRadio();
2819 }
2820 }
2821
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002822 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002823 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824
2825 final long identity = Binder.clearCallingIdentity();
2826 try {
2827 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2828 if (defaultPhone != null) {
2829 defaultPhone.setRadioPower(turnOn);
2830 return true;
2831 } else {
2832 loge("There's no default phone.");
2833 return false;
2834 }
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002837 }
Wink Saville36469e72014-06-11 15:17:00 -07002838 }
2839
Wink Savilleb564aae2014-10-23 10:18:09 -07002840 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002842
2843 final long identity = Binder.clearCallingIdentity();
2844 try {
2845 final Phone phone = getPhone(subId);
2846 if (phone != null) {
2847 phone.setRadioPower(turnOn);
2848 return true;
2849 } else {
2850 return false;
2851 }
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002854 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855 }
2856
Wink Saville36469e72014-06-11 15:17:00 -07002857 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002859 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002861
2862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 int subId = mSubscriptionController.getDefaultDataSubId();
2865 final Phone phone = getPhone(subId);
2866 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002867 phone.getDataSettingsManager().setDataEnabled(
2868 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869 return true;
2870 } else {
2871 return false;
2872 }
2873 } finally {
2874 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 }
2877
Wink Saville36469e72014-06-11 15:17:00 -07002878 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002879 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002880 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002881 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882
2883 final long identity = Binder.clearCallingIdentity();
2884 try {
2885 int subId = mSubscriptionController.getDefaultDataSubId();
2886 final Phone phone = getPhone(subId);
2887 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002888 phone.getDataSettingsManager().setDataEnabled(
2889 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 return true;
2891 } else {
2892 return false;
2893 }
2894 } finally {
2895 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002897 }
2898
Sanket Padawe356d7632015-06-22 14:03:32 -07002899 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002900 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 final Phone phone = getPhone(subId);
2904 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07002905 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 } else {
2907 return false;
2908 }
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 }
2913
2914 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002915 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002916 }
2917
pkanwarae03a6b2016-11-06 20:37:09 -08002918 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919 enforceCallPermission();
2920
2921 final long identity = Binder.clearCallingIdentity();
2922 try {
2923 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2924 return;
2925 }
2926 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2927 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
2930 }
pkanwar32d516d2016-10-14 19:37:38 -07002931 };
2932
Wink Savilleb564aae2014-10-23 10:18:09 -07002933 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002934 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002935
2936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2939 return false;
2940 }
2941 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2942 } finally {
2943 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002945 }
2946
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002947 /**
2948 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2949 * tag on getCallState Binder call.
2950 */
2951 @Deprecated
2952 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002954 if (CompatChanges.isChangeEnabled(
2955 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2956 Binder.getCallingUid())) {
2957 // Do not allow this API to be called on API version 31+, it should only be
2958 // called on old apps using this Binder call directly.
2959 throw new SecurityException("This method can only be used for applications "
2960 + "targeting API version 30 or less.");
2961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962 final long identity = Binder.clearCallingIdentity();
2963 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002964 Phone phone = getPhone(getDefaultSubscription());
2965 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2966 PhoneConstantConversions.convertCallState(phone.getState());
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
2970 }
2971
2972 @Override
2973 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2974 if (CompatChanges.isChangeEnabled(
2975 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2976 Binder.getCallingUid())) {
2977 // Check READ_PHONE_STATE for API version 31+
2978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2979 featureId, "getCallStateForSubscription")) {
2980 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2981 + "targeting API level 31+.");
2982 }
2983 }
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2988 PhoneConstantConversions.convertCallState(phone.getState());
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002992 }
2993
Sanket Padawe356d7632015-06-22 14:03:32 -07002994 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002995 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002996 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2997 }
2998
2999 @Override
3000 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 final long identity = Binder.clearCallingIdentity();
3002 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003003 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003004 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07003005 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006 } else {
3007 return PhoneConstantConversions.convertDataState(
3008 PhoneConstants.DataState.DISCONNECTED);
3009 }
3010 } finally {
3011 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003013 }
3014
Sanket Padawe356d7632015-06-22 14:03:32 -07003015 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003016 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003017 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3018 }
3019
3020 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003021 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 final long identity = Binder.clearCallingIdentity();
3023 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003024 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003026 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003027 } else {
3028 return TelephonyManager.DATA_ACTIVITY_NONE;
3029 }
3030 } finally {
3031 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003032 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003033 }
3034
3035 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003036 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003037 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003038 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003039
3040 LocationAccessPolicy.LocationPermissionResult locationResult =
3041 LocationAccessPolicy.checkLocationPermission(mApp,
3042 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3043 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003044 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003045 .setCallingPid(Binder.getCallingPid())
3046 .setCallingUid(Binder.getCallingUid())
3047 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003048 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003049 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3050 .build());
3051 switch (locationResult) {
3052 case DENIED_HARD:
3053 throw new SecurityException("Not allowed to access cell location");
3054 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003055 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3056 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003057 }
3058
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003059 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003063 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003064 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
Svetoslav64fad262015-04-14 14:35:21 -07003068 }
3069
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003070 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003071 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003072 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3073 // registered cell info, so return a NULL country instead.
3074 final long identity = Binder.clearCallingIdentity();
3075 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003076 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3077 // Get default phone in this case.
3078 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3079 }
Jack Yucda0c342022-11-17 22:47:32 -08003080 final int subId = mSubscriptionController.getSubId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003082 if (phone == null) return "";
3083 ServiceStateTracker sst = phone.getServiceStateTracker();
3084 if (sst == null) return "";
3085 LocaleTracker lt = sst.getLocaleTracker();
3086 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003087 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003088 } finally {
3089 Binder.restoreCallingIdentity(identity);
3090 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003091 }
3092
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003093 /**
3094 * This method was removed due to potential issues caused by performing partial
3095 * updates of service state, and lack of a credible use case.
3096 *
3097 * This has the ability to break the telephony implementation by disabling notification of
3098 * changes in device connectivity. DO NOT USE THIS!
3099 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003100 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003101 public void enableLocationUpdates() {
3102 mApp.enforceCallingOrSelfPermission(
3103 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104 }
3105
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003106 /**
3107 * This method was removed due to potential issues caused by performing partial
3108 * updates of service state, and lack of a credible use case.
3109 *
3110 * This has the ability to break the telephony implementation by disabling notification of
3111 * changes in device connectivity. DO NOT USE THIS!
3112 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003113 @Override
3114 public void disableLocationUpdates() {
3115 mApp.enforceCallingOrSelfPermission(
3116 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 }
3118
3119 @Override
3120 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003121 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3122 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003123 try {
3124 mApp.getSystemService(AppOpsManager.class)
3125 .checkPackage(Binder.getCallingUid(), callingPackage);
3126 } catch (SecurityException e) {
3127 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3128 throw e;
3129 }
3130
Nathan Haroldf096d982020-11-18 17:18:06 -08003131 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003132 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3133 throw new SecurityException(
3134 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3135 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003136
Jordan Liu1617b712019-07-10 15:06:26 -07003137 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003138 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3139 return null;
3140 }
Svetoslav64fad262015-04-14 14:35:21 -07003141
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003142 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003144 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003145 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003146
Nathan Haroldf180aac2018-06-01 18:43:55 -07003147 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3148 for (CellInfo ci : info) {
3149 if (ci instanceof CellInfoGsm) {
3150 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3151 } else if (ci instanceof CellInfoWcdma) {
3152 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3153 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003154 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003155 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003156 }
3157
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003158 private List<CellInfo> getCachedCellInfo() {
3159 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3160 for (Phone phone : PhoneFactory.getPhones()) {
3161 List<CellInfo> info = phone.getAllCellInfo();
3162 if (info != null) cellInfos.addAll(info);
3163 }
3164 return cellInfos;
3165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003166
3167 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003168 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003169 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003170 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003171
3172 LocationAccessPolicy.LocationPermissionResult locationResult =
3173 LocationAccessPolicy.checkLocationPermission(mApp,
3174 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3175 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003176 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003177 .setCallingPid(Binder.getCallingPid())
3178 .setCallingUid(Binder.getCallingUid())
3179 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003180 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003181 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3182 .build());
3183 switch (locationResult) {
3184 case DENIED_HARD:
3185 throw new SecurityException("Not allowed to access cell info");
3186 case DENIED_SOFT:
3187 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003188 }
3189
Nathan Haroldf096d982020-11-18 17:18:06 -08003190 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003191 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3192 return getCachedCellInfo();
3193 }
3194
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003195 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003196 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197 final long identity = Binder.clearCallingIdentity();
3198 try {
3199 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3200 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003201 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003202 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203 if (info != null) cellInfos.addAll(info);
3204 }
3205 return cellInfos;
3206 } finally {
3207 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003208 }
3209 }
3210
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003211 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003212 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3213 String callingFeatureId) {
3214 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3215 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003216 }
3217
3218 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003219 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3220 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003221 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003222 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003223 }
3224
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003225 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3226 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003227 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003228 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003229
3230 LocationAccessPolicy.LocationPermissionResult locationResult =
3231 LocationAccessPolicy.checkLocationPermission(mApp,
3232 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3233 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003234 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003235 .setCallingPid(Binder.getCallingPid())
3236 .setCallingUid(Binder.getCallingUid())
3237 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003238 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3239 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003240 .build());
3241 switch (locationResult) {
3242 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003243 if (TelephonyPermissions
3244 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003245 // Safetynet logging for b/154934934
3246 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3247 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003248 throw new SecurityException("Not allowed to access cell info");
3249 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003250 if (TelephonyPermissions
3251 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003252 // Safetynet logging for b/154934934
3253 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3254 }
Nathan Harold5320c422019-05-09 10:26:08 -07003255 try {
3256 cb.onCellInfo(new ArrayList<CellInfo>());
3257 } catch (RemoteException re) {
3258 // Drop without consequences
3259 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003260 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003261 }
3262
Nathan Harolda939a962019-05-09 10:13:47 -07003263
3264 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003265 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3266
3267 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3268 }
3269
3270 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003271 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003272 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003273 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274
3275 final long identity = Binder.clearCallingIdentity();
3276 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003277 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278 } finally {
3279 Binder.restoreCallingIdentity(identity);
3280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003281 }
3282
Shishir Agrawala9f32182016-04-12 12:00:16 -07003283 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003284 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003285 Phone phone = PhoneFactory.getPhone(slotIndex);
3286 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003287 return null;
3288 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003289 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003290 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003291 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003292 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003293 return null;
3294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003295
3296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 return phone.getImei();
3299 } finally {
3300 Binder.restoreCallingIdentity(identity);
3301 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003302 }
3303
3304 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003305 public String getTypeAllocationCodeForSlot(int slotIndex) {
3306 Phone phone = PhoneFactory.getPhone(slotIndex);
3307 String tac = null;
3308 if (phone != null) {
3309 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003310 try {
3311 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3312 } catch (IndexOutOfBoundsException e) {
3313 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3314 return null;
3315 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003316 }
3317 return tac;
3318 }
3319
3320 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003321 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003322 try {
3323 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3324 } catch (SecurityException se) {
3325 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3326 throw new SecurityException("Package " + callingPackage + " does not belong to "
3327 + Binder.getCallingUid());
3328 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003329 Phone phone = PhoneFactory.getPhone(slotIndex);
3330 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003331 return null;
3332 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003333
Jeff Davidson913390f2018-02-23 17:11:49 -08003334 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003335 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003336 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003337 return null;
3338 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003339
3340 final long identity = Binder.clearCallingIdentity();
3341 try {
3342 return phone.getMeid();
3343 } finally {
3344 Binder.restoreCallingIdentity(identity);
3345 }
Jack Yu2af8d712017-03-15 17:14:14 -07003346 }
3347
3348 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003349 public String getManufacturerCodeForSlot(int slotIndex) {
3350 Phone phone = PhoneFactory.getPhone(slotIndex);
3351 String manufacturerCode = null;
3352 if (phone != null) {
3353 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003354 try {
3355 manufacturerCode =
3356 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3357 } catch (IndexOutOfBoundsException e) {
3358 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3359 return null;
3360 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003361 }
3362 return manufacturerCode;
3363 }
3364
3365 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003366 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3367 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003368 Phone phone = PhoneFactory.getPhone(slotIndex);
3369 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003370 return null;
3371 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003372 int subId = phone.getSubId();
3373 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003374 mApp, subId, callingPackage, callingFeatureId,
3375 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003376 return null;
3377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378
3379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 return phone.getDeviceSvn();
3382 } finally {
3383 Binder.restoreCallingIdentity(identity);
3384 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003385 }
3386
fionaxu43304da2017-11-27 22:51:16 -08003387 @Override
3388 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 final Phone phone = getPhone(subId);
3392 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3393 } finally {
3394 Binder.restoreCallingIdentity(identity);
3395 }
fionaxu43304da2017-11-27 22:51:16 -08003396 }
3397
3398 @Override
3399 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003400 final long identity = Binder.clearCallingIdentity();
3401 try {
3402 final Phone phone = getPhone(subId);
3403 return phone == null ? null : phone.getCarrierName();
3404 } finally {
3405 Binder.restoreCallingIdentity(identity);
3406 }
fionaxu43304da2017-11-27 22:51:16 -08003407 }
3408
calvinpanffe225e2018-11-01 19:43:06 +08003409 @Override
chen xu0026ca62019-03-06 15:28:50 -08003410 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003411 final long identity = Binder.clearCallingIdentity();
3412 try {
3413 final Phone phone = getPhone(subId);
3414 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003415 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003416 } finally {
3417 Binder.restoreCallingIdentity(identity);
3418 }
3419 }
3420
3421 @Override
chen xu0026ca62019-03-06 15:28:50 -08003422 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003423 final long identity = Binder.clearCallingIdentity();
3424 try {
3425 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003426 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
3430 }
3431
chen xu651eec72018-11-11 19:03:44 -08003432 @Override
chen xu864e11c2018-12-06 22:10:03 -08003433 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3434 if (!isSubscriptionMccMnc) {
3435 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3436 }
chen xu651eec72018-11-11 19:03:44 -08003437 final Phone phone = PhoneFactory.getPhone(slotIndex);
3438 if (phone == null) {
3439 return TelephonyManager.UNKNOWN_CARRIER_ID;
3440 }
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3444 } finally {
3445 Binder.restoreCallingIdentity(identity);
3446 }
3447 }
3448
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003449 //
3450 // Internal helper methods.
3451 //
3452
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003453 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003454 * Make sure the caller is the calling package itself
3455 *
3456 * @throws SecurityException if the caller is not the calling package
3457 */
3458 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3459 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003460 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3461 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003462 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003463 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003464 } catch (PackageManager.NameNotFoundException e) {
3465 // packageUid is -1
3466 }
3467 if (packageUid != callingUid) {
3468 throw new SecurityException(message + ": Package " + callingPackage
3469 + " does not belong to " + callingUid);
3470 }
3471 }
3472
3473 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003474 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3475 *
3476 * @throws SecurityException if the caller does not have the required permission
3477 */
3478 private void enforceModifyPermission() {
3479 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3480 }
3481
Shuo Qian3b6ee772019-11-13 17:43:31 -08003482 private void enforceActiveEmergencySessionPermission() {
3483 mApp.enforceCallingOrSelfPermission(
3484 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3485 }
3486
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003487 /**
3488 * Make sure the caller has the CALL_PHONE permission.
3489 *
3490 * @throws SecurityException if the caller does not have the required permission
3491 */
3492 private void enforceCallPermission() {
3493 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3494 }
3495
paulhu5a773602019-08-23 19:17:33 +08003496 private void enforceSettingsPermission() {
3497 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003498 }
3499
Michele Berionne5e411512020-11-13 02:36:59 +00003500 private void enforceRebootPermission() {
3501 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3502 }
3503
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003504 private String createTelUrl(String number) {
3505 if (TextUtils.isEmpty(number)) {
3506 return null;
3507 }
3508
Jake Hambye994d462014-02-03 13:10:13 -08003509 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003510 }
3511
Ihab Awadf9e92732013-12-05 18:02:52 -08003512 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003513 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3514 }
3515
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003516 private static void logv(String msg) {
3517 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3518 }
3519
Ihab Awadf9e92732013-12-05 18:02:52 -08003520 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003521 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3522 }
3523
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003524 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003525 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003526 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003527 }
3528
Sanket Padawe356d7632015-06-22 14:03:32 -07003529 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003530 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003531 final long identity = Binder.clearCallingIdentity();
3532 try {
3533 final Phone phone = PhoneFactory.getPhone(slotIndex);
3534 if (phone == null) {
3535 return PhoneConstants.PHONE_TYPE_NONE;
3536 } else {
3537 return phone.getPhoneType();
3538 }
3539 } finally {
3540 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003541 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003542 }
3543
3544 /**
3545 * Returns the CDMA ERI icon index to display
3546 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003547 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003548 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3549 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3550 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003551 }
3552
Sanket Padawe356d7632015-06-22 14:03:32 -07003553 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003554 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3555 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003557 mApp, subId, callingPackage, callingFeatureId,
3558 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003559 return -1;
3560 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003561
3562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 final Phone phone = getPhone(subId);
3565 if (phone != null) {
3566 return phone.getCdmaEriIconIndex();
3567 } else {
3568 return -1;
3569 }
3570 } finally {
3571 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003573 }
3574
3575 /**
3576 * Returns the CDMA ERI icon mode,
3577 * 0 - ON
3578 * 1 - FLASHING
3579 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003580 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003581 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3582 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3583 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003584 }
3585
Sanket Padawe356d7632015-06-22 14:03:32 -07003586 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003587 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3588 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003590 mApp, subId, callingPackage, callingFeatureId,
3591 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003592 return -1;
3593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003594
3595 final long identity = Binder.clearCallingIdentity();
3596 try {
3597 final Phone phone = getPhone(subId);
3598 if (phone != null) {
3599 return phone.getCdmaEriIconMode();
3600 } else {
3601 return -1;
3602 }
3603 } finally {
3604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003606 }
3607
3608 /**
3609 * Returns the CDMA ERI text,
3610 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003611 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003612 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3613 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3614 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003615 }
3616
Sanket Padawe356d7632015-06-22 14:03:32 -07003617 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003618 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3619 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003620 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003621 mApp, subId, callingPackage, callingFeatureId,
3622 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003623 return null;
3624 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003625
3626 final long identity = Binder.clearCallingIdentity();
3627 try {
3628 final Phone phone = getPhone(subId);
3629 if (phone != null) {
3630 return phone.getCdmaEriText();
3631 } else {
3632 return null;
3633 }
3634 } finally {
3635 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003637 }
3638
3639 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003640 * Returns the CDMA MDN.
3641 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003642 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003643 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3645 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646
3647 final long identity = Binder.clearCallingIdentity();
3648 try {
3649 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003650 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003651 return phone.getLine1Number();
3652 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003653 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654 return null;
3655 }
3656 } finally {
3657 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003658 }
3659 }
3660
3661 /**
3662 * Returns the CDMA MIN.
3663 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003664 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003665 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3667 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003668
3669 final long identity = Binder.clearCallingIdentity();
3670 try {
3671 final Phone phone = getPhone(subId);
3672 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3673 return phone.getCdmaMin();
3674 } else {
3675 return null;
3676 }
3677 } finally {
3678 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003679 }
3680 }
3681
Hall Liud892bec2018-11-30 14:51:45 -08003682 @Override
3683 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3684 INumberVerificationCallback callback, String callingPackage) {
3685 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3686 != PERMISSION_GRANTED) {
3687 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3688 }
3689 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3690
3691 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3692 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003693 throw new SecurityException("Calling package must be configured in the device config: "
3694 + "calling package: " + callingPackage
3695 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003696 }
3697
3698 if (range == null) {
3699 throw new NullPointerException("Range must be non-null");
3700 }
3701
3702 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003703 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003704
3705 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3706 }
3707
Junda Liuca05d5d2014-08-14 22:36:34 -07003708 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003709 * Returns true if CDMA provisioning needs to run.
3710 */
3711 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003712 final long identity = Binder.clearCallingIdentity();
3713 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003714 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003715 } finally {
3716 Binder.restoreCallingIdentity(identity);
3717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003718 }
3719
3720 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003721 * Sets the voice mail number of a given subId.
3722 */
3723 @Override
3724 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003725 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3726 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727
3728 final long identity = Binder.clearCallingIdentity();
3729 try {
3730 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3731 new Pair<String, String>(alphaTag, number), new Integer(subId));
3732 return success;
3733 } finally {
3734 Binder.restoreCallingIdentity(identity);
3735 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003736 }
3737
Ta-wei Yen87c49842016-05-13 21:19:52 -07003738 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003739 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3740 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003741 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3742 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003743 if (!TextUtils.equals(callingPackage, systemDialer)) {
3744 throw new SecurityException("caller must be system dialer");
3745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746
3747 final long identity = Binder.clearCallingIdentity();
3748 try {
3749 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3750 if (phoneAccountHandle == null) {
3751 return null;
3752 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003753 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003754 } finally {
3755 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003756 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003757 }
3758
3759 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003760 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3761 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003762 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003764 mApp, subId, callingPackage, callingFeatureId,
3765 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003766 return null;
3767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003769 final long identity = Binder.clearCallingIdentity();
3770 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003771 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003772 } finally {
3773 Binder.restoreCallingIdentity(identity);
3774 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003775 }
3776
3777 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003778 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3779 VisualVoicemailSmsFilterSettings settings) {
3780 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003781
3782 final long identity = Binder.clearCallingIdentity();
3783 try {
3784 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003785 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003786 } finally {
3787 Binder.restoreCallingIdentity(identity);
3788 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003789 }
3790
3791 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003792 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3793 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794
3795 final long identity = Binder.clearCallingIdentity();
3796 try {
3797 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003798 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799 } finally {
3800 Binder.restoreCallingIdentity(identity);
3801 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003802 }
3803
3804 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003805 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3806 String callingPackage, int subId) {
3807 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808
3809 final long identity = Binder.clearCallingIdentity();
3810 try {
3811 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003812 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 } finally {
3814 Binder.restoreCallingIdentity(identity);
3815 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003816 }
3817
3818 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003819 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003820 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003821
3822 final long identity = Binder.clearCallingIdentity();
3823 try {
3824 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003825 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826 } finally {
3827 Binder.restoreCallingIdentity(identity);
3828 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003829 }
3830
3831 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003832 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3833 String callingAttributionTag, int subId, String number, int port, String text,
3834 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003835 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003836 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003837 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003838 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003839 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3840 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003841 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003842
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003843 /**
fionaxu0152e512016-11-14 13:36:14 -08003844 * Sets the voice activation state of a given subId.
3845 */
3846 @Override
3847 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3849 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003850
3851 final long identity = Binder.clearCallingIdentity();
3852 try {
3853 final Phone phone = getPhone(subId);
3854 if (phone != null) {
3855 phone.setVoiceActivationState(activationState);
3856 } else {
3857 loge("setVoiceActivationState fails with invalid subId: " + subId);
3858 }
3859 } finally {
3860 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003861 }
3862 }
3863
3864 /**
3865 * Sets the data activation state of a given subId.
3866 */
3867 @Override
3868 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3870 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871
3872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 final Phone phone = getPhone(subId);
3875 if (phone != null) {
3876 phone.setDataActivationState(activationState);
3877 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003878 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003879 }
3880 } finally {
3881 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003882 }
3883 }
3884
3885 /**
3886 * Returns the voice activation state of a given subId.
3887 */
3888 @Override
3889 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003890 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891
fionaxu0152e512016-11-14 13:36:14 -08003892 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003893 final long identity = Binder.clearCallingIdentity();
3894 try {
3895 if (phone != null) {
3896 return phone.getVoiceActivationState();
3897 } else {
3898 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3899 }
3900 } finally {
3901 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003902 }
3903 }
3904
3905 /**
3906 * Returns the data activation state of a given subId.
3907 */
3908 @Override
3909 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003911
fionaxu0152e512016-11-14 13:36:14 -08003912 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 if (phone != null) {
3916 return phone.getDataActivationState();
3917 } else {
3918 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3919 }
3920 } finally {
3921 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003922 }
3923 }
3924
3925 /**
Wink Saville36469e72014-06-11 15:17:00 -07003926 * Returns the unread count of voicemails for a subId
3927 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003928 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003929 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3930 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003931 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003932 mApp, subId, callingPackage, callingFeatureId,
3933 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003934 return 0;
3935 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003936 final long identity = Binder.clearCallingIdentity();
3937 try {
3938 final Phone phone = getPhone(subId);
3939 if (phone != null) {
3940 return phone.getVoiceMessageCount();
3941 } else {
3942 return 0;
3943 }
3944 } finally {
3945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003947 }
3948
3949 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003950 * returns true, if the device is in a state where both voice and data
3951 * are supported simultaneously. This can change based on location or network condition.
3952 */
3953 @Override
3954 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003955 final long identity = Binder.clearCallingIdentity();
3956 try {
3957 final Phone phone = getPhone(subId);
3958 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3959 } finally {
3960 Binder.restoreCallingIdentity(identity);
3961 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003962 }
3963
3964 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003965 * Send the dialer code if called from the current default dialer or the caller has
3966 * carrier privilege.
3967 * @param inputCode The dialer code to send
3968 */
3969 @Override
3970 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003971 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003972 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003973 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3974 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003975 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003976 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003977 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003979
3980 final long identity = Binder.clearCallingIdentity();
3981 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003982 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003983 } finally {
3984 Binder.restoreCallingIdentity(identity);
3985 }
fionaxu235cc5e2017-03-06 22:25:57 -08003986 }
3987
Pengquan Menga1bb6272018-09-06 09:59:22 -07003988 @Override
3989 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003990 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003991 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003992 mApp, subId, "getNetworkSelectionMode");
3993 final long identity = Binder.clearCallingIdentity();
3994 try {
3995 if (!isActiveSubscription(subId)) {
3996 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3997 }
3998 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3999 } finally {
4000 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004001 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004002 }
4003
Brad Ebinger35c841c2018-10-01 10:40:55 -07004004 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004005 public boolean isInEmergencySmsMode() {
4006 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4007 final long identity = Binder.clearCallingIdentity();
4008 try {
4009 for (Phone phone : PhoneFactory.getPhones()) {
4010 if (phone.isInEmergencySmsMode()) {
4011 return true;
4012 }
4013 }
4014 } finally {
4015 Binder.restoreCallingIdentity(identity);
4016 }
4017 return false;
4018 }
4019
shilu366312e2019-12-17 09:28:10 -08004020 /**
4021 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4022 * @param subId The subscription to use to check the configuration.
4023 * @param c The callback that will be used to send the result.
4024 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004025 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004026 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4027 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004028 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004029 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004030
4031 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4032 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4033 "IMS not available on device.");
4034 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 final long token = Binder.clearCallingIdentity();
4036 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004037 int slotId = getSlotIndexOrException(subId);
4038 verifyImsMmTelConfiguredOrThrow(slotId);
4039 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004040 } catch (ImsException e) {
4041 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004042 } finally {
4043 Binder.restoreCallingIdentity(token);
4044 }
4045 }
4046
shilu366312e2019-12-17 09:28:10 -08004047 /**
4048 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4049 * @param subId The subscription to use to check the configuration.
4050 * @param c The callback that will be used to send the result.
4051 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004052 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004053 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004054 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004055 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004056 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4057 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4058 }
Meng Wangafbc5852019-09-19 17:37:13 -07004059 final long token = Binder.clearCallingIdentity();
4060 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004061 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4062 .removeRegistrationCallbackForSubscription(c, subId);
4063 } catch (ImsException e) {
4064 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4065 + "is inactive, ignoring unregister.");
4066 // If the subscription is no longer active, just return, since the callback
4067 // will already have been removed internally.
4068 } finally {
4069 Binder.restoreCallingIdentity(token);
4070 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004071 }
4072
Brad Ebingera34a6c22019-10-22 17:36:18 -07004073 /**
4074 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4075 */
4076 @Override
4077 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4078 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4079 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4080 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4081 "IMS not available on device.");
4082 }
4083 final long token = Binder.clearCallingIdentity();
4084 try {
4085 Phone phone = getPhone(subId);
4086 if (phone == null) {
4087 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4088 + subId + "'");
4089 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4090 }
4091 phone.getImsRegistrationState(regState -> {
4092 try {
4093 consumer.accept((regState == null)
4094 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4095 } catch (RemoteException e) {
4096 // Ignore if the remote process is no longer available to call back.
4097 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4098 }
4099 });
4100 } finally {
4101 Binder.restoreCallingIdentity(token);
4102 }
4103 }
4104
4105 /**
4106 * Get the transport type for the IMS service registration state.
4107 */
4108 @Override
4109 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004110 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004111 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004112 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4113 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4114 "IMS not available on device.");
4115 }
4116 final long token = Binder.clearCallingIdentity();
4117 try {
4118 Phone phone = getPhone(subId);
4119 if (phone == null) {
4120 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4121 + subId + "'");
4122 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4123 }
4124 phone.getImsRegistrationTech(regTech -> {
4125 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4126 int regTechConverted = (regTech == null)
4127 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4128 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4129 regTechConverted);
4130 try {
4131 consumer.accept(regTechConverted);
4132 } catch (RemoteException e) {
4133 // Ignore if the remote process is no longer available to call back.
4134 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4135 }
4136 });
4137 } finally {
4138 Binder.restoreCallingIdentity(token);
4139 }
4140 }
4141
shilu366312e2019-12-17 09:28:10 -08004142 /**
4143 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4144 * @param subId The subscription to use to check the configuration.
4145 * @param c The callback that will be used to send the result.
4146 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004147 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004148 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4149 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004150 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004151 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004152 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4153 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4154 "IMS not available on device.");
4155 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004156 final long token = Binder.clearCallingIdentity();
4157 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004158 int slotId = getSlotIndexOrException(subId);
4159 verifyImsMmTelConfiguredOrThrow(slotId);
4160 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004161 } catch (ImsException e) {
4162 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004163 } finally {
4164 Binder.restoreCallingIdentity(token);
4165 }
4166 }
4167
shilu366312e2019-12-17 09:28:10 -08004168 /**
4169 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4170 * @param subId The subscription to use to check the configuration.
4171 * @param c The callback that will be used to send the result.
4172 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004173 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004174 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004175 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004176 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004177 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4178 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4179 }
Meng Wangafbc5852019-09-19 17:37:13 -07004180
4181 final long token = Binder.clearCallingIdentity();
4182 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004183 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004184 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004185 } catch (ImsException e) {
4186 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4187 + "is inactive, ignoring unregister.");
4188 // If the subscription is no longer active, just return, since the callback
4189 // will already have been removed internally.
4190 } finally {
4191 Binder.restoreCallingIdentity(token);
4192 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004193 }
4194
4195 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004196 public boolean isCapable(int subId, int capability, int regTech) {
4197 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004198 final long token = Binder.clearCallingIdentity();
4199 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004200 int slotId = getSlotIndexOrException(subId);
4201 verifyImsMmTelConfiguredOrThrow(slotId);
4202 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4203 } catch (com.android.ims.ImsException e) {
4204 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4205 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004206 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004207 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4208 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004209 } finally {
4210 Binder.restoreCallingIdentity(token);
4211 }
4212 }
4213
4214 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004215 public boolean isAvailable(int subId, int capability, int regTech) {
4216 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004217 final long token = Binder.clearCallingIdentity();
4218 try {
4219 Phone phone = getPhone(subId);
4220 if (phone == null) return false;
4221 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004222 } catch (com.android.ims.ImsException e) {
4223 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4224 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 } finally {
4226 Binder.restoreCallingIdentity(token);
4227 }
4228 }
4229
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004230 /**
4231 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4232 * subscription.
4233 * @param subId The subscription to use to check the configuration.
4234 * @param callback The callback that will be used to send the result.
4235 * @param capability The MmTelFeature capability that will be used to send the result.
4236 * @param transportType The transport type of the MmTelFeature capability.
4237 */
4238 @Override
4239 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4240 int transportType) {
4241 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004242 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4243 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4244 "IMS not available on device.");
4245 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004246 final long token = Binder.clearCallingIdentity();
4247 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004248 int slotId = getSlotIndex(subId);
4249 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4250 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4251 + subId + "'");
4252 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4253 }
4254 verifyImsMmTelConfiguredOrThrow(slotId);
4255 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4256 transportType, aBoolean -> {
4257 try {
4258 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4259 } catch (RemoteException e) {
4260 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4261 + "running. Ignore");
4262 }
4263 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004264 } catch (ImsException e) {
4265 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004266 } finally {
4267 Binder.restoreCallingIdentity(token);
4268 }
4269 }
4270
shilu366312e2019-12-17 09:28:10 -08004271 /**
4272 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4273 * @param subId The subscription to use to check the configuration.
4274 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004275 @Override
4276 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004277 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004278 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004279
Brad Ebinger35c841c2018-10-01 10:40:55 -07004280 final long token = Binder.clearCallingIdentity();
4281 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004282 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004283 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004284 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004285 } catch (ImsException e) {
4286 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004287 } finally {
4288 Binder.restoreCallingIdentity(token);
4289 }
4290 }
4291
4292 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004293 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004295 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004296 final long identity = Binder.clearCallingIdentity();
4297 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004298 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004299 // This setting doesn't require an active ImsService connection, so do not verify. The
4300 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004301 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004302 } catch (ImsException e) {
4303 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004304 } finally {
4305 Binder.restoreCallingIdentity(identity);
4306 }
4307 }
4308
shilu366312e2019-12-17 09:28:10 -08004309 /**
4310 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4311 * @param subId The subscription to use to check the configuration.
4312 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004313 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004314 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004315 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004316 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004317 final long identity = Binder.clearCallingIdentity();
4318 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004319 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004320 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004321 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004322 } catch (ImsException e) {
4323 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004324 } finally {
4325 Binder.restoreCallingIdentity(identity);
4326 }
4327 }
4328
4329 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004330 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004332 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004333 final long identity = Binder.clearCallingIdentity();
4334 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004335 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004336 // This setting doesn't require an active ImsService connection, so do not verify. The
4337 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004338 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004339 } catch (ImsException e) {
4340 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004341 } finally {
4342 Binder.restoreCallingIdentity(identity);
4343 }
4344 }
4345
shilu366312e2019-12-17 09:28:10 -08004346 /**
4347 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4348 * @param subId The subscription to use to check the configuration.
4349 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004350 @Override
4351 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004352 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004353 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 final long identity = Binder.clearCallingIdentity();
4355 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004356 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004357 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004358 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004359 } catch (ImsException e) {
4360 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004361 } finally {
4362 Binder.restoreCallingIdentity(identity);
4363 }
4364 }
4365
4366 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004367 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004369 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 final long identity = Binder.clearCallingIdentity();
4371 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004372 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004373 // This setting doesn't require an active ImsService connection, so do not verify. The
4374 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004375 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004376 } catch (ImsException e) {
4377 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 } finally {
4379 Binder.restoreCallingIdentity(identity);
4380 }
4381 }
4382
shilu366312e2019-12-17 09:28:10 -08004383 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004384 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4385 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4386 * @param subId The subscription to use to check the configuration.
4387 */
4388 @Override
4389 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004390 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004391 mApp, subId, "isCrossSimCallingEnabledByUser");
4392 final long identity = Binder.clearCallingIdentity();
4393 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004394 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004395 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004396 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004397 } catch (ImsException e) {
4398 throw new ServiceSpecificException(e.getCode());
4399 } finally {
4400 Binder.restoreCallingIdentity(identity);
4401 }
4402 }
4403
4404 /**
4405 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4406 * Requires MODIFY_PHONE_STATE permission.
4407 * @param subId The subscription to use to check the configuration.
4408 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4409 * false otherwise
4410 */
4411 @Override
4412 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4414 "setCrossSimCallingEnabled");
4415 final long identity = Binder.clearCallingIdentity();
4416 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004417 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004418 // This setting doesn't require an active ImsService connection, so do not verify. The
4419 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004420 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004421 } catch (ImsException e) {
4422 throw new ServiceSpecificException(e.getCode());
4423 } finally {
4424 Binder.restoreCallingIdentity(identity);
4425 }
4426 }
4427
4428 /**
shilu366312e2019-12-17 09:28:10 -08004429 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4430 * @param subId The subscription to use to check the configuration.
4431 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004432 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004433
Brad Ebinger35c841c2018-10-01 10:40:55 -07004434 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004435 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004436 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004437 final long identity = Binder.clearCallingIdentity();
4438 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004439 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004440 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004441 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004442 } catch (ImsException e) {
4443 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004444 } finally {
4445 Binder.restoreCallingIdentity(identity);
4446 }
4447 }
4448
4449 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004450 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004452 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004453 final long identity = Binder.clearCallingIdentity();
4454 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004455 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004456 // This setting doesn't require an active ImsService connection, so do not verify. The
4457 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004458 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004459 } catch (ImsException e) {
4460 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004461 } finally {
4462 Binder.restoreCallingIdentity(identity);
4463 }
4464 }
4465
4466 @Override
4467 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4469 "setVoWiFiNonPersistent");
4470 final long identity = Binder.clearCallingIdentity();
4471 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004472 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004473 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004474 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004475 } catch (ImsException e) {
4476 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004477 } finally {
4478 Binder.restoreCallingIdentity(identity);
4479 }
4480 }
4481
shilu366312e2019-12-17 09:28:10 -08004482 /**
4483 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4484 * @param subId The subscription to use to check the configuration.
4485 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004486 @Override
4487 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004488 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004489 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004490 final long identity = Binder.clearCallingIdentity();
4491 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004492 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004493 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004494 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004495 } catch (ImsException e) {
4496 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004497 } finally {
4498 Binder.restoreCallingIdentity(identity);
4499 }
4500 }
4501
4502 @Override
4503 public void setVoWiFiModeSetting(int subId, int mode) {
4504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4505 "setVoWiFiModeSetting");
4506 final long identity = Binder.clearCallingIdentity();
4507 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004508 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004509 // This setting doesn't require an active ImsService connection, so do not verify. The
4510 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004511 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004512 } catch (ImsException e) {
4513 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004514 } finally {
4515 Binder.restoreCallingIdentity(identity);
4516 }
4517 }
4518
4519 @Override
4520 public int getVoWiFiRoamingModeSetting(int subId) {
4521 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4522 final long identity = Binder.clearCallingIdentity();
4523 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004524 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004525 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004526 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004527 } catch (ImsException e) {
4528 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004529 } finally {
4530 Binder.restoreCallingIdentity(identity);
4531 }
4532 }
4533
4534 @Override
4535 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4537 "setVoWiFiRoamingModeSetting");
4538 final long identity = Binder.clearCallingIdentity();
4539 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004540 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004541 // This setting doesn't require an active ImsService connection, so do not verify. The
4542 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004543 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004544 } catch (ImsException e) {
4545 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004546 } finally {
4547 Binder.restoreCallingIdentity(identity);
4548 }
4549 }
4550
4551 @Override
4552 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4554 "setRttCapabilityEnabled");
4555 final long identity = Binder.clearCallingIdentity();
4556 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004557 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004558 // This setting doesn't require an active ImsService connection, so do not verify. The
4559 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004560 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004561 } catch (ImsException e) {
4562 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004563 } finally {
4564 Binder.restoreCallingIdentity(identity);
4565 }
4566 }
4567
shilu366312e2019-12-17 09:28:10 -08004568 /**
4569 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4570 * @param subId The subscription to use to check the configuration.
4571 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004572 @Override
4573 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004574 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004575 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004576 final long identity = Binder.clearCallingIdentity();
4577 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004578 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004579 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004580 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004581 } catch (ImsException e) {
4582 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004583 } finally {
4584 Binder.restoreCallingIdentity(identity);
4585 }
4586 }
4587
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004588 @Override
4589 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4590 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004591
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004592 final long identity = Binder.clearCallingIdentity();
4593 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004594 if (!isImsAvailableOnDevice()) {
4595 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4596 "IMS not available on device.");
4597 }
4598 int slotId = getSlotIndexOrException(subId);
4599 verifyImsMmTelConfiguredOrThrow(slotId);
4600 ImsManager.getInstance(mApp, slotId)
4601 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004602 } catch (ImsException e) {
4603 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004604 } finally {
4605 Binder.restoreCallingIdentity(identity);
4606 }
4607 }
4608
4609 @Override
4610 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4611 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004612
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004613 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004614 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4615 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4616 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004617 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004618 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004619 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004620 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004621 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4622 + "is inactive, ignoring unregister.");
4623 // If the subscription is no longer active, just return, since the callback will already
4624 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004625 } finally {
4626 Binder.restoreCallingIdentity(identity);
4627 }
4628 }
4629
joonhunshincffb7fc2021-11-28 07:32:01 +00004630 @Override
4631 public void registerFeatureProvisioningChangedCallback(int subId,
4632 IFeatureProvisioningCallback callback) {
4633 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4634 mApp, subId, "registerFeatureProvisioningChangedCallback");
4635
4636 final long identity = Binder.clearCallingIdentity();
4637 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4638 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4639 }
4640
joonhunshin91bc1952022-04-29 08:47:15 +00004641 try {
4642 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4643 if (controller == null) {
4644 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4645 "Device does not support IMS");
4646 }
4647 controller.addFeatureProvisioningChangedCallback(subId, callback);
4648 } finally {
4649 Binder.restoreCallingIdentity(identity);
4650 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004651 }
4652
4653 @Override
4654 public void unregisterFeatureProvisioningChangedCallback(int subId,
4655 IFeatureProvisioningCallback callback) {
4656 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4657 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4658
4659 final long identity = Binder.clearCallingIdentity();
4660 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4661 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4662 }
4663
joonhunshin91bc1952022-04-29 08:47:15 +00004664 try {
4665 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4666 if (controller == null) {
4667 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4668 return;
4669 }
4670 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4671 } finally {
4672 Binder.restoreCallingIdentity(identity);
4673 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004674 }
allenwtsu99c623b2020-01-03 18:24:23 +08004675
4676 private void checkModifyPhoneStatePermission(int subId, String message) {
4677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4678 message);
4679 }
4680
allenwtsu99c623b2020-01-03 18:24:23 +08004681 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004682 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004683 boolean isProvisioned) {
4684 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4685
4686 final long identity = Binder.clearCallingIdentity();
4687 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004688 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4689 if (controller == null) {
4690 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4691 return;
4692 }
4693 controller.setRcsProvisioningStatusForCapability(
4694 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
allenwtsu99c623b2020-01-03 18:24:23 +08004698 }
4699
4700
4701 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004702 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4703 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4704 mApp, subId, "getRcsProvisioningStatusForCapability");
4705
allenwtsu99c623b2020-01-03 18:24:23 +08004706 final long identity = Binder.clearCallingIdentity();
4707 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004708 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4709 if (controller == null) {
4710 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4711
4712 // device does not support IMS, this method will return true always.
4713 return true;
4714 }
4715 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004716 } finally {
4717 Binder.restoreCallingIdentity(identity);
4718 }
4719 }
4720
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004721 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004722 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4723 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004724 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004725
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004726 final long identity = Binder.clearCallingIdentity();
4727 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004728 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4729 if (controller == null) {
4730 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4731 return;
4732 }
4733 controller.setImsProvisioningStatusForCapability(
4734 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004735 } finally {
4736 Binder.restoreCallingIdentity(identity);
4737 }
4738 }
4739
4740 @Override
4741 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004742 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4743 mApp, subId, "getProvisioningStatusForCapability");
4744
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004745 final long identity = Binder.clearCallingIdentity();
4746 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004747 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4748 if (controller == null) {
4749 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004750
joonhunshin91bc1952022-04-29 08:47:15 +00004751 // device does not support IMS, this method will return true always.
4752 return true;
4753 }
4754 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004755 } finally {
4756 Binder.restoreCallingIdentity(identity);
4757 }
4758 }
4759
4760 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004761 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4762 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4763 mApp, subId, "isProvisioningRequiredForCapability");
4764
4765 final long identity = Binder.clearCallingIdentity();
4766 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004767 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4768 if (controller == null) {
4769 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4770
4771 // device does not support IMS, this method will return false
4772 return false;
4773 }
4774 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004775 } finally {
4776 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004777 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004778 }
4779
4780 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004781 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4782 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4783 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004784
joonhunshincffb7fc2021-11-28 07:32:01 +00004785 final long identity = Binder.clearCallingIdentity();
4786 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004787 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4788 if (controller == null) {
4789 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4790
4791 // device does not support IMS, this method will return false
4792 return false;
4793 }
4794 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004795 } finally {
4796 Binder.restoreCallingIdentity(identity);
4797 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004798 }
4799
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004800 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004801 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004802 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4803 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4804 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004805 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4806 mApp, subId, "getImsProvisioningInt");
4807
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004808 final long identity = Binder.clearCallingIdentity();
4809 try {
4810 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004811 int slotId = getSlotIndex(subId);
4812 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4813 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4814 + subId + "' for key:" + key);
4815 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4816 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004817
joonhunshin91bc1952022-04-29 08:47:15 +00004818 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4819 if (controller == null) {
4820 loge("getImsProvisioningInt: Device does not support IMS");
4821
4822 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4823 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4824 }
4825 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004826 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4827 return retVal;
4828 }
4829
calvinpanb5a34062021-02-08 19:59:36 +08004830 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004831 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004832 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4833 + subId + "' for key:" + key);
4834 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004835 } finally {
4836 Binder.restoreCallingIdentity(identity);
4837 }
4838 }
4839
4840 @Override
4841 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004842 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4843 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4844 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004845 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4846 mApp, subId, "getImsProvisioningString");
4847
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004848 final long identity = Binder.clearCallingIdentity();
4849 try {
4850 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004851 int slotId = getSlotIndex(subId);
4852 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4853 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4854 + subId + "' for key:" + key);
4855 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4856 }
calvinpanb5a34062021-02-08 19:59:36 +08004857 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004858 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004859 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4860 + subId + "' for key:" + key);
4861 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004862 } finally {
4863 Binder.restoreCallingIdentity(identity);
4864 }
4865 }
4866
4867 @Override
4868 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004869 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4870 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4871 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4873 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004874
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004875 final long identity = Binder.clearCallingIdentity();
4876 try {
4877 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004878 int slotId = getSlotIndex(subId);
4879 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4880 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4881 + subId + "' for key:" + key);
4882 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4883 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004884
joonhunshin91bc1952022-04-29 08:47:15 +00004885 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4886 if (controller == null) {
4887 loge("setImsProvisioningInt: Device does not support IMS");
4888
4889 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
4890 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4891 }
4892 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00004893 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4894 return retVal;
4895 }
4896
calvinpanb5a34062021-02-08 19:59:36 +08004897 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4898 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004899 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004900 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004901 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004902 } finally {
4903 Binder.restoreCallingIdentity(identity);
4904 }
4905 }
4906
4907 @Override
4908 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004909 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4910 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4911 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4913 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004914 final long identity = Binder.clearCallingIdentity();
4915 try {
4916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 int slotId = getSlotIndex(subId);
4918 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4919 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4920 + subId + "' for key:" + key);
4921 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4922 }
calvinpanb5a34062021-02-08 19:59:36 +08004923 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4924 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004925 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004926 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004927 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004928 } finally {
4929 Binder.restoreCallingIdentity(identity);
4930 }
4931 }
4932
Brad Ebinger919631e2021-06-02 17:46:35 -07004933 /**
4934 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4935 * for the given slot ID or no ImsResolver instance has been created.
4936 * @param slotId The slot ID that the IMS service is created for.
4937 * @throws ImsException If there is no ImsService configured for this slot.
4938 */
4939 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4940 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4941 ImsFeature.FEATURE_MMTEL)) {
4942 throw new ImsException("This subscription does not support MMTEL over IMS",
4943 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4944 }
4945 }
4946
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004947 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004948 int slotId = SubscriptionManager.getSlotIndex(subId);
4949 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004950 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4951 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004952 }
4953 return slotId;
4954 }
4955
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004956 private int getSlotIndex(int subId) {
4957 int slotId = SubscriptionManager.getSlotIndex(subId);
4958 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4959 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4960 }
4961 return slotId;
4962 }
4963
Wink Saville36469e72014-06-11 15:17:00 -07004964 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004965 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004966 */
4967 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004968 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4969 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004970 try {
4971 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4972 } catch (SecurityException se) {
4973 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4974 throw new SecurityException("Package " + callingPackage + " does not belong to "
4975 + Binder.getCallingUid());
4976 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004977 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004978 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004979 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004980 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004981 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004982 mApp, subId, callingPackage, callingFeatureId,
4983 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004984 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4985 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004987 final long identity = Binder.clearCallingIdentity();
4988 try {
4989 final Phone phone = getPhone(subId);
4990 if (phone != null) {
4991 return phone.getServiceState().getDataNetworkType();
4992 } else {
4993 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4994 }
4995 } finally {
4996 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004998 }
4999
5000 /**
5001 * Returns the data network type
5002 */
5003 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005004 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005005 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5006 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005007 }
5008
5009 /**
5010 * Returns the data network type for a subId
5011 */
5012 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005013 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5014 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005015 String functionName = "getDataNetworkTypeForSubscriber";
5016 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5017 mApp, functionName)) {
5018 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5019 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5020 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5021 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005022 }
5023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024 final long identity = Binder.clearCallingIdentity();
5025 try {
5026 final Phone phone = getPhone(subId);
5027 if (phone != null) {
5028 return phone.getServiceState().getDataNetworkType();
5029 } else {
5030 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5031 }
5032 } finally {
5033 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005034 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005035 }
5036
5037 /**
Wink Saville36469e72014-06-11 15:17:00 -07005038 * Returns the Voice network type for a subId
5039 */
5040 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005041 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5042 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005043 String functionName = "getVoiceNetworkTypeForSubscriber";
5044 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5045 mApp, functionName)) {
5046 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5047 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5048 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5049 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005050 }
5051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 final long identity = Binder.clearCallingIdentity();
5053 try {
5054 final Phone phone = getPhone(subId);
5055 if (phone != null) {
5056 return phone.getServiceState().getVoiceNetworkType();
5057 } else {
5058 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5059 }
5060 } finally {
5061 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005062 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005063 }
5064
5065 /**
5066 * @return true if a ICC card is present
5067 */
5068 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005069 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005070 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5071 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005072 }
5073
5074 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005075 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005076 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005077 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005078 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079 final long identity = Binder.clearCallingIdentity();
5080 try {
5081 final Phone phone = PhoneFactory.getPhone(slotIndex);
5082 if (phone != null) {
5083 return phone.getIccCard().hasIccCard();
5084 } else {
5085 return false;
5086 }
5087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005090 }
5091
5092 /**
5093 * Return if the current radio is LTE on CDMA. This
5094 * is a tri-state return value as for a period of time
5095 * the mode may be unknown.
5096 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005097 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005098 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005099 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005100 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005101 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005102 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5103 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5104 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005105 }
5106
Sanket Padawe356d7632015-06-22 14:03:32 -07005107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005108 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5109 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005110 try {
5111 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5112 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005113 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5114 }
5115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 final long identity = Binder.clearCallingIdentity();
5117 try {
5118 final Phone phone = getPhone(subId);
5119 if (phone == null) {
5120 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5121 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005122 return TelephonyProperties.lte_on_cdma_device()
5123 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005124 }
5125 } finally {
5126 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005127 }
Wink Saville36469e72014-06-11 15:17:00 -07005128 }
5129
Wink Saville36469e72014-06-11 15:17:00 -07005130 /**
5131 * {@hide}
5132 * Returns Default subId, 0 in the case of single standby.
5133 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005134 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005135 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005136 }
5137
Shishir Agrawala9f32182016-04-12 12:00:16 -07005138 private int getSlotForDefaultSubscription() {
5139 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5140 }
5141
Wink Savilleb564aae2014-10-23 10:18:09 -07005142 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005143 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005144 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005145
Pengquan Menge92a50d2018-09-21 15:54:48 -07005146 private boolean isActiveSubscription(int subId) {
5147 return mSubscriptionController.isActiveSubId(subId);
5148 }
5149
Ihab Awadf2177b72013-11-25 13:33:23 -08005150 /**
5151 * @see android.telephony.TelephonyManager.WifiCallingChoices
5152 */
5153 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 final long identity = Binder.clearCallingIdentity();
5155 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005156 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005157 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5158 getWhenToMakeWifiCallsDefaultPreference());
5159 } finally {
5160 Binder.restoreCallingIdentity(identity);
5161 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005162 }
5163
5164 /**
5165 * @see android.telephony.TelephonyManager.WifiCallingChoices
5166 */
5167 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 final long identity = Binder.clearCallingIdentity();
5169 try {
5170 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005171 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5173 } finally {
5174 Binder.restoreCallingIdentity(identity);
5175 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005176 }
5177
Sailesh Nepald1e68152013-12-12 19:08:02 -08005178 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005179 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005180 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005181 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005182
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005183 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5184 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5185 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005186 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005187 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5188 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005189 }
5190 return PhoneFactory.getPhone(phoneId);
5191 }
5192
Shishir Agrawal566b7612013-10-28 14:41:00 -07005193 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005194 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005195 @NonNull IccLogicalChannelRequest request) {
5196 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5197 /*message=*/ "iccOpenLogicalChannel");
5198
5199 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5200 // Verify that the callingPackage in the request belongs to the calling UID
5201 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5202
5203 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005204 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005205
Rambo Wanga1782702021-11-10 20:15:19 -08005206 private Phone getPhoneFromValidIccLogicalChannelRequest(
5207 @NonNull IccLogicalChannelRequest request, String message) {
5208 Phone phone;
5209 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5211 mApp, request.subId, message);
5212 phone = getPhoneFromSubId(request.subId);
5213 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5214 enforceModifyPermission();
5215 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5216 } else {
5217 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005218 }
Rambo Wanga1782702021-11-10 20:15:19 -08005219 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005220 }
5221
5222 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005223 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 final long identity = Binder.clearCallingIdentity();
5225 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005226 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005228 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5229 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005230 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5231 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 loge("The calling package is not allowed to access ISD-R.");
5233 throw new SecurityException(
5234 "The calling package is not allowed to access ISD-R.");
5235 }
Derek Tan740e1672017-06-27 14:56:27 -07005236 }
Derek Tan740e1672017-06-27 14:56:27 -07005237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005239 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5240 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 return response;
5242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005245 }
5246
5247 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005248 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5249 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5250 /*message=*/"iccCloseLogicalChannel");
5251
5252 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5253
5254 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005255 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005256
Rambo Wanga1782702021-11-10 20:15:19 -08005257 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5258 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005259 // before this feature is enabled, this API should only return false if
5260 // the operation fails instead of throwing runtime exception for
5261 // backward-compatibility.
5262 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5263 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264 final long identity = Binder.clearCallingIdentity();
5265 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005266 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005267 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 }
Chen Xue9d737e2022-01-01 23:41:31 -08005269 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005270 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005271 Boolean success = false;
5272 if (result instanceof RuntimeException) {
5273 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005274 if (shouldThrowExceptionOnFailure) {
5275 throw (RuntimeException) result;
5276 } else {
5277 return false;
5278 }
Chen Xue9d737e2022-01-01 23:41:31 -08005279 } else if (result instanceof Boolean) {
5280 success = (Boolean) result;
5281 } else {
5282 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5283 }
Rambo Wanga1782702021-11-10 20:15:19 -08005284 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 return success;
5286 } finally {
5287 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005288 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005289 }
5290
5291 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005292 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005293 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5295 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005296 if (DBG) {
5297 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5298 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5299 + p3 + " data=" + data);
5300 }
5301 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5302 command, p1, p2, p3, data);
5303 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005304
Jordan Liu4c733742019-02-28 12:03:40 -08005305 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005306 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5307 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005308 enforceModifyPermission();
5309 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005310 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5311 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5312 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005313 }
5314 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005315 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5316 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005317 }
5318
5319 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5320 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321 final long identity = Binder.clearCallingIdentity();
5322 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005323 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 return "";
5325 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005328 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5329 null /* workSource */);
5330 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 // Append the returned status code to the end of the response payload.
5333 String s = Integer.toHexString(
5334 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5335 if (response.payload != null) {
5336 s = IccUtils.bytesToHexString(response.payload) + s;
5337 }
5338 return s;
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005341 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005342 }
Jake Hambye994d462014-02-03 13:10:13 -08005343
Evan Charltonc66da362014-05-16 14:06:40 -07005344 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005345 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5346 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5348 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005349 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005350 if (DBG) {
5351 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5352 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5353 }
5354 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5355 cla, command, p1, p2, p3, data);
5356 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005357
Jordan Liu4c733742019-02-28 12:03:40 -08005358 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005359 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5360 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005361 enforceModifyPermission();
5362 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5363 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005364 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5365 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5366 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005367 }
5368
5369 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005370 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5371 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005372 }
5373
5374 // open APDU basic channel assuming the caller has sufficient permissions
5375 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5376 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 final long identity = Binder.clearCallingIdentity();
5378 try {
5379 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5380 && TextUtils.equals(ISDR_AID, data)) {
5381 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005382 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5383 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005384 if (bestComponent == null
5385 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5386 loge("The calling package is not allowed to select ISD-R.");
5387 throw new SecurityException(
5388 "The calling package is not allowed to select ISD-R.");
5389 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005390 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005391
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005392 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005393 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5394 null /* workSource */);
5395 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 // Append the returned status code to the end of the response payload.
5398 String s = Integer.toHexString(
5399 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5400 if (response.payload != null) {
5401 s = IccUtils.bytesToHexString(response.payload) + s;
5402 }
5403 return s;
5404 } finally {
5405 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005406 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005407 }
5408
5409 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005410 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005411 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5413 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415 final long identity = Binder.clearCallingIdentity();
5416 try {
5417 if (DBG) {
5418 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5419 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5420 }
5421
5422 IccIoResult response =
5423 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5424 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5425 subId);
5426
5427 if (DBG) {
5428 log("Exchange SIM_IO [R]" + response);
5429 }
5430
5431 byte[] result = null;
5432 int length = 2;
5433 if (response.payload != null) {
5434 length = 2 + response.payload.length;
5435 result = new byte[length];
5436 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5437 } else {
5438 result = new byte[length];
5439 }
5440
5441 result[length - 1] = (byte) response.sw2;
5442 result[length - 2] = (byte) response.sw1;
5443 return result;
5444 } finally {
5445 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005446 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005447 }
5448
Nathan Haroldb3014052017-01-25 15:57:32 -08005449 /**
5450 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5451 * on a particular subscription
5452 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005453 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5454 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005455 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005456 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005457 return null;
5458 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459
5460 final long identity = Binder.clearCallingIdentity();
5461 try {
5462 if (appType != TelephonyManager.APPTYPE_USIM
5463 && appType != TelephonyManager.APPTYPE_SIM) {
5464 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5465 return null;
5466 }
5467 Object response = sendRequest(
5468 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5469 if (response instanceof String[]) {
5470 return (String[]) response;
5471 }
yincheng zhao2737e882019-09-06 17:06:54 -07005472 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005474 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 } finally {
5476 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005477 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005478 }
5479
yincheng zhao2737e882019-09-06 17:06:54 -07005480 /**
5481 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5482 * subscription.
5483 *
5484 * @param subId the id of the subscription.
5485 * @param appType the uicc app type, must be USIM or SIM.
5486 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5487 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005488 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005489 * @return number of fplmns that is successfully written to the SIM.
5490 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005491 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5492 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5494 mApp, subId, "setForbiddenPlmns");
5495
yincheng zhao2737e882019-09-06 17:06:54 -07005496 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5497 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5498 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5499 }
5500 if (fplmns == null) {
5501 throw new IllegalArgumentException("Fplmn List provided is null");
5502 }
5503 for (String fplmn : fplmns) {
5504 if (!CellIdentity.isValidPlmn(fplmn)) {
5505 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5506 }
5507 }
5508 final long identity = Binder.clearCallingIdentity();
5509 try {
5510 Object response = sendRequest(
5511 CMD_SET_FORBIDDEN_PLMNS,
5512 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5513 subId);
5514 return (int) response;
5515 } finally {
5516 Binder.restoreCallingIdentity(identity);
5517 }
5518 }
5519
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005520 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005521 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5523 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005524
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 final long identity = Binder.clearCallingIdentity();
5526 try {
5527 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5528 if (response.payload == null) {
5529 return "";
5530 }
Evan Charltonc66da362014-05-16 14:06:40 -07005531
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532 // Append the returned status code to the end of the response payload.
5533 String s = Integer.toHexString(
5534 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5535 s = IccUtils.bytesToHexString(response.payload) + s;
5536 return s;
5537 } finally {
5538 Binder.restoreCallingIdentity(identity);
5539 }
Evan Charltonc66da362014-05-16 14:06:40 -07005540 }
5541
Jake Hambye994d462014-02-03 13:10:13 -08005542 /**
5543 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5544 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5545 *
5546 * @param itemID the ID of the item to read
5547 * @return the NV item as a String, or null on error.
5548 */
5549 @Override
5550 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005551 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5553 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554
5555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005558 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5560 return value;
5561 } finally {
5562 Binder.restoreCallingIdentity(identity);
5563 }
Jake Hambye994d462014-02-03 13:10:13 -08005564 }
5565
5566 /**
5567 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5568 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5569 *
5570 * @param itemID the ID of the item to read
5571 * @param itemValue the value to write, as a String
5572 * @return true on success; false on any failure
5573 */
5574 @Override
5575 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005576 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5578 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579
5580 final long identity = Binder.clearCallingIdentity();
5581 try {
5582 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5583 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005584 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5586 return success;
5587 } finally {
5588 Binder.restoreCallingIdentity(identity);
5589 }
Jake Hambye994d462014-02-03 13:10:13 -08005590 }
5591
5592 /**
5593 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5594 * Used for device configuration by some CDMA operators.
5595 *
5596 * @param preferredRoamingList byte array containing the new PRL
5597 * @return true on success; false on any failure
5598 */
5599 @Override
5600 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5602 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603
5604 final long identity = Binder.clearCallingIdentity();
5605 try {
5606 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5607 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5608 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5609 return success;
5610 } finally {
5611 Binder.restoreCallingIdentity(identity);
5612 }
Jake Hambye994d462014-02-03 13:10:13 -08005613 }
5614
5615 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005616 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005617 * Used for device configuration by some CDMA operators.
5618 *
chen xu6dac5ab2018-10-26 17:39:23 -07005619 * @param slotIndex - device slot.
5620 *
Jake Hambye994d462014-02-03 13:10:13 -08005621 * @return true on success; false on any failure
5622 */
5623 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005624 public boolean resetModemConfig(int slotIndex) {
5625 Phone phone = PhoneFactory.getPhone(slotIndex);
5626 if (phone != null) {
5627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5628 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629
chen xu6dac5ab2018-10-26 17:39:23 -07005630 final long identity = Binder.clearCallingIdentity();
5631 try {
5632 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5633 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5634 return success;
5635 } finally {
5636 Binder.restoreCallingIdentity(identity);
5637 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 }
chen xu6dac5ab2018-10-26 17:39:23 -07005639 return false;
5640 }
5641
5642 /**
5643 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5644 *
5645 * @param slotIndex - device slot.
5646 *
5647 * @return true on success; false on any failure
5648 */
5649 @Override
5650 public boolean rebootModem(int slotIndex) {
5651 Phone phone = PhoneFactory.getPhone(slotIndex);
5652 if (phone != null) {
5653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5654 mApp, phone.getSubId(), "rebootModem");
5655
5656 final long identity = Binder.clearCallingIdentity();
5657 try {
5658 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5659 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5660 return success;
5661 } finally {
5662 Binder.restoreCallingIdentity(identity);
5663 }
5664 }
5665 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005666 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005667
Brad Ebinger51f743a2017-01-23 13:50:20 -08005668 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005669 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5670 * {@link #disableIms(int)}.
5671 * @param slotIndex device slot.
5672 */
5673 public void resetIms(int slotIndex) {
5674 enforceModifyPermission();
5675
5676 final long identity = Binder.clearCallingIdentity();
5677 try {
5678 if (mImsResolver == null) {
5679 // may happen if the does not support IMS.
5680 return;
5681 }
5682 mImsResolver.disableIms(slotIndex);
5683 mImsResolver.enableIms(slotIndex);
5684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
5687 }
5688
5689 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005690 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5691 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005692 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005693 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005694 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695
5696 final long identity = Binder.clearCallingIdentity();
5697 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005698 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005699 // may happen if the device does not support IMS.
5700 return;
5701 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005702 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 } finally {
5704 Binder.restoreCallingIdentity(identity);
5705 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005706 }
5707
5708 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005709 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5710 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005711 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005712 public void disableIms(int slotId) {
5713 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714
5715 final long identity = Binder.clearCallingIdentity();
5716 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005717 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005718 // may happen if the device does not support IMS.
5719 return;
5720 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005721 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 } finally {
5723 Binder.restoreCallingIdentity(identity);
5724 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005725 }
5726
5727 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005728 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5729 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005730 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005731 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005732 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005733 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734
5735 final long identity = Binder.clearCallingIdentity();
5736 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005737 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005738 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5739 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005740 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005741 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 } finally {
5743 Binder.restoreCallingIdentity(identity);
5744 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005745 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005746 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005747 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5748 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005749 @Override
5750 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005751 enforceModifyPermission();
5752
5753 final long identity = Binder.clearCallingIdentity();
5754 try {
5755 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005756 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005757 } finally {
5758 Binder.restoreCallingIdentity(identity);
5759 }
5760 }
5761
5762 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005763 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005764 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005765 */
5766 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5767 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005768
5769 final long identity = Binder.clearCallingIdentity();
5770 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005771 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005772 // may happen if the device does not support IMS.
5773 return null;
5774 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005775 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005779 }
5780
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005781 /**
5782 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005783 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005784 */
5785 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5786 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787
5788 final long identity = Binder.clearCallingIdentity();
5789 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005790 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005791 // may happen if the device does not support IMS.
5792 return null;
5793 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005794 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 } finally {
5796 Binder.restoreCallingIdentity(identity);
5797 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005798 }
5799
Brad Ebinger884c07b2018-02-15 16:17:40 -08005800 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005801 * Sets the ImsService Package Name that Telephony will bind to.
5802 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005803 * @param slotIndex the slot ID that the ImsService should bind for.
5804 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005805 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005806 * @param featureTypes An integer array of feature types associated with a packageName.
5807 * @param packageName The name of the package that the current configuration will be replaced
5808 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005809 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005810 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005811 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5812 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005813 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yude40a3f2022-11-19 22:29:12 -08005815 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005816
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005817 final long identity = Binder.clearCallingIdentity();
5818 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005819 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005820 // may happen if the device does not support IMS.
5821 return false;
5822 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005823 Map<Integer, String> featureConfig = new HashMap<>();
5824 for (int featureType : featureTypes) {
5825 featureConfig.put(featureType, packageName);
5826 }
5827 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5828 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005829 } finally {
5830 Binder.restoreCallingIdentity(identity);
5831 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005832 }
5833
5834 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005835 * Clears any carrier ImsService overrides for the slot index specified that were previously
5836 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5837 *
5838 * This should only be used for testing.
5839 *
5840 * @param slotIndex the slot ID that the ImsService should bind for.
5841 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5842 */
5843 @Override
5844 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08005845 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5846 "clearCarrierImsServiceOverride");
5847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yude40a3f2022-11-19 22:29:12 -08005848 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08005849
5850 final long identity = Binder.clearCallingIdentity();
5851 try {
5852 if (mImsResolver == null) {
5853 // may happen if the device does not support IMS.
5854 return false;
5855 }
5856 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5857 } finally {
5858 Binder.restoreCallingIdentity(identity);
5859 }
5860 }
5861
5862 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005864 *
5865 * @param slotId The slot that the ImsService is associated with.
5866 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5867 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005868 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005869 * @return the package name of the ImsService configuration.
5870 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005871 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5872 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005873 TelephonyPermissions
Jack Yude40a3f2022-11-19 22:29:12 -08005874 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
5875 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005876
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005877 final long identity = Binder.clearCallingIdentity();
5878 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005879 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005880 // may happen if the device does not support IMS.
5881 return "";
5882 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005883 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005884 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5885 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005886 } finally {
5887 Binder.restoreCallingIdentity(identity);
5888 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005889 }
5890
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005891 /**
5892 * Get the MmTelFeature state associated with the requested subscription id.
5893 * @param subId The subscription that the MmTelFeature is associated with.
5894 * @param callback A callback with an integer containing the
5895 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5896 */
5897 @Override
5898 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5899 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005900 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5901 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5902 "IMS not available on device.");
5903 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005904 final long token = Binder.clearCallingIdentity();
5905 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005906 int slotId = getSlotIndex(subId);
5907 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5908 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5909 + subId + "'");
5910 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5911 }
5912 verifyImsMmTelConfiguredOrThrow(slotId);
5913 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5914 try {
5915 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5916 } catch (RemoteException e) {
5917 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5918 + "Ignore");
5919 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005920 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005921 } catch (ImsException e) {
5922 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005923 } finally {
5924 Binder.restoreCallingIdentity(token);
5925 }
5926 }
5927
Daniel Brightbb5840b2021-01-12 15:48:18 -08005928 /**
5929 * Sets the ims registration state on all valid {@link Phone}s.
5930 */
5931 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005932 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933
5934 final long identity = Binder.clearCallingIdentity();
5935 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005936 // NOTE: Before S, this method only set the default phone.
5937 for (final Phone phone : PhoneFactory.getPhones()) {
5938 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5939 phone.setImsRegistrationState(registered);
5940 }
5941 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005942 } finally {
5943 Binder.restoreCallingIdentity(identity);
5944 }
Wink Saville36469e72014-06-11 15:17:00 -07005945 }
5946
5947 /**
Stuart Scott54788802015-03-30 13:18:01 -07005948 * Set the network selection mode to automatic.
5949 *
5950 */
5951 @Override
5952 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5954 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955
5956 final long identity = Binder.clearCallingIdentity();
5957 try {
shilufc958392020-01-20 11:36:01 -08005958 if (!isActiveSubscription(subId)) {
5959 return;
5960 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005962 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5963 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005964 } finally {
5965 Binder.restoreCallingIdentity(identity);
5966 }
Stuart Scott54788802015-03-30 13:18:01 -07005967 }
5968
Jack Yud10cdd42020-09-28 20:28:01 -07005969 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005970 * Ask the radio to connect to the input network and change selection mode to manual.
5971 *
5972 * @param subId the id of the subscription.
5973 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5974 * the operator to attach to.
5975 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5976 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5977 * normal network selection next time.
5978 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005979 */
5980 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005981 public boolean setNetworkSelectionModeManual(
5982 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5984 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005985
5986 if (!isActiveSubscription(subId)) {
5987 return false;
5988 }
5989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 final long identity = Binder.clearCallingIdentity();
5991 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005992 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005994 if (DBG) {
5995 log("setNetworkSelectionModeManual: subId: " + subId
5996 + " operator: " + operatorInfo);
5997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5999 } finally {
6000 Binder.restoreCallingIdentity(identity);
6001 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006002 }
shilu84f6e8b2019-12-19 13:58:01 -08006003 /**
6004 * Get the manual network selection
6005 *
6006 * @param subId the id of the subscription.
6007 *
6008 * @return the previously saved user selected PLMN
6009 */
6010 @Override
6011 public String getManualNetworkSelectionPlmn(int subId) {
6012 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006013 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006014 mApp, subId, "getManualNetworkSelectionPlmn");
6015
6016 final long identity = Binder.clearCallingIdentity();
6017 try {
6018 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006019 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006020 }
6021
6022 final Phone phone = getPhone(subId);
6023 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006024 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006025 }
6026 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6027 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6028 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6029 } finally {
6030 Binder.restoreCallingIdentity(identity);
6031 }
6032 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006033
6034 /**
6035 * Scans for available networks.
6036 */
6037 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006038 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6039 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6041 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006042 LocationAccessPolicy.LocationPermissionResult locationResult =
6043 LocationAccessPolicy.checkLocationPermission(mApp,
6044 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6045 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006046 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006047 .setCallingPid(Binder.getCallingPid())
6048 .setCallingUid(Binder.getCallingUid())
6049 .setMethod("getCellNetworkScanResults")
6050 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006051 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6052 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006053 .build());
6054 switch (locationResult) {
6055 case DENIED_HARD:
6056 throw new SecurityException("Not allowed to access scan results -- location");
6057 case DENIED_SOFT:
6058 return null;
6059 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060
Pengquan Menga1bb6272018-09-06 09:59:22 -07006061 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 try {
6063 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006064 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066 } finally {
6067 Binder.restoreCallingIdentity(identity);
6068 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006069 }
6070
6071 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006072 * Get the call forwarding info, given the call forwarding reason.
6073 */
6074 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006075 public void getCallForwarding(int subId, int callForwardingReason,
6076 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006077 enforceReadPrivilegedPermission("getCallForwarding");
6078 long identity = Binder.clearCallingIdentity();
6079 try {
6080 if (DBG) {
6081 log("getCallForwarding: subId " + subId
6082 + " callForwardingReason" + callForwardingReason);
6083 }
Hall Liu27d24262020-09-18 19:04:59 -07006084
6085 Phone phone = getPhone(subId);
6086 if (phone == null) {
6087 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006088 callback.onError(
6089 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006090 } catch (RemoteException e) {
6091 // ignore
6092 }
6093 return;
6094 }
6095
6096 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6097 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6098 @Override
6099 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6100 try {
6101 callback.onCallForwardingInfoAvailable(info);
6102 } catch (RemoteException e) {
6103 // ignore
6104 }
6105 }
6106
6107 @Override
6108 public void onError(int error) {
6109 try {
6110 callback.onError(error);
6111 } catch (RemoteException e) {
6112 // ignore
6113 }
6114 }
6115 });
6116 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006117 } finally {
6118 Binder.restoreCallingIdentity(identity);
6119 }
6120 }
6121
6122 /**
6123 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6124 * reason, the number to forward, and the timeout before the forwarding is attempted.
6125 */
6126 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006127 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6128 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006129 enforceModifyPermission();
6130 long identity = Binder.clearCallingIdentity();
6131 try {
6132 if (DBG) {
6133 log("setCallForwarding: subId " + subId
6134 + " callForwardingInfo" + callForwardingInfo);
6135 }
Hall Liu27d24262020-09-18 19:04:59 -07006136
6137 Phone phone = getPhone(subId);
6138 if (phone == null) {
6139 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006140 callback.accept(
6141 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006142 } catch (RemoteException e) {
6143 // ignore
6144 }
6145 return;
6146 }
6147
6148 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6149 FunctionalUtils.ignoreRemoteException(callback::accept));
6150
6151 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006152 } finally {
6153 Binder.restoreCallingIdentity(identity);
6154 }
6155 }
6156
6157 /**
Hall Liu27d24262020-09-18 19:04:59 -07006158 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006159 */
6160 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006161 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006162 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006163 long identity = Binder.clearCallingIdentity();
6164 try {
Hall Liu27d24262020-09-18 19:04:59 -07006165 Phone phone = getPhone(subId);
6166 if (phone == null) {
6167 try {
6168 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6169 } catch (RemoteException e) {
6170 // ignore
6171 }
6172 return;
6173 }
SongFerngWang0e767992021-03-31 22:08:45 +08006174 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6175 PersistableBundle c = configManager.getConfigForSubId(subId);
6176 boolean requireUssd = c.getBoolean(
6177 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006178
Shuo Qian4a594052020-01-23 11:59:30 -08006179 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006180 if (requireUssd) {
6181 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6182 getSubscriptionCarrierId(subId));
6183 String newUssdCommand = "";
6184 try {
6185 newUssdCommand = carrierXmlParser.getFeature(
6186 CarrierXmlParser.FEATURE_CALL_WAITING)
6187 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6188 } catch (NullPointerException e) {
6189 loge("Failed to generate USSD number" + e);
6190 }
6191 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6192 mMainThreadHandler, callback, carrierXmlParser,
6193 CarrierXmlParser.SsEntry.SSAction.QUERY);
6194 final String ussdCommand = newUssdCommand;
6195 Executors.newSingleThreadExecutor().execute(() -> {
6196 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6197 });
6198 } else {
6199 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6200 callback::accept);
6201 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6202 }
Shuo Qian4a594052020-01-23 11:59:30 -08006203 } finally {
6204 Binder.restoreCallingIdentity(identity);
6205 }
6206 }
6207
6208 /**
Hall Liu27d24262020-09-18 19:04:59 -07006209 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006210 */
6211 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006212 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006213 enforceModifyPermission();
6214 long identity = Binder.clearCallingIdentity();
6215 try {
Hall Liu27d24262020-09-18 19:04:59 -07006216 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6217
6218 Phone phone = getPhone(subId);
6219 if (phone == null) {
6220 try {
6221 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6222 } catch (RemoteException e) {
6223 // ignore
6224 }
6225 return;
6226 }
6227
SongFerngWang0e767992021-03-31 22:08:45 +08006228 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6229 PersistableBundle c = configManager.getConfigForSubId(subId);
6230 boolean requireUssd = c.getBoolean(
6231 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006232
SongFerngWang0e767992021-03-31 22:08:45 +08006233 if (DBG) log("getCallWaitingStatus: subId " + subId);
6234 if (requireUssd) {
6235 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6236 getSubscriptionCarrierId(subId));
6237 CarrierXmlParser.SsEntry.SSAction ssAction =
6238 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6239 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6240 String newUssdCommand = "";
6241 try {
6242 newUssdCommand = carrierXmlParser.getFeature(
6243 CarrierXmlParser.FEATURE_CALL_WAITING)
6244 .makeCommand(ssAction, null);
6245 } catch (NullPointerException e) {
6246 loge("Failed to generate USSD number" + e);
6247 }
6248 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6249 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6250 final String ussdCommand = newUssdCommand;
6251 Executors.newSingleThreadExecutor().execute(() -> {
6252 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6253 });
6254 } else {
6255 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6256 FunctionalUtils.ignoreRemoteException(callback::accept));
6257
6258 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6259 }
Shuo Qian4a594052020-01-23 11:59:30 -08006260 } finally {
6261 Binder.restoreCallingIdentity(identity);
6262 }
6263 }
6264
6265 /**
yinxub1bed742017-04-17 11:45:04 -07006266 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006267 *
yinxub1bed742017-04-17 11:45:04 -07006268 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006269 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6270 * location related information which will be sent if the caller already possess
6271 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006272 * @param request contains the radio access networks with bands/channels to scan
6273 * @param messenger callback messenger for scan results or errors
6274 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006275 * @return the id of the requested scan which can be used to stop the scan.
6276 */
6277 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006278 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6279 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006280 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6282 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006283 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006284 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6285 if (!renounceFineLocationAccess) {
6286 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6287 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6288 .setCallingPackage(callingPackage)
6289 .setCallingFeatureId(callingFeatureId)
6290 .setCallingPid(Binder.getCallingPid())
6291 .setCallingUid(Binder.getCallingUid())
6292 .setMethod("requestNetworkScan")
6293 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6294 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6295 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6296 .build());
6297 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006298 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006299 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6300 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006301 if (e != null) {
6302 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6303 throw e;
6304 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006305 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006306 return TelephonyScanManager.INVALID_SCAN_ID;
6307 }
6308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 }
Hall Liu912dfd32019-04-25 14:02:26 -07006310 int callingUid = Binder.getCallingUid();
6311 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006312 final long identity = Binder.clearCallingIdentity();
6313 try {
6314 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006315 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006316 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006317 } finally {
6318 Binder.restoreCallingIdentity(identity);
6319 }
yinxu504e1392017-04-12 16:03:22 -07006320 }
6321
Hall Liub2ac8ef2019-02-28 15:56:23 -08006322 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006323 NetworkScanRequest request, int subId, String callingPackage) {
6324 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006325 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6326 boolean hasNetworkScanPermission =
6327 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6328 == PERMISSION_GRANTED;
6329
6330 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6331 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6332 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006333 }
6334
6335 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6336 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006337 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6338 return new SecurityException("Specific channels must not be"
6339 + " scanned without location access.");
6340 }
6341 }
6342 }
6343
Hall Liub2ac8ef2019-02-28 15:56:23 -08006344 return null;
6345 }
6346
yinxu504e1392017-04-12 16:03:22 -07006347 /**
6348 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006349 *
6350 * @param subId id of the subscription
6351 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006352 */
6353 @Override
6354 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6356 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006357
Hall Liu912dfd32019-04-25 14:02:26 -07006358 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006359 final long identity = Binder.clearCallingIdentity();
6360 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006361 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006362 } finally {
6363 Binder.restoreCallingIdentity(identity);
6364 }
yinxu504e1392017-04-12 16:03:22 -07006365 }
6366
6367 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006368 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006369 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006370 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006371 */
6372 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006373 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006374 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006375 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006376 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377
6378 final long identity = Binder.clearCallingIdentity();
6379 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006380 if (DBG) log("getAllowedNetworkTypesBitmask");
6381 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6382 int networkTypesBitmask = (result != null ? result[0] : -1);
6383 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6384 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 } finally {
6386 Binder.restoreCallingIdentity(identity);
6387 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006388 }
6389
6390 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006391 * Get the allowed network types for certain reason.
6392 *
6393 * @param subId the id of the subscription.
6394 * @param reason the reason the allowed network type change is taking place
6395 * @return the allowed network types.
6396 */
6397 @Override
6398 public long getAllowedNetworkTypesForReason(int subId,
6399 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006400 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006401 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006402 final long identity = Binder.clearCallingIdentity();
6403 try {
6404 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6405 } finally {
6406 Binder.restoreCallingIdentity(identity);
6407 }
6408 }
6409
6410 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006411 * Enable/Disable E-UTRA-NR Dual Connectivity
6412 * @param subId subscription id of the sim card
6413 * @param nrDualConnectivityState expected NR dual connectivity state
6414 * This can be passed following states
6415 * <ol>
6416 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6417 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6418 * <li>Disable NR dual connectivity and force secondary cell to be released
6419 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6420 * </ol>
6421 * @return operation result.
6422 */
6423 @Override
6424 public int setNrDualConnectivityState(int subId,
6425 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6427 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006428 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006429 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6430 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6431 }
6432
Sooraj Sasindran37444802020-08-11 10:40:43 -07006433 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6434 final long identity = Binder.clearCallingIdentity();
6435 try {
6436 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6437 nrDualConnectivityState, subId,
6438 workSource);
6439 if (DBG) log("enableNRDualConnectivity result: " + result);
6440 return result;
6441 } finally {
6442 Binder.restoreCallingIdentity(identity);
6443 }
6444 }
6445
6446 /**
6447 * Is E-UTRA-NR Dual Connectivity enabled
6448 * @return true if dual connectivity is enabled else false
6449 */
6450 @Override
6451 public boolean isNrDualConnectivityEnabled(int subId) {
6452 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006453 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006454 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006455 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006456 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6457 return false;
6458 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006459 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6460 final long identity = Binder.clearCallingIdentity();
6461 try {
6462 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6463 null, subId, workSource);
6464 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6465 return isEnabled;
6466 } finally {
6467 Binder.restoreCallingIdentity(identity);
6468 }
6469 }
6470
6471 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006472 * Set the allowed network types of the device and
6473 * provide the reason triggering the allowed network change.
6474 *
6475 * @param subId the id of the subscription.
6476 * @param reason the reason the allowed network type change is taking place
6477 * @param allowedNetworkTypes the allowed network types.
6478 * @return true on success; false on any failure.
6479 */
6480 @Override
6481 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006482 @TelephonyManager.AllowedNetworkTypesReason int reason,
6483 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6485 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006486 // If the caller only has carrier privileges, then they should not be able to override
6487 // any network types which were set for security reasons.
6488 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6489 != PERMISSION_GRANTED
6490 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6491 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6492 throw new SecurityException(
6493 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6494 + " reason "
6495 + reason);
6496 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006497 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006498 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6499 return false;
6500 }
6501 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6502 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006503 return false;
6504 }
6505
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006506 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6507 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6508
6509
6510 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6511 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6512 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006513 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006514
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006515 final long identity = Binder.clearCallingIdentity();
6516 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006517 Boolean success = (Boolean) sendRequest(
6518 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6519 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6520
6521 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6522 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006523 } finally {
6524 Binder.restoreCallingIdentity(identity);
6525 }
6526 }
6527
6528 /**
Miaoa84611c2019-03-15 09:21:10 +08006529 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006530 *
Miaoa84611c2019-03-15 09:21:10 +08006531 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006532 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006533 * @hide
6534 */
6535 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006536 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006537 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006538 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006539 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006540 try {
Miaoa84611c2019-03-15 09:21:10 +08006541 if (phone != null) {
6542 return phone.hasMatchedTetherApnSetting();
6543 } else {
6544 return false;
6545 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006546 } finally {
6547 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006548 }
Junda Liu475951f2014-11-07 16:45:03 -08006549 }
6550
6551 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006552 * Get the user enabled state of Mobile Data.
6553 *
6554 * TODO: remove and use isUserDataEnabled.
6555 * This can't be removed now because some vendor codes
6556 * calls through ITelephony directly while they should
6557 * use TelephonyManager.
6558 *
6559 * @return true on enabled
6560 */
6561 @Override
6562 public boolean getDataEnabled(int subId) {
6563 return isUserDataEnabled(subId);
6564 }
6565
6566 /**
6567 * Get whether mobile data is enabled per user setting.
6568 *
6569 * There are other factors deciding whether mobile data is actually enabled, but they are
6570 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006571 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006572 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6573 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006574 *
6575 * @return {@code true} if data is enabled else {@code false}
6576 */
6577 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006578 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006579 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006580 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006581 try {
6582 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6583 functionName);
6584 } catch (Exception e) {
6585 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6586 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006587 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006589 mApp, subId, functionName);
6590
Robert Greenwalt646120a2014-05-23 11:54:03 -07006591 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006592
6593 final long identity = Binder.clearCallingIdentity();
6594 try {
6595 int phoneId = mSubscriptionController.getPhoneId(subId);
6596 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6597 Phone phone = PhoneFactory.getPhone(phoneId);
6598 if (phone != null) {
6599 boolean retVal = phone.isUserDataEnabled();
6600 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6601 return retVal;
6602 } else {
6603 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6604 return false;
6605 }
6606 } finally {
6607 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006608 }
6609 }
6610
6611 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006612 * Checks if the device is capable of mobile data by considering whether whether the
6613 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6614 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006615 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006616 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006617 */
6618 @Override
6619 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006620 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006621 try {
6622 try {
6623 mApp.enforceCallingOrSelfPermission(
6624 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006625 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006626 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006627 try {
6628 mApp.enforceCallingOrSelfPermission(
6629 android.Manifest.permission.READ_PHONE_STATE,
6630 functionName);
6631 } catch (Exception e2) {
6632 mApp.enforceCallingOrSelfPermission(
6633 permission.READ_BASIC_PHONE_STATE, functionName);
6634 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006635 }
6636 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006637 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006638 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639
6640 final long identity = Binder.clearCallingIdentity();
6641 try {
6642 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643 Phone phone = PhoneFactory.getPhone(phoneId);
6644 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006645 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006646 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006647 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006648 return retVal;
6649 } else {
6650 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6651 return false;
6652 }
6653 } finally {
6654 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006655 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006656 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006657
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006658 /**
6659 * Check if data is enabled for a specific reason
6660 * @param subId Subscription index
6661 * @param reason the reason the data enable change is taking place
6662 * @return {@code true} if the overall data is enabled; {@code false} if not.
6663 */
6664 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006665 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006666 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006667 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006668 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006669 try {
6670 mApp.enforceCallingOrSelfPermission(
6671 android.Manifest.permission.ACCESS_NETWORK_STATE,
6672 functionName);
6673 } catch (Exception e) {
6674 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6675 functionName);
6676 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006677 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006678 try {
6679 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006680 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006681 } catch (Exception e2) {
6682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006683 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006684 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006685 }
6686
6687
6688 final long identity = Binder.clearCallingIdentity();
6689 try {
6690 int phoneId = mSubscriptionController.getPhoneId(subId);
6691 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006692 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006693 + " reason=" + reason);
6694 }
6695 Phone phone = PhoneFactory.getPhone(phoneId);
6696 if (phone != null) {
6697 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006698 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006699 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006700 return retVal;
6701 } else {
6702 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006703 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006704 + subId + " retVal=false");
6705 }
6706 return false;
6707 }
6708 } finally {
6709 Binder.restoreCallingIdentity(identity);
6710 }
6711 }
6712
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006713 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006714 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006715 // No permission needed; this only lets the caller inspect their own status.
6716 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006717 }
Junda Liu29340342014-07-10 15:23:27 -07006718
6719 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006720 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006721 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006722 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6723 }
6724
6725 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6726 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006727 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006728 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006729 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6730 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006731 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6732 if (cpt == null) {
6733 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006734 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6735 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006736 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006737 }
6738
6739 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006740 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006741 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006742 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006743 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006744 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006745 Phone phone = getPhone(subId);
6746 if (phone == null) {
6747 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6748 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6749 }
6750 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6751 if (cpt == null) {
6752 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006753 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6754 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006755 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006756 }
6757
6758 @Override
6759 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006760 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006761 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6762 }
6763
6764 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006765 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006766 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006767 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006768 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006769 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6770 Phone phone = PhoneFactory.getPhone(phoneId);
6771 if (phone == null) {
6772 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006773 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006774 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6775 if (cpt == null) {
6776 continue;
6777 }
6778 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006779 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6780 break;
6781 }
6782 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006783 return result;
Junda Liu29340342014-07-10 15:23:27 -07006784 }
Derek Tan89e89d42014-07-08 17:00:10 -07006785
6786 @Override
Junda Liue64de782015-04-16 17:19:16 -07006787 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006788 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006789 Phone phone = PhoneFactory.getPhone(phoneId);
6790 if (phone == null) {
6791 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006792 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006793 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6794 if (cpt == null) {
6795 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006796 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006797 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006798 }
6799
Amith Yamasani6e118872016-02-19 12:53:51 -08006800 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006801 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006802 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006803 Phone phone = PhoneFactory.getPhone(phoneId);
6804 if (phone == null) {
6805 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006806 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006807 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6808 if (cpt == null) {
6809 return Collections.emptyList();
6810 }
6811 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006812 }
6813
chen xuf7e9fe82019-05-09 19:31:02 -07006814 @Override
6815 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006816 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006817 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006818 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006819 try {
6820 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6821 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6822 }
6823 } finally {
6824 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006825 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006826 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006827 }
6828
Rambo Wang6812ffb2022-03-15 16:54:17 -07006829 @Override
6830 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6831 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6832
6833 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6834 if (phone == null) {
6835 return null;
6836 }
6837 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6838 if (cpt == null) {
6839 return null;
6840 }
6841 return cpt.getCarrierServicePackageName();
6842 }
6843
Wink Savilleb564aae2014-10-23 10:18:09 -07006844 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006845 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006846 UiccPort port = phone == null ? null : phone.getUiccPort();
6847 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006848 return null;
6849 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006850 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006851 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006852 return null;
6853 }
6854 return iccId;
6855 }
6856
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006857 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006858 public void setCallComposerStatus(int subId, int status) {
6859 enforceModifyPermission();
6860
6861 final long identity = Binder.clearCallingIdentity();
6862 try {
6863 Phone phone = getPhone(subId);
6864 if (phone != null) {
6865 Phone defaultPhone = phone.getImsPhone();
6866 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6867 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6868 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006869 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6870 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006871 }
6872 }
Shuo Qian284ae752020-12-22 19:10:14 -08006873 } catch (ImsException e) {
6874 throw new ServiceSpecificException(e.getCode());
6875 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006876 Binder.restoreCallingIdentity(identity);
6877 }
6878 }
6879
6880 @Override
6881 public int getCallComposerStatus(int subId) {
6882 enforceReadPrivilegedPermission("getCallComposerStatus");
6883
6884 final long identity = Binder.clearCallingIdentity();
6885 try {
6886 Phone phone = getPhone(subId);
6887 if (phone != null) {
6888 Phone defaultPhone = phone.getImsPhone();
6889 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6890 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6891 return imsPhone.getCallComposerStatus();
6892 }
6893 }
6894 } finally {
6895 Binder.restoreCallingIdentity(identity);
6896 }
6897 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6898 }
6899
6900 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006901 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6902 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006903 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006904 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006906 final long identity = Binder.clearCallingIdentity();
6907 try {
6908 final String iccId = getIccId(subId);
6909 final Phone phone = getPhone(subId);
6910 if (phone == null) {
6911 return false;
6912 }
6913 final String subscriberId = phone.getSubscriberId();
6914
6915 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006916 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006917 + subscriberId + " to " + number);
6918 }
6919
6920 if (TextUtils.isEmpty(iccId)) {
6921 return false;
6922 }
6923
6924 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6925
6926 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6927 if (alphaTag == null) {
6928 editor.remove(alphaTagPrefKey);
6929 } else {
6930 editor.putString(alphaTagPrefKey, alphaTag);
6931 }
6932
6933 // Record both the line number and IMSI for this ICCID, since we need to
6934 // track all merged IMSIs based on line number
6935 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6936 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6937 if (number == null) {
6938 editor.remove(numberPrefKey);
6939 editor.remove(subscriberPrefKey);
6940 } else {
6941 editor.putString(numberPrefKey, number);
6942 editor.putString(subscriberPrefKey, subscriberId);
6943 }
6944
6945 editor.commit();
6946 return true;
6947 } finally {
6948 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006949 }
Derek Tan7226c842014-07-02 17:42:23 -07006950 }
6951
6952 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006953 public String getLine1NumberForDisplay(int subId, String callingPackage,
6954 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006955 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006957 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006958 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006959 return null;
6960 }
Derek Tan97ebb422014-09-05 16:55:38 -07006961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006962 final long identity = Binder.clearCallingIdentity();
6963 try {
6964 String iccId = getIccId(subId);
6965 if (iccId != null) {
6966 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6967 if (DBG_MERGE) {
6968 log("getLine1NumberForDisplay returning "
6969 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6970 }
6971 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006972 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006973 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6974 return null;
6975 } finally {
6976 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006977 }
Derek Tan7226c842014-07-02 17:42:23 -07006978 }
6979
6980 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006981 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6982 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006984 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006985 return null;
6986 }
Derek Tan97ebb422014-09-05 16:55:38 -07006987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006988 final long identity = Binder.clearCallingIdentity();
6989 try {
6990 String iccId = getIccId(subId);
6991 if (iccId != null) {
6992 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6993 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6994 }
6995 return null;
6996 } finally {
6997 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006998 }
Derek Tan7226c842014-07-02 17:42:23 -07006999 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007000
7001 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007002 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7003 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007004 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7005 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007006 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007007 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007008 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007009 return null;
7010 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007011
Jordan Liub49b04b2019-05-06 14:45:15 -07007012 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7013 // the process, where TelephonyManager was instantiated.
7014 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007015 final long identity = Binder.clearCallingIdentity();
7016 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007017 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 final TelephonyManager tele = TelephonyManager.from(context);
7019 final SubscriptionManager sub = SubscriptionManager.from(context);
7020
7021 // Figure out what subscribers are currently active
7022 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023
Jordan Liub49b04b2019-05-06 14:45:15 -07007024 // Only consider subs which match the current subId
7025 // This logic can be simplified. See b/131189269 for progress.
7026 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007027 activeSubscriberIds.add(tele.getSubscriberId(subId));
7028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029
7030 // First pass, find a number override for an active subscriber
7031 String mergeNumber = null;
7032 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7033 for (String key : prefs.keySet()) {
7034 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7035 final String subscriberId = (String) prefs.get(key);
7036 if (activeSubscriberIds.contains(subscriberId)) {
7037 final String iccId = key.substring(
7038 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7039 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7040 mergeNumber = (String) prefs.get(numberKey);
7041 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007042 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 + " for active subscriber " + subscriberId);
7044 }
7045 if (!TextUtils.isEmpty(mergeNumber)) {
7046 break;
7047 }
7048 }
7049 }
7050 }
7051
7052 // Shortcut when no active merged subscribers
7053 if (TextUtils.isEmpty(mergeNumber)) {
7054 return null;
7055 }
7056
7057 // Second pass, find all subscribers under that line override
7058 final ArraySet<String> result = new ArraySet<>();
7059 for (String key : prefs.keySet()) {
7060 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7061 final String number = (String) prefs.get(key);
7062 if (mergeNumber.equals(number)) {
7063 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7064 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7065 final String subscriberId = (String) prefs.get(subscriberKey);
7066 if (!TextUtils.isEmpty(subscriberId)) {
7067 result.add(subscriberId);
7068 }
7069 }
7070 }
7071 }
7072
7073 final String[] resultArray = result.toArray(new String[result.size()]);
7074 Arrays.sort(resultArray);
7075 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007076 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007077 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7078 }
7079 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007080 } finally {
7081 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007082 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007083 }
7084
7085 @Override
zoey chen38003472019-12-13 17:16:31 +08007086 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7087 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007088
7089 final long identity = Binder.clearCallingIdentity();
7090 try {
7091 final TelephonyManager telephonyManager = mApp.getSystemService(
7092 TelephonyManager.class);
7093 String subscriberId = telephonyManager.getSubscriberId(subId);
7094 if (subscriberId == null) {
7095 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007096 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007097 + subId);
7098 }
7099 return null;
7100 }
7101
7102 final SubscriptionInfo info = SubscriptionController.getInstance()
7103 .getSubscriptionInfo(subId);
7104 final ParcelUuid groupUuid = info.getGroupUuid();
7105 // If it doesn't belong to any group, return just subscriberId of itself.
7106 if (groupUuid == null) {
7107 return new String[]{subscriberId};
7108 }
7109
7110 // Get all subscriberIds from the group.
7111 final List<String> mergedSubscriberIds = new ArrayList<>();
7112 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007113 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007114 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007115 for (SubscriptionInfo subInfo : groupInfos) {
7116 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7117 if (subscriberId != null) {
7118 mergedSubscriberIds.add(subscriberId);
7119 }
7120 }
7121
7122 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7123 } finally {
7124 Binder.restoreCallingIdentity(identity);
7125
7126 }
7127 }
7128
7129 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007130 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007131 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007132 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133
7134 final long identity = Binder.clearCallingIdentity();
7135 try {
7136 final Phone phone = getPhone(subId);
7137 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7138 } finally {
7139 Binder.restoreCallingIdentity(identity);
7140 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007141 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007142
7143 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007144 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007145 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7146 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007147 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7148 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149
7150 final long identity = Binder.clearCallingIdentity();
7151 try {
7152 final Phone phone = getPhone(subId);
7153 if (phone == null) {
7154 return false;
7155 }
7156 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7157 cdmaNonRoamingList);
7158 } finally {
7159 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007160 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007161 }
7162
7163 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007164 @Deprecated
7165 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7166 enforceModifyPermission();
7167
7168 int returnValue = 0;
7169 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007170 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007171 if(result.exception == null) {
7172 if (result.result != null) {
7173 byte[] responseData = (byte[])(result.result);
7174 if(responseData.length > oemResp.length) {
7175 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7176 responseData.length + "bytes. Buffer Size is " +
7177 oemResp.length + "bytes.");
7178 }
7179 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7180 returnValue = responseData.length;
7181 }
7182 } else {
7183 CommandException ex = (CommandException) result.exception;
7184 returnValue = ex.getCommandError().ordinal();
7185 if(returnValue > 0) returnValue *= -1;
7186 }
7187 } catch (RuntimeException e) {
7188 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7189 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7190 if(returnValue > 0) returnValue *= -1;
7191 }
7192
7193 return returnValue;
7194 }
7195
7196 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007197 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007198 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007199 try {
7200 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007201 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007202 mApp, phone.getSubId(), "getRadioAccessFamily");
7203 } catch (SecurityException e) {
7204 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7205 throw e;
7206 }
chen xub97461a2018-10-26 14:17:57 -07007207 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007208 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007209 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007210 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211 final long identity = Binder.clearCallingIdentity();
7212 try {
chen xub97461a2018-10-26 14:17:57 -07007213 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007214 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007215 mApp, phone.getSubId(), "getRadioAccessFamily");
7216 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007217 } finally {
7218 Binder.restoreCallingIdentity(identity);
7219 }
chen xub97461a2018-10-26 14:17:57 -07007220 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007221 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007222
7223 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007224 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007225 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007226 try {
7227 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7228 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007229 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007230 }
7231 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007232 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007233 }
7234 RoleManager rm = mApp.getSystemService(RoleManager.class);
7235 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7236 if (!dialerRoleHolders.contains(callingPackage)) {
7237 throw new SecurityException("App must be the dialer role holder to"
7238 + " upload a call composer pic");
7239 }
7240
7241 Executors.newSingleThreadExecutor().execute(() -> {
7242 ByteArrayOutputStream output = new ByteArrayOutputStream(
7243 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7244 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7245 boolean readUntilEnd = false;
7246 int totalBytesRead = 0;
7247 byte[] buffer = new byte[16 * 1024];
7248 while (true) {
7249 int numRead;
7250 try {
7251 numRead = input.read(buffer);
7252 } catch (IOException e) {
7253 try {
7254 fd.checkError();
7255 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7256 null);
7257 } catch (IOException e1) {
7258 // This means that the other side closed explicitly with an error. If this
7259 // happens, log and ignore.
7260 loge("Remote end of call composer picture pipe closed: " + e1);
7261 }
7262 break;
7263 }
7264 if (numRead == -1) {
7265 readUntilEnd = true;
7266 break;
7267 }
7268 totalBytesRead += numRead;
7269 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7270 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7271 try {
7272 input.close();
7273 } catch (IOException e) {
7274 // ignore
7275 }
7276 break;
7277 }
7278 output.write(buffer, 0, numRead);
7279 }
7280 // Generally, the remote end will close the file descriptors. The only case where we
7281 // close is above, where the picture size is too big.
7282
7283 try {
7284 fd.checkError();
7285 } catch (IOException e) {
7286 loge("Remote end for call composer closed with an error: " + e);
7287 return;
7288 }
7289
Hall Liuaa4211e2021-01-20 15:43:39 -08007290 if (!readUntilEnd) {
7291 loge("Did not finish reading entire image; aborting");
7292 return;
7293 }
Hall Liu82694d52020-12-11 18:22:04 -08007294
Hall Liuaa4211e2021-01-20 15:43:39 -08007295 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7296 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7297 new CallComposerPictureTransfer.Factory() {},
7298 imageData,
7299 (result) -> {
7300 if (result.first != null) {
7301 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7302 Bundle outputResult = new Bundle();
7303 outputResult.putParcelable(
7304 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7305 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7306 outputResult);
7307 } else {
7308 callback.send(result.second, null);
7309 }
7310 }
7311 );
Hall Liu82694d52020-12-11 18:22:04 -08007312 });
7313 }
7314
7315 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007316 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007317 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007318 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007319
7320 final long identity = Binder.clearCallingIdentity();
7321 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007322 ImsManager.getInstance(defaultPhone.getContext(),
7323 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007324 } finally {
7325 Binder.restoreCallingIdentity(identity);
7326 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007327 }
7328
7329 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007330 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007331 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007332 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7333 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007334 return false;
7335 }
Svet Ganovb320e182015-04-16 12:30:10 -07007336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 final long identity = Binder.clearCallingIdentity();
7338 try {
7339 // Check the user preference and the system-level IMS setting. Even if the user has
7340 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7341 // In the long run, we may instead need to check if there exists a connection service
7342 // which can support video calling.
7343 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007344 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345 return imsManager.isVtEnabledByPlatform()
7346 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7347 && imsManager.isVtEnabledByUser();
7348 } finally {
7349 Binder.restoreCallingIdentity(identity);
7350 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007351 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007352
Andrew Leea1239f22015-03-02 17:44:07 -08007353 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007354 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7355 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007356 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007357 mApp, subId, callingPackage, callingFeatureId,
7358 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007359 return false;
7360 }
7361
7362 final long identity = Binder.clearCallingIdentity();
7363 try {
7364 CarrierConfigManager configManager =
7365 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007366 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7368 } finally {
7369 Binder.restoreCallingIdentity(identity);
7370 }
Andrew Leea1239f22015-03-02 17:44:07 -08007371 }
7372
7373 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007374 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007376 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 return false;
7378 }
7379
7380 final long identity = Binder.clearCallingIdentity();
7381 try {
7382 CarrierConfigManager configManager =
7383 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007384 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7386 } finally {
7387 Binder.restoreCallingIdentity(identity);
7388 }
Andrew Leea1239f22015-03-02 17:44:07 -08007389 }
7390
Andrew Lee9431b832015-03-09 18:46:45 -07007391 @Override
7392 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007393 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007394 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007395 }
7396
7397 @Override
7398 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007399 final long identity = Binder.clearCallingIdentity();
7400 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007401 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007402 } finally {
7403 Binder.restoreCallingIdentity(identity);
7404 }
Andrew Lee9431b832015-03-09 18:46:45 -07007405 }
7406
Hall Liuf6668912018-10-31 17:05:23 -07007407 /**
7408 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7409 * support for the feature and device firmware support.
7410 *
7411 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7412 */
7413 @Override
7414 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007416 final Phone phone = getPhone(subscriptionId);
7417 if (phone == null) {
7418 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7419 return false;
7420 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007422 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007423 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7424 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007425 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 return isCarrierSupported && isDeviceSupported;
7427 } finally {
7428 Binder.restoreCallingIdentity(identity);
7429 }
Hall Liu98187582018-01-22 19:15:32 -08007430 }
7431
Hall Liuf6668912018-10-31 17:05:23 -07007432 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007433 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7434 * RTT setting, will return true if the device and carrier both support RTT.
7435 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007436 */
7437 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 final long identity = Binder.clearCallingIdentity();
7439 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007440 boolean isRttSupported = isRttSupported(subscriptionId);
7441 boolean isUserRttSettingOn = Settings.Secure.getInt(
7442 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7443 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7444 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7445 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 } finally {
7447 Binder.restoreCallingIdentity(identity);
7448 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007449 }
7450
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007451 @Deprecated
7452 @Override
7453 public String getDeviceId(String callingPackage) {
7454 return getDeviceIdWithFeature(callingPackage, null);
7455 }
7456
Sanket Padawe7310cc72015-01-14 09:53:20 -08007457 /**
7458 * Returns the unique device ID of phone, for example, the IMEI for
7459 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7460 *
7461 * <p>Requires Permission:
7462 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7463 */
7464 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007465 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007466 try {
7467 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7468 } catch (SecurityException se) {
7469 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7470 throw new SecurityException("Package " + callingPackage + " does not belong to "
7471 + Binder.getCallingUid());
7472 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007473 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007474 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007475 return null;
7476 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007477 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007478 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007479 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007480 return null;
7481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482
7483 final long identity = Binder.clearCallingIdentity();
7484 try {
7485 return phone.getDeviceId();
7486 } finally {
7487 Binder.restoreCallingIdentity(identity);
7488 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007489 }
7490
Ping Sunc67b7c22016-03-02 19:16:45 +08007491 /**
7492 * {@hide}
7493 * Returns the IMS Registration Status on a particular subid
7494 *
7495 * @param subId
7496 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007497 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007498 Phone phone = getPhone(subId);
7499 if (phone != null) {
7500 return phone.isImsRegistered();
7501 } else {
7502 return false;
7503 }
7504 }
7505
Santos Cordon7a1885b2015-02-03 11:15:19 -08007506 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007507 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007508 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007509 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007510 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007511 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7512 }
7513 final long identity = Binder.clearCallingIdentity();
7514 try {
7515 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7516 } finally {
7517 Binder.restoreCallingIdentity(identity);
7518 }
7519 }
7520
7521 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007522 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007523 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007524 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007525 mApp,
7526 subscriptionId,
7527 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007528 final long identity = Binder.clearCallingIdentity();
7529 try {
7530 Phone phone = getPhone(subscriptionId);
7531 if (phone == null) {
7532 return null;
7533 }
7534 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7535 } finally {
7536 Binder.restoreCallingIdentity(identity);
7537 }
7538 }
7539
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007540 /**
7541 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007542 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007543 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 final long identity = Binder.clearCallingIdentity();
7545 try {
7546 Phone phone = getPhone(subId);
7547 if (phone != null) {
7548 return phone.isWifiCallingEnabled();
7549 } else {
7550 return false;
7551 }
7552 } finally {
7553 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007554 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007555 }
7556
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007557 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007558 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007559 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007560 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007561 final long identity = Binder.clearCallingIdentity();
7562 try {
7563 Phone phone = getPhone(subId);
7564 if (phone != null) {
7565 return phone.isVideoEnabled();
7566 } else {
7567 return false;
7568 }
7569 } finally {
7570 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007571 }
7572 }
7573
7574 /**
7575 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7576 * defined in {@link ImsRegistrationImplBase}.
7577 */
7578 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579 final long identity = Binder.clearCallingIdentity();
7580 try {
7581 Phone phone = getPhone(subId);
7582 if (phone != null) {
7583 return phone.getImsRegistrationTech();
7584 } else {
7585 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7586 }
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007589 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007590 }
7591
Stuart Scott8eef64f2015-04-08 15:13:54 -07007592 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007593 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007594 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007595 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7596 return;
7597 }
Kai Shif70f46f2021-03-03 13:59:46 -08007598 Phone defaultPhone = getDefaultPhone();
7599 if (defaultPhone != null) {
7600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7601 mApp, getDefaultPhone().getSubId(), "factoryReset");
7602 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007603 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007604
Svet Ganovcc087f82015-05-12 20:35:54 -07007605 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007606 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7607 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007608 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007609 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007610 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007611 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007612 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007613 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007614 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007615 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007616 // There has been issues when Sms raw table somehow stores orphan
7617 // fragments. They lead to garbled message when new fragments come
7618 // in and combined with those stale ones. In case this happens again,
7619 // user can reset all network settings which will clean up this table.
7620 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007621 // Clean up IMS settings as well here.
7622 int slotId = getSlotIndex(subId);
7623 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7624 ImsManager.getInstance(mApp, slotId).factoryReset();
7625 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007626
Kai Shif70f46f2021-03-03 13:59:46 -08007627 if (defaultPhone == null) {
7628 return;
7629 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007630 // Erase modem config if erase modem on network setting is enabled.
7631 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7632 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7633 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007634 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007635 }
Kai Shif70f46f2021-03-03 13:59:46 -08007636
7637 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007638 } finally {
7639 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007640 }
7641 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007642
SongFerngWangfd89b102021-05-27 22:44:54 +08007643 @VisibleForTesting
7644 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7645 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7646 return;
7647 }
7648 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7649 RILConstants.PREFERRED_NETWORK_MODE);
7650 SubscriptionManager.setSubscriptionProperty(subId,
7651 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7652 "user=" + defaultNetworkType);
7653 phone.loadAllowedNetworksFromSubscriptionDatabase();
7654 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7655 defaultNetworkType, null);
7656 }
7657
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007658 private void cleanUpSmsRawTable(Context context) {
7659 ContentResolver resolver = context.getContentResolver();
7660 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7661 resolver.delete(uri, null, null);
7662 }
7663
Narayan Kamath1c496c22015-04-16 14:40:19 +01007664 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007665 public String getSimLocaleForSubscriber(int subId) {
7666 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7667 final Phone phone = getPhone(subId);
7668 if (phone == null) {
7669 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007670 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007671 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007672 final long identity = Binder.clearCallingIdentity();
7673 try {
chen xu5d3637b2019-01-21 23:31:38 -08007674 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007675 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007676 if (info == null) {
7677 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7678 return null;
7679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680 // Try and fetch the locale from the carrier properties or from the SIM language
7681 // preferences (EF-PL and EF-LI)...
7682 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007683 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007684 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7685 if (localeFromDefaultSim != null) {
7686 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7687 if (DBG) log("Using locale from subId: " + subId + " locale: "
7688 + localeFromDefaultSim);
tom hsu22b7c3e2022-10-27 00:10:04 +08007689 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007690 } else {
7691 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007692 }
7693 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695 // The SIM language preferences only store a language (e.g. fr = French), not an
7696 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7697 // the SIM and carrier preferences does not include a country we add the country
7698 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007699 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007700 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007701 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu22b7c3e2022-10-27 00:10:04 +08007702 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007703 }
7704
7705 if (DBG) log("No locale found - returning null");
7706 return null;
7707 } finally {
7708 Binder.restoreCallingIdentity(identity);
7709 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007710 }
7711
tom hsue9360cd2022-09-29 23:49:21 +08007712 @VisibleForTesting
tom hsu22b7c3e2022-10-27 00:10:04 +08007713 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsue9360cd2022-09-29 23:49:21 +08007714 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu22b7c3e2022-10-27 00:10:04 +08007715 phone.getContext());
tom hsue9360cd2022-09-29 23:49:21 +08007716 for (String localeTag : supportedLocale) {
tom hsu22b7c3e2022-10-27 00:10:04 +08007717 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7718 && TextUtils.equals(inputLocale.getCountry(),
tom hsue9360cd2022-09-29 23:49:21 +08007719 Locale.forLanguageTag(localeTag).getCountry())) {
7720 return localeTag;
7721 }
7722 }
7723 return inputLocale.toLanguageTag();
7724 }
7725
Narayan Kamath1c496c22015-04-16 14:40:19 +01007726 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007727 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007728 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007729 }
7730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731 /**
7732 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7733 */
7734 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007735 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007736 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007737 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007738
Gary Jian3aa9a762022-01-24 16:41:19 +08007739 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7740 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007741
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007742 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007743 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7744 * representing the state of the modem.
7745 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007746 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7747 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007748 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007749 */
7750 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007751 public void requestModemActivityInfo(ResultReceiver result) {
7752 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007753 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007754
7755 final long identity = Binder.clearCallingIdentity();
7756 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007757 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758 } finally {
7759 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007760 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007761 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007762
Siddharth Rayb8114062018-06-17 15:02:38 -07007763 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7764 // less than total activity duration.
7765 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7766 if (info == null) {
7767 return false;
7768 }
7769 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007770 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7771 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7772
Siddharth Rayb8114062018-06-17 15:02:38 -07007773 return (info.isValid()
7774 && (info.getSleepTimeMillis() <= activityDurationMs)
7775 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007776 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007777 && (totalTxTimeMs <= activityDurationMs));
7778 }
7779
Gary Jian3aa9a762022-01-24 16:41:19 +08007780 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7781 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7782 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7783 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7784
7785 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7786 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7787 }
7788
7789 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7790 mLastModemActivityInfo.setReceiveTimeMillis(
7791 rat,
7792 freq,
7793 info.getReceiveTimeMillis(rat, freq)
7794 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7795 }
7796
7797 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7798 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7799 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7800 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7801
7802 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7803 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7804 }
7805 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7806 mLastModemActivityInfo.setReceiveTimeMillis(
7807 rat,
7808 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7809 }
7810
7811 /**
7812 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7813 * @param info recent ModemActivityInfo
7814 */
7815 private void mergeModemActivityInfo(ModemActivityInfo info) {
7816 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7817 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7818 boolean matched;
7819 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7820 matched = false;
7821 int rat = info.getSpecificInfoRat(i);
7822 int freq = info.getSpecificInfoFrequencyRange(i);
7823 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7824 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7825 //if it already exists
7826 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7827 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7828 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7829 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7830 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7831 updateLastModemActivityInfo(info, rat, freq);
7832 matched = true;
7833 }
7834 } else {
7835 updateLastModemActivityInfo(info, rat);
7836 matched = true;
7837 }
7838 }
7839 }
7840
7841 if (!matched) {
7842 mDeltaSpecificInfo =
7843 new ActivityStatsTechSpecificInfo(
7844 rat,
7845 freq,
7846 info.getTransmitTimeMillis(rat, freq),
7847 (int) info.getReceiveTimeMillis(rat, freq));
7848 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7849 }
7850 }
7851 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7852 mLastModemActivitySpecificInfo =
7853 new ActivityStatsTechSpecificInfo[merged.size()];
7854 merged.toArray(mLastModemActivitySpecificInfo);
7855
7856 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7857 mLastModemActivityInfo.setSleepTimeMillis(
7858 info.getSleepTimeMillis()
7859 + mLastModemActivityInfo.getSleepTimeMillis());
7860 mLastModemActivityInfo.setIdleTimeMillis(
7861 info.getIdleTimeMillis()
7862 + mLastModemActivityInfo.getIdleTimeMillis());
7863 }
7864
Jack Yu85bd38a2015-11-09 11:34:32 -08007865 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007866 * Returns the service state information on specified subscription.
7867 */
7868 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007869 public ServiceState getServiceStateForSubscriber(int subId,
7870 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7871 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007872 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007873 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007874 return null;
7875 }
7876
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007877 boolean hasFinePermission = false;
7878 boolean hasCoarsePermission = false;
7879 if (!renounceFineLocationAccess) {
7880 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7881 LocationAccessPolicy.checkLocationPermission(mApp,
7882 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7883 .setCallingPackage(callingPackage)
7884 .setCallingFeatureId(callingFeatureId)
7885 .setCallingPid(Binder.getCallingPid())
7886 .setCallingUid(Binder.getCallingUid())
7887 .setMethod("getServiceStateForSubscriber")
7888 .setLogAsInfo(true)
7889 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7890 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7891 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7892 .build());
7893 hasFinePermission =
7894 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7895 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007896
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007897 if (!renounceCoarseLocationAccess) {
7898 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7899 LocationAccessPolicy.checkLocationPermission(mApp,
7900 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7901 .setCallingPackage(callingPackage)
7902 .setCallingFeatureId(callingFeatureId)
7903 .setCallingPid(Binder.getCallingPid())
7904 .setCallingUid(Binder.getCallingUid())
7905 .setMethod("getServiceStateForSubscriber")
7906 .setLogAsInfo(true)
7907 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7908 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7909 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7910 .build());
7911 hasCoarsePermission =
7912 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7913 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007914
Jack Yu479f40e2020-10-27 21:29:25 -07007915 final Phone phone = getPhone(subId);
7916 if (phone == null) {
7917 return null;
7918 }
7919
Jordan Liu0f2bc442020-11-18 16:47:37 -08007920 final long identity = Binder.clearCallingIdentity();
7921
Jack Yu479f40e2020-10-27 21:29:25 -07007922 boolean isCallingPackageDataService = phone.getDataServicePackages()
7923 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007924 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007925 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7926 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7927 Rlog.d(LOG_TAG,
7928 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7929 return null;
7930 }
7931
Hall Liuf19c44f2018-11-27 14:38:17 -08007932 ServiceState ss = phone.getServiceState();
7933
7934 // Scrub out the location info in ServiceState depending on what level of access
7935 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007936 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007937 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7938 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007939 } finally {
7940 Binder.restoreCallingIdentity(identity);
7941 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007942 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007943
7944 /**
7945 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7946 *
7947 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7948 * voicemail ringtone.
7949 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7950 * PhoneAccount.
7951 */
7952 @Override
7953 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007954 final long identity = Binder.clearCallingIdentity();
7955 try {
7956 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7957 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007958 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7962 } finally {
7963 Binder.restoreCallingIdentity(identity);
7964 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007965 }
7966
7967 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007968 * Sets the per-account voicemail ringtone.
7969 *
7970 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7971 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7972 *
7973 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7974 * voicemail ringtone.
7975 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7976 * PhoneAccount.
7977 */
7978 @Override
7979 public void setVoicemailRingtoneUri(String callingPackage,
7980 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007981 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007982 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007983 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7984 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7986 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7987 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007988 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007989
7990 final long identity = Binder.clearCallingIdentity();
7991 try {
7992 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7993 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007994 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007995 }
7996 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7997 } finally {
7998 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007999 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008000 }
8001
8002 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008003 * Returns whether vibration is set for voicemail notification in Phone settings.
8004 *
8005 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8006 * voicemail vibration setting.
8007 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8008 */
8009 @Override
8010 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008011 final long identity = Binder.clearCallingIdentity();
8012 try {
8013 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8014 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008015 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008016 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8019 } finally {
8020 Binder.restoreCallingIdentity(identity);
8021 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008022 }
8023
Youhan Wange64578a2016-05-02 15:32:42 -07008024 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008025 * Sets the per-account voicemail vibration.
8026 *
8027 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8028 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8029 *
8030 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8031 * voicemail vibration setting.
8032 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8033 * specific PhoneAccount.
8034 */
8035 @Override
8036 public void setVoicemailVibrationEnabled(String callingPackage,
8037 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008038 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008039 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008040 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8041 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8043 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8044 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008045 }
8046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047 final long identity = Binder.clearCallingIdentity();
8048 try {
8049 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8050 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008051 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008052 }
8053 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8054 } finally {
8055 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008056 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008057 }
8058
8059 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008060 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8061 *
8062 * @throws SecurityException if the caller does not have the required permission
8063 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008064 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008065 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008066 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008067 }
8068
8069 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008070 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8071 * permission.
8072 *
8073 * @throws SecurityException if the caller does not have the required permission
8074 */
8075 private void enforceSendSmsPermission() {
8076 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8077 }
8078
8079 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008080 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008081 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008082 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008083 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008084 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008085 final long identity = Binder.clearCallingIdentity();
8086 try {
8087 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008088 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008089 if (componentName == null) {
8090 throw new SecurityException(
8091 "Caller not current active visual voicemail package[null]");
8092 }
8093 String vvmPackage = componentName.getPackageName();
8094 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008095 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008096 }
8097 } finally {
8098 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008099 }
8100 }
8101
8102 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008103 * Return the application ID for the app type.
8104 *
8105 * @param subId the subscription ID that this request applies to.
8106 * @param appType the uicc app type.
8107 * @return Application ID for specificied app type, or null if no uicc.
8108 */
8109 @Override
8110 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008111 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008112 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008113
8114 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008115 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008116 if (phone == null) {
8117 return null;
8118 }
8119 String aid = null;
8120 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008121 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008122 .getApplicationByType(appType).getAid();
8123 } catch (Exception e) {
8124 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8125 }
8126 return aid;
8127 } finally {
8128 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008129 }
Youhan Wange64578a2016-05-02 15:32:42 -07008130 }
8131
Youhan Wang4001d252016-05-11 10:29:41 -07008132 /**
8133 * Return the Electronic Serial Number.
8134 *
8135 * @param subId the subscription ID that this request applies to.
8136 * @return ESN or null if error.
8137 */
8138 @Override
8139 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008140 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008141 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008142
8143 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008144 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008145 if (phone == null) {
8146 return null;
8147 }
8148 String esn = null;
8149 try {
8150 esn = phone.getEsn();
8151 } catch (Exception e) {
8152 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8153 }
8154 return esn;
8155 } finally {
8156 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008157 }
Youhan Wang4001d252016-05-11 10:29:41 -07008158 }
8159
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008160 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008161 * Return the Preferred Roaming List Version.
8162 *
8163 * @param subId the subscription ID that this request applies to.
8164 * @return PRLVersion or null if error.
8165 */
8166 @Override
8167 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008168 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008169 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008170
8171 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008172 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 if (phone == null) {
8174 return null;
8175 }
8176 String cdmaPrlVersion = null;
8177 try {
8178 cdmaPrlVersion = phone.getCdmaPrlVersion();
8179 } catch (Exception e) {
8180 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8181 }
8182 return cdmaPrlVersion;
8183 } finally {
8184 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008185 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008186 }
8187
8188 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008189 * Get snapshot of Telephony histograms
8190 * @return List of Telephony histograms
8191 * @hide
8192 */
8193 @Override
8194 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8196 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008197
8198 final long identity = Binder.clearCallingIdentity();
8199 try {
8200 return RIL.getTelephonyRILTimingHistograms();
8201 } finally {
8202 Binder.restoreCallingIdentity(identity);
8203 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008204 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008205
8206 /**
8207 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008208 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8209 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008210 * Require system privileges. In the future we may add this to carrier APIs.
8211 *
Michele Berionne482f8202018-11-27 18:57:59 -08008212 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008213 */
8214 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008215 @TelephonyManager.SetCarrierRestrictionResult
8216 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008217 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008218 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008219
Michele Berionne482f8202018-11-27 18:57:59 -08008220 if (carrierRestrictionRules == null) {
8221 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008222 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224 final long identity = Binder.clearCallingIdentity();
8225 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008226 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008227 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008228 } finally {
8229 Binder.restoreCallingIdentity(identity);
8230 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008231 }
8232
8233 /**
8234 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008235 * Get the allowed carrier list and the excluded carrier list, including the priority between
8236 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008237 * Require system privileges. In the future we may add this to carrier APIs.
8238 *
Michele Berionne482f8202018-11-27 18:57:59 -08008239 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008240 */
8241 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008242 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008243 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008244 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008245
8246 final long identity = Binder.clearCallingIdentity();
8247 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008248 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8249 if (response instanceof CarrierRestrictionRules) {
8250 return (CarrierRestrictionRules) response;
8251 }
8252 // Response is an Exception of some kind,
8253 // which is signalled to the user as a NULL retval
8254 return null;
8255 } catch (Exception e) {
8256 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8257 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258 } finally {
8259 Binder.restoreCallingIdentity(identity);
8260 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008261 }
8262
fionaxu59545b42016-05-25 15:53:37 -07008263 /**
fionaxu59545b42016-05-25 15:53:37 -07008264 * Action set from carrier signalling broadcast receivers to enable/disable radio
8265 * @param subId the subscription ID that this action applies to.
8266 * @param enabled control enable or disable radio.
8267 * {@hide}
8268 */
8269 @Override
8270 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8271 enforceModifyPermission();
8272 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008273
8274 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008275 if (phone == null) {
8276 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8277 return;
8278 }
8279 try {
8280 phone.carrierActionSetRadioEnabled(enabled);
8281 } catch (Exception e) {
8282 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283 } finally {
8284 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008285 }
8286 }
8287
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008288 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008289 * Enable or disable Voice over NR (VoNR)
8290 * @param subId the subscription ID that this action applies to.
8291 * @param enabled enable or disable VoNR.
8292 * @return operation result.
8293 */
8294 @Override
8295 public int setVoNrEnabled(int subId, boolean enabled) {
8296 enforceModifyPermission();
8297 final Phone phone = getPhone(subId);
8298
8299 final long identity = Binder.clearCallingIdentity();
8300 if (phone == null) {
8301 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8302 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8303 }
8304
8305 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8306 try {
8307 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8308 workSource);
8309 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008310
8311 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8312 if (DBG) {
8313 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8314 }
8315 SubscriptionManager.setSubscriptionProperty(
8316 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8317 (enabled ? "1" : "0"));
8318 }
8319
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008320 return result;
8321 } finally {
8322 Binder.restoreCallingIdentity(identity);
8323 }
8324 }
8325
8326 /**
8327 * Is voice over NR enabled
8328 * @return true if VoNR is enabled else false
8329 */
8330 @Override
8331 public boolean isVoNrEnabled(int subId) {
8332 enforceReadPrivilegedPermission("isVoNrEnabled");
8333 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8334 final long identity = Binder.clearCallingIdentity();
8335 try {
8336 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8337 null, subId, workSource);
8338 if (DBG) log("isVoNrEnabled: " + isEnabled);
8339 return isEnabled;
8340 } finally {
8341 Binder.restoreCallingIdentity(identity);
8342 }
8343 }
8344
8345 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008346 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8347 * network status based on which carrier apps could apply actions accordingly,
8348 * enable/disable default url handler for example.
8349 *
8350 * @param subId the subscription ID that this action applies to.
8351 * @param report control start/stop reporting the default network status.
8352 * {@hide}
8353 */
8354 @Override
8355 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8356 enforceModifyPermission();
8357 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008358
8359 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008360 if (phone == null) {
8361 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8362 return;
8363 }
8364 try {
8365 phone.carrierActionReportDefaultNetworkStatus(report);
8366 } catch (Exception e) {
8367 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368 } finally {
8369 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008370 }
8371 }
8372
8373 /**
fionaxud9622282017-07-17 17:51:30 -07008374 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8375 * @param subId the subscription ID that this action applies to.
8376 * {@hide}
8377 */
8378 @Override
8379 public void carrierActionResetAll(int subId) {
8380 enforceModifyPermission();
8381 final Phone phone = getPhone(subId);
8382 if (phone == null) {
8383 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8384 return;
8385 }
8386 try {
8387 phone.carrierActionResetAll();
8388 } catch (Exception e) {
8389 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8390 }
8391 }
8392
8393 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008394 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8395 * bug report is being generated.
8396 */
8397 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008398 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008399 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8400 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008401 writer.println("Permission Denial: can't dump Phone from pid="
8402 + Binder.getCallingPid()
8403 + ", uid=" + Binder.getCallingUid()
8404 + "without permission "
8405 + android.Manifest.permission.DUMP);
8406 return;
8407 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008408 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008409 }
Jack Yueb89b242016-06-22 13:27:47 -07008410
Brad Ebingerdac2f002018-04-03 15:17:52 -07008411 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008412 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8413 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8414 @NonNull String[] args) {
8415 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8416 this, in.getFileDescriptor(), out.getFileDescriptor(),
8417 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008418 }
8419
Jack Yueb89b242016-06-22 13:27:47 -07008420 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008421 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008422 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008423 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008424 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008425 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008426 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008427 */
8428 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008429 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008430 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008431 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8432 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8433 try {
8434 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008435 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008436 } catch (SecurityException se) {
8437 enforceModifyPermission();
8438 }
8439 } else {
8440 enforceModifyPermission();
8441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008442
8443 final long identity = Binder.clearCallingIdentity();
8444 try {
8445 Phone phone = getPhone(subId);
8446 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008447 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8448 phone.carrierActionSetMeteredApnsEnabled(enabled);
8449 } else {
Jack Yuabb10902022-07-31 00:43:21 -07008450 phone.getDataSettingsManager().setDataEnabled(
8451 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008453 }
8454 } finally {
8455 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008456 }
8457 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008458
8459 /**
8460 * Get Client request stats
8461 * @return List of Client Request Stats
8462 * @hide
8463 */
8464 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008465 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8466 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008468 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008469 return null;
8470 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008471 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008473 final long identity = Binder.clearCallingIdentity();
8474 try {
8475 if (phone != null) {
8476 return phone.getClientRequestStats();
8477 }
8478
8479 return null;
8480 } finally {
8481 Binder.restoreCallingIdentity(identity);
8482 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008483 }
8484
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008485 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008486 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008487 if (uid == Process.ROOT_UID && packageName == null) {
8488 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8489 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8490 // exception. ROOT_UID seems not to have a valid package name returned by
8491 // PackageManager, so just fake it here to avoid issues when running telephony shell
8492 // commands that plumb through the RIL as root, like so:
8493 // $ adb root
8494 // $ adb shell cmd phone ...
8495 packageName = "root";
8496 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008497 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008498 }
Jack Yueb4124c2017-02-16 15:32:43 -08008499
8500 /**
Grace Chen70990072017-03-24 17:21:30 -07008501 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008502 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008503 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008504 * @param state State of SIM (power down, power up, pass through)
8505 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8506 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8507 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008508 *
8509 **/
8510 @Override
Grace Chen70990072017-03-24 17:21:30 -07008511 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008512 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008513 Phone phone = PhoneFactory.getPhone(slotIndex);
8514
vagdeviaf9a5b92018-08-15 16:01:53 -07008515 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8516
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008517 final long identity = Binder.clearCallingIdentity();
8518 try {
8519 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008520 phone.setSimPowerState(state, null, workSource);
8521 }
8522 } finally {
8523 Binder.restoreCallingIdentity(identity);
8524 }
8525 }
8526
8527 /**
8528 * Set SIM card power state.
8529 *
8530 * @param slotIndex SIM slot id.
8531 * @param state State of SIM (power down, power up, pass through)
8532 * @param callback callback to trigger after success or failure
8533 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8534 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8535 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8536 *
8537 **/
8538 @Override
8539 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8540 IIntegerConsumer callback) {
8541 enforceModifyPermission();
8542 Phone phone = PhoneFactory.getPhone(slotIndex);
8543
8544 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8545
8546 final long identity = Binder.clearCallingIdentity();
8547 try {
8548 if (phone != null) {
8549 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8550 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008551 }
8552 } finally {
8553 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008554 }
8555 }
Shuo Qiandd210312017-04-12 22:11:33 +00008556
Tyler Gunn65d45c22017-06-05 11:22:26 -07008557 private boolean isUssdApiAllowed(int subId) {
8558 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008559 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008560 if (configManager == null) {
8561 return false;
8562 }
8563 PersistableBundle pb = configManager.getConfigForSubId(subId);
8564 if (pb == null) {
8565 return false;
8566 }
8567 return pb.getBoolean(
8568 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8569 }
8570
Shuo Qiandd210312017-04-12 22:11:33 +00008571 /**
8572 * Check if phone is in emergency callback mode
8573 * @return true if phone is in emergency callback mode
8574 * @param subId sub id
8575 */
goneil9c5f4872017-12-05 14:07:56 -08008576 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008577 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008578 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008579 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008580
8581 final long identity = Binder.clearCallingIdentity();
8582 try {
8583 if (phone != null) {
8584 return phone.isInEcm();
8585 } else {
8586 return false;
8587 }
8588 } finally {
8589 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008590 }
8591 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008592
8593 /**
8594 * Get the current signal strength information for the given subscription.
8595 * Because this information is not updated when the device is in a low power state
8596 * it should not be relied-upon to be current.
8597 * @param subId Subscription index
8598 * @return the most recent cached signal strength info from the modem
8599 */
8600 @Override
8601 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008602 final long identity = Binder.clearCallingIdentity();
8603 try {
8604 Phone p = getPhone(subId);
8605 if (p == null) {
8606 return null;
8607 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008609 return p.getSignalStrength();
8610 } finally {
8611 Binder.restoreCallingIdentity(identity);
8612 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008613 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008614
Pengquan Meng77b7f132018-08-22 14:49:57 -07008615 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008616 * Get the current modem radio state for the given slot.
8617 * @param slotIndex slot index.
8618 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008619 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008620 * @return the current radio power state from the modem
8621 */
8622 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008623 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008624 Phone phone = PhoneFactory.getPhone(slotIndex);
8625 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008626 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8627 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008628 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8629 }
8630
8631 final long identity = Binder.clearCallingIdentity();
8632 try {
8633 return phone.getRadioPowerState();
8634 } finally {
8635 Binder.restoreCallingIdentity(identity);
8636 }
8637 }
8638 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8639 }
8640
8641 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008642 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8643 *
8644 * <p>Requires one of the following permissions:
8645 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008646 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008647 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8648 * privileges.
8649 *
8650 * @param subId subscription id
8651 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8652 * {@code false}.
8653 */
8654 @Override
8655 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008656 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008657 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008658 try {
8659 mApp.enforceCallingOrSelfPermission(
8660 android.Manifest.permission.ACCESS_NETWORK_STATE,
8661 functionName);
8662 } catch (Exception e) {
8663 mApp.enforceCallingOrSelfPermission(
8664 permission.READ_BASIC_PHONE_STATE, functionName);
8665 }
Shuo Qian093013d2020-08-13 15:42:55 -07008666 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008667 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008668 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008669 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008670
Pengquan Menga1bb6272018-09-06 09:59:22 -07008671 boolean isEnabled = false;
8672 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008673 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008674 Phone phone = getPhone(subId);
8675 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008676 } finally {
8677 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008678 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008679 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008680 }
8681
8682
8683 /**
8684 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8685 *
8686 * <p> Requires permission:
8687 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8688 * privileges.
8689 *
8690 * @param subId subscription id
8691 * @param isEnabled {@code true} means enable, {@code false} means disable.
8692 */
8693 @Override
8694 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8696 mApp, subId, "setDataRoamingEnabled");
8697
Pengquan Menga1bb6272018-09-06 09:59:22 -07008698 final long identity = Binder.clearCallingIdentity();
8699 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008700 Phone phone = getPhone(subId);
8701 if (phone != null) {
8702 phone.setDataRoamingEnabled(isEnabled);
8703 }
8704 } finally {
8705 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008706 }
8707 }
8708
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008709 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008710 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008711 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008712 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008713 mApp, subId, "isManualNetworkSelectionAllowed");
8714
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008715 boolean isAllowed = true;
8716 final long identity = Binder.clearCallingIdentity();
8717 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008718 Phone phone = getPhone(subId);
8719 if (phone != null) {
8720 isAllowed = phone.isCspPlmnEnabled();
8721 }
8722 } finally {
8723 Binder.restoreCallingIdentity(identity);
8724 }
8725 return isAllowed;
8726 }
8727
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008728 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8729 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008730 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008731 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008732 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008733 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8734 if (phone == null) {
8735 return false;
8736 }
8737 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8738 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8739 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008740 }
8741
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008742 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008743 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008744 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008745 mApp.getSystemService(AppOpsManager.class)
8746 .checkPackage(Binder.getCallingUid(), callingPackage);
8747
Jordan Liu1e142fc2019-04-22 15:10:43 -07008748 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008749 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008750 try {
8751 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008752 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008753 } catch (SecurityException e) {
8754 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8755 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008756 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008757 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008758 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008759 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008760 }
sandeepjsb6c87872021-09-27 15:34:44 +00008761 // checking compatibility, if calling app's target SDK is T and beyond.
8762 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8763 Binder.getCallingUid())) {
8764 isIccIdAccessRestricted = true;
8765 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008766 final long identity = Binder.clearCallingIdentity();
8767 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008768 UiccController uiccController = UiccController.getInstance();
8769 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008770 if (hasReadPermission) {
8771 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008772 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008773
8774 // Remove private info if the caller doesn't have access
8775 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8776 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008777 //setting the value after compatibility check
8778 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008779 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8780 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008781 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008782 if (card == null) {
8783 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008784 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008785 continue;
8786 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008787 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8788 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008789 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008790 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008791 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008792 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8793 for (UiccPortInfo portInfo : portInfos) {
8794 UiccPort port = uiccController.getUiccPortForSlot(
8795 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8796 if (port == null) {
8797 // assume no access if port is null
8798 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8799 continue;
8800 }
8801 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8802 uiccPortInfos.add(portInfo);
8803 } else {
8804 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8805 }
8806 }
8807 filteredInfos.add(new UiccCardInfo(
8808 cardInfo.isEuicc(),
8809 cardInfo.getCardId(),
8810 null,
8811 cardInfo.getPhysicalSlotIndex(),
8812 cardInfo.isRemovable(),
8813 cardInfo.isMultipleEnabledProfilesSupported(),
8814 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008815 }
8816 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008817 } finally {
8818 Binder.restoreCallingIdentity(identity);
8819 }
8820 }
8821
sandeepjsb6c87872021-09-27 15:34:44 +00008822 /**
8823 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8824 * generally private and require carrier privileges to view.
8825 *
8826 * @hide
8827 */
8828 @NonNull
8829 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8830 List<UiccPortInfo> portinfo = new ArrayList<>();
8831 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8832 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8833 }
8834 return new UiccCardInfo(
8835 cardInfo.isEuicc(),
8836 cardInfo.getCardId(),
8837 null,
8838 cardInfo.getPhysicalSlotIndex(),
8839 cardInfo.isRemovable(),
8840 cardInfo.isMultipleEnabledProfilesSupported(),
8841 portinfo
8842 );
8843 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008844
sandeepjsb6c87872021-09-27 15:34:44 +00008845 /**
8846 * @hide
8847 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8848 * These values are generally private and require carrier privileges to view.
8849 */
8850 @NonNull
8851 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8852 return new UiccPortInfo(
8853 UiccPortInfo.ICCID_REDACTED,
8854 portInfo.getPortIndex(),
8855 portInfo.getLogicalSlotIndex(),
8856 portInfo.isActive()
8857 );
8858 }
8859 @Override
8860 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008861 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008862 mApp.getSystemService(AppOpsManager.class)
8863 .checkPackage(Binder.getCallingUid(), callingPackage);
8864
sandeepjsb6c87872021-09-27 15:34:44 +00008865 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008866
Aman Guptaf3c90b32022-03-17 04:54:16 +00008867 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8868 // we are reading iccId which is PII data.
8869 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008870
8871 // checking compatibility, if calling app's target SDK is T and beyond.
8872 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8873 Binder.getCallingUid())) {
8874 isLogicalSlotAccessRestricted = true;
8875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008876 final long identity = Binder.clearCallingIdentity();
8877 try {
8878 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008879 if (slots == null || slots.length == 0) {
8880 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008881 return null;
8882 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008883 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8884 for (int i = 0; i < slots.length; i++) {
8885 UiccSlot slot = slots[i];
8886 if (slot == null) {
8887 continue;
8888 }
8889
Jordan Liu7be7e652019-05-06 18:55:02 +00008890 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008891 UiccCard card = slot.getUiccCard();
8892 if (card != null) {
8893 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008894 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008895 cardId = slot.getEid();
8896 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00008897 // If cardId is null, use iccId of default port as cardId.
8898 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07008899 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008900 }
8901
Jordan Liu857451f2019-05-09 16:35:35 -07008902 if (cardId != null) {
8903 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8904 // if cardId is an EID, it's all digits so this is fine
8905 cardId = IccUtils.stripTrailingFs(cardId);
8906 }
8907
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008908 int cardState = 0;
8909 switch (slot.getCardState()) {
8910 case CARDSTATE_ABSENT:
8911 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8912 break;
8913 case CARDSTATE_PRESENT:
8914 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8915 break;
8916 case CARDSTATE_ERROR:
8917 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8918 break;
8919 case CARDSTATE_RESTRICTED:
8920 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8921 break;
8922 default:
8923 break;
8924
8925 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008926 List<UiccPortInfo> portInfos = new ArrayList<>();
8927 int[] portIndexes = slot.getPortList();
8928 for (int portIdx : portIndexes) {
8929 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00008930 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008931 portInfos.add(new UiccPortInfo(iccId, portIdx,
8932 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008933 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008934 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008935 slot.isEuicc(),
8936 cardId,
8937 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008938 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008939 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008940 //setting the value after compatibility check
8941 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008942 }
8943 return infos;
8944 } finally {
8945 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008946 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008947 }
8948
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008949 /* Returns null if doesn't have read permission or carrier privilege access. */
8950 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8951 boolean hasReadPermission) {
8952 String iccId = slot.getIccId(portIndex);
8953 if (hasReadPermission) { // if has read permission
8954 return iccId;
8955 } else {
8956 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8957 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8958 // if no read permission, checking carrier privilege access
8959 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8960 return iccId;
8961 }
8962 }
8963 }
8964 // No read permission or carrier privilege access.
8965 return UiccPortInfo.ICCID_REDACTED;
8966 }
8967
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008968 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008969 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008970 public boolean switchSlots(int[] physicalSlots) {
8971 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008972
8973 final long identity = Binder.clearCallingIdentity();
8974 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008975 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8976 for (int i = 0; i < physicalSlots.length; i++) {
8977 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8978 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8979 physicalSlots[i], i));
8980 }
8981 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008982 } finally {
8983 Binder.restoreCallingIdentity(identity);
8984 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008985 }
Jack Yu4c988042018-02-27 15:30:01 -08008986
8987 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008988 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8989 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8990 enforceModifyPermission();
8991
8992 final long identity = Binder.clearCallingIdentity();
8993 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008994 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00008995 } finally {
8996 Binder.restoreCallingIdentity(identity);
8997 }
8998 }
8999
9000 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009001 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009002 final long identity = Binder.clearCallingIdentity();
9003 try {
9004 return UiccController.getInstance().getCardIdForDefaultEuicc();
9005 } finally {
9006 Binder.restoreCallingIdentity(identity);
9007 }
9008 }
9009
Pengquan Meng85728fb2018-03-12 16:31:21 -07009010 /**
goneil47ffb6e2018-04-06 15:40:58 -07009011 * A test API to reload the UICC profile.
9012 *
9013 * <p>Requires that the calling app has permission
9014 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9015 * @hide
9016 */
9017 @Override
9018 public void refreshUiccProfile(int subId) {
9019 enforceModifyPermission();
9020
9021 final long identity = Binder.clearCallingIdentity();
9022 try {
9023 Phone phone = getPhone(subId);
9024 if (phone == null) {
9025 return;
9026 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009027 UiccPort uiccPort = phone.getUiccPort();
9028 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009029 return;
9030 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009031 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009032 if (uiccProfile == null) {
9033 return;
9034 }
9035 uiccProfile.refresh();
9036 } finally {
9037 Binder.restoreCallingIdentity(identity);
9038 }
9039 }
9040
9041 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009042 * Returns false if the mobile data is disabled by default, otherwise return true.
9043 */
9044 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009045 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009046 }
9047
9048 /**
9049 * Returns true if the data roaming is enabled by default, i.e the system property
9050 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9051 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9052 */
9053 private boolean getDefaultDataRoamingEnabled(int subId) {
9054 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009055 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009056 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009057 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9058 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9059 return isDataRoamingEnabled;
9060 }
9061
9062 /**
9063 * Returns the default network type for the given {@code subId}, if the default network type is
9064 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9065 */
9066 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009067 List<Integer> list = TelephonyProperties.default_network();
9068 int phoneId = mSubscriptionController.getPhoneId(subId);
9069 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9070 return list.get(phoneId);
9071 }
9072 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009073 }
fionaxua13278b2018-03-21 00:08:13 -07009074
9075 @Override
9076 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009077 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009078 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009079
9080 final long identity = Binder.clearCallingIdentity();
9081 try {
9082 final Phone phone = getPhone(subId);
9083 if (phone == null) {
9084 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9085 return;
9086 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009087 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9088 if (cpt != null) {
9089 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9090 }
9091 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009092 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9093 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009094 if (carrierPrivilegeRules == null) {
9095 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9096 } else {
9097 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9098 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009099 } finally {
9100 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009101 }
fionaxua13278b2018-03-21 00:08:13 -07009102 }
9103
9104 @Override
9105 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009106 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009107
9108 final long identity = Binder.clearCallingIdentity();
9109 try {
9110 final Phone phone = getPhone(subId);
9111 if (phone == null) {
9112 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9113 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9114 }
9115 return phone.getCarrierIdListVersion();
9116 } finally {
9117 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009118 }
fionaxua13278b2018-03-21 00:08:13 -07009119 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009120
9121 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009122 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9123 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009124 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009125 mApp, subId, callingPackage, callingFeatureId,
9126 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009127 return -1;
9128 }
9129
9130 final long identity = Binder.clearCallingIdentity();
9131 try {
9132 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9133 } finally {
9134 Binder.restoreCallingIdentity(identity);
9135 }
9136 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009137
9138 @Override
9139 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009140 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009141 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009142 mApp, subId, "getCdmaRoamingMode");
9143
9144 final long identity = Binder.clearCallingIdentity();
9145 try {
9146 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9147 } finally {
9148 Binder.restoreCallingIdentity(identity);
9149 }
9150 }
9151
9152 @Override
9153 public boolean setCdmaRoamingMode(int subId, int mode) {
9154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9155 mApp, subId, "setCdmaRoamingMode");
9156
9157 final long identity = Binder.clearCallingIdentity();
9158 try {
9159 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9160 } finally {
9161 Binder.restoreCallingIdentity(identity);
9162 }
9163 }
9164
9165 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009166 public int getCdmaSubscriptionMode(int subId) {
9167 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009168 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009169 mApp, subId, "getCdmaSubscriptionMode");
9170
9171 final long identity = Binder.clearCallingIdentity();
9172 try {
9173 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9174 } finally {
9175 Binder.restoreCallingIdentity(identity);
9176 }
9177 }
9178
9179 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009180 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9182 mApp, subId, "setCdmaSubscriptionMode");
9183
9184 final long identity = Binder.clearCallingIdentity();
9185 try {
9186 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9187 } finally {
9188 Binder.restoreCallingIdentity(identity);
9189 }
9190 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009191
sqianc5eccab2018-10-19 18:46:41 -07009192 @Override
sqian8c685422019-02-22 15:55:18 -08009193 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009194 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009195 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009196 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9197 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009198 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9199 }
9200 final long identity = Binder.clearCallingIdentity();
9201 try {
sqian854d44b2018-12-12 16:48:18 -08009202 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9203 for (Phone phone: PhoneFactory.getPhones()) {
9204 if (phone.getEmergencyNumberTracker() != null
9205 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9206 emergencyNumberListInternal.put(
9207 phone.getSubId(),
9208 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9209 }
sqian11b7a0e2018-12-05 18:48:28 -08009210 }
sqian854d44b2018-12-12 16:48:18 -08009211 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009212 } finally {
9213 Binder.restoreCallingIdentity(identity);
9214 }
sqianc5eccab2018-10-19 18:46:41 -07009215 }
9216
9217 @Override
sqian8c685422019-02-22 15:55:18 -08009218 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009219 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009220 if (!exactMatch) {
9221 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009222 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009223 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009224 }
9225 final long identity = Binder.clearCallingIdentity();
9226 try {
sqian854d44b2018-12-12 16:48:18 -08009227 for (Phone phone: PhoneFactory.getPhones()) {
9228 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009229 && phone.getEmergencyNumberTracker()
9230 .isEmergencyNumber(number, exactMatch)) {
9231 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009232 }
sqian11b7a0e2018-12-05 18:48:28 -08009233 }
9234 return false;
9235 } finally {
9236 Binder.restoreCallingIdentity(identity);
9237 }
9238 }
9239
sqianf4ca7ed2019-01-15 18:32:07 -08009240 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009241 * Start emergency callback mode for GsmCdmaPhone for testing.
9242 */
9243 @Override
9244 public void startEmergencyCallbackMode() {
9245 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9246 "startEmergencyCallbackMode");
9247 enforceModifyPermission();
9248 final long identity = Binder.clearCallingIdentity();
9249 try {
9250 for (Phone phone : PhoneFactory.getPhones()) {
9251 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9252 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9253 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9254 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9255 gsmCdmaPhone.obtainMessage(
9256 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9257 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9258 }
9259 }
9260 } finally {
9261 Binder.restoreCallingIdentity(identity);
9262 }
9263 }
9264
9265 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009266 * Update emergency number list for test mode.
9267 */
9268 @Override
9269 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9270 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9271 "updateEmergencyNumberListTestMode");
9272
9273 final long identity = Binder.clearCallingIdentity();
9274 try {
9275 for (Phone phone: PhoneFactory.getPhones()) {
9276 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9277 if (tracker != null) {
9278 tracker.executeEmergencyNumberTestModeCommand(action, num);
9279 }
9280 }
9281 } finally {
9282 Binder.restoreCallingIdentity(identity);
9283 }
9284 }
9285
9286 /**
9287 * Get the full emergency number list for test mode.
9288 */
9289 @Override
9290 public List<String> getEmergencyNumberListTestMode() {
9291 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9292 "getEmergencyNumberListTestMode");
9293
9294 final long identity = Binder.clearCallingIdentity();
9295 try {
9296 Set<String> emergencyNumbers = new HashSet<>();
9297 for (Phone phone: PhoneFactory.getPhones()) {
9298 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9299 if (tracker != null) {
9300 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9301 emergencyNumbers.add(num.getNumber());
9302 }
9303 }
9304 }
9305 return new ArrayList<>(emergencyNumbers);
9306 } finally {
9307 Binder.restoreCallingIdentity(identity);
9308 }
9309 }
9310
chen xud6b45bd2018-10-30 22:27:10 -07009311 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009312 public int getEmergencyNumberDbVersion(int subId) {
9313 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9314
9315 final long identity = Binder.clearCallingIdentity();
9316 try {
9317 final Phone phone = getPhone(subId);
9318 if (phone == null) {
9319 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9320 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9321 }
9322 return phone.getEmergencyNumberDbVersion();
9323 } finally {
9324 Binder.restoreCallingIdentity(identity);
9325 }
9326 }
9327
9328 @Override
9329 public void notifyOtaEmergencyNumberDbInstalled() {
9330 enforceModifyPermission();
9331
9332 final long identity = Binder.clearCallingIdentity();
9333 try {
9334 for (Phone phone: PhoneFactory.getPhones()) {
9335 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9336 if (tracker != null) {
9337 tracker.updateOtaEmergencyNumberDatabase();
9338 }
9339 }
9340 } finally {
9341 Binder.restoreCallingIdentity(identity);
9342 }
9343 }
9344
9345 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009346 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009347 enforceActiveEmergencySessionPermission();
9348
9349 final long identity = Binder.clearCallingIdentity();
9350 try {
9351 for (Phone phone: PhoneFactory.getPhones()) {
9352 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9353 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009354 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9355 }
9356 }
9357 } finally {
9358 Binder.restoreCallingIdentity(identity);
9359 }
9360 }
9361
9362 @Override
9363 public void resetOtaEmergencyNumberDbFilePath() {
9364 enforceActiveEmergencySessionPermission();
9365
9366 final long identity = Binder.clearCallingIdentity();
9367 try {
9368 for (Phone phone: PhoneFactory.getPhones()) {
9369 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9370 if (tracker != null) {
9371 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009372 }
9373 }
9374 } finally {
9375 Binder.restoreCallingIdentity(identity);
9376 }
9377 }
9378
9379 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009380 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9381 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9382 Phone phone = getPhone(subId);
9383 if (phone == null) {
9384 return null;
9385 }
9386 final long identity = Binder.clearCallingIdentity();
9387 try {
9388 UiccProfile profile = UiccController.getInstance()
9389 .getUiccProfileForPhone(phone.getPhoneId());
9390 if (profile != null) {
9391 return profile.getCertsFromCarrierPrivilegeAccessRules();
9392 }
9393 } finally {
9394 Binder.restoreCallingIdentity(identity);
9395 }
9396 return null;
9397 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009398
9399 /**
9400 * Enable or disable a modem stack.
9401 */
9402 @Override
9403 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9404 enforceModifyPermission();
9405
9406 final long identity = Binder.clearCallingIdentity();
9407 try {
9408 Phone phone = PhoneFactory.getPhone(slotIndex);
9409 if (phone == null) {
9410 return false;
9411 } else {
9412 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9413 }
9414 } finally {
9415 Binder.restoreCallingIdentity(identity);
9416 }
9417 }
Michelecea4cf22018-12-21 15:00:11 -08009418
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009419 /**
9420 * Whether a modem stack is enabled or not.
9421 */
9422 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009423 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9424 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009425 Phone phone = PhoneFactory.getPhone(slotIndex);
9426 if (phone == null) return false;
9427
9428 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009429 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9430 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009431 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9432 }
9433
9434 final long identity = Binder.clearCallingIdentity();
9435 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009436 try {
9437 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9438 } catch (NoSuchElementException ex) {
9439 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9440 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009441 } finally {
9442 Binder.restoreCallingIdentity(identity);
9443 }
9444 }
9445
Michelecea4cf22018-12-21 15:00:11 -08009446 @Override
Michele0ea7d782019-03-19 14:58:42 -07009447 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009448 enforceModifyPermission();
9449
9450 final long identity = Binder.clearCallingIdentity();
9451 try {
9452 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009453 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009454 .commit();
9455 } finally {
9456 Binder.restoreCallingIdentity(identity);
9457 }
9458 }
9459
9460 @Override
Michele0ea7d782019-03-19 14:58:42 -07009461 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009462 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009464 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9465 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009466 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009467 }
Michelecea4cf22018-12-21 15:00:11 -08009468
9469 final long identity = Binder.clearCallingIdentity();
9470 try {
Michele0ea7d782019-03-19 14:58:42 -07009471 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009472 } finally {
9473 Binder.restoreCallingIdentity(identity);
9474 }
9475 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009476
Michele0ea7d782019-03-19 14:58:42 -07009477 @TelephonyManager.IsMultiSimSupportedResult
9478 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009479 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9480 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9481 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009482 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9483 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009484 }
9485 // Check if the hardware supports multisim functionality. If usage of multisim is not
9486 // supported by the modem, indicate that it is restricted.
9487 PhoneCapability staticCapability =
9488 mPhoneConfigurationManager.getStaticPhoneCapability();
9489 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009490 loge("isMultiSimSupportedInternal: no static configuration available");
9491 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009492 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009493 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009494 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9495 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009496 }
9497 // Check if support of multiple SIMs is restricted by carrier
9498 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009499 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009500 }
9501
Michele0ea7d782019-03-19 14:58:42 -07009502 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009503 }
9504
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009505 /**
9506 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009507 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9508 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9509 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009510 * @param numOfSims number of active sims we want to switch to
9511 */
9512 @Override
9513 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009514 if (numOfSims == 1) {
9515 enforceModifyPermission();
9516 } else {
9517 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9518 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9519 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009520 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009521
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009522 try {
Michele30b57b22019-03-01 12:01:14 -08009523 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009524 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009525 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9526 return;
9527 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009528 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9529 } finally {
9530 Binder.restoreCallingIdentity(identity);
9531 }
9532 }
9533
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009534 @Override
9535 public boolean isApplicationOnUicc(int subId, int appType) {
9536 enforceReadPrivilegedPermission("isApplicationOnUicc");
9537 Phone phone = getPhone(subId);
9538 if (phone == null) {
9539 return false;
9540 }
9541 final long identity = Binder.clearCallingIdentity();
9542 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009543 UiccPort uiccPort = phone.getUiccPort();
9544 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009545 return false;
9546 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009547 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009548 if (uiccProfile == null) {
9549 return false;
9550 }
9551 if (TelephonyManager.APPTYPE_SIM <= appType
9552 && appType <= TelephonyManager.APPTYPE_ISIM) {
9553 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9554 }
9555 return false;
9556 } finally {
9557 Binder.restoreCallingIdentity(identity);
9558 }
9559 }
9560
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009561 /**
chen xub4baa772019-04-03 10:23:41 -07009562 * Get whether making changes to modem configurations will trigger reboot.
9563 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009564 */
9565 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009566 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9567 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009568 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009569 mApp, subId, callingPackage, callingFeatureId,
9570 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009571 return false;
9572 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009573 final long identity = Binder.clearCallingIdentity();
9574 try {
9575 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9576 } finally {
9577 Binder.restoreCallingIdentity(identity);
9578 }
9579 }
9580
Nathan Harold29f5f052019-02-15 13:41:57 -08009581 private void updateModemStateMetrics() {
9582 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9583 // TODO: check the state for each modem if the api is ready.
9584 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9585 }
9586
Pengquan Meng3889a572019-01-23 11:16:29 -08009587 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009588 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009589 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009590 // Verify that the callingPackage belongs to the calling UID
9591 mApp.getSystemService(AppOpsManager.class)
9592 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009593 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009594 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009595 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009596 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9597 if (slotInfos != null) {
9598 for (int i = 0; i < slotInfos.length; i++) {
9599 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9600 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9601 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9602 portInfo.getLogicalSlotIndex()));
9603 }
9604 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009605 }
9606 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009607 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009608 } finally {
9609 Binder.restoreCallingIdentity(identity);
9610 }
9611 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009612
9613 /**
9614 * Get the IRadio HAL Version
9615 */
9616 @Override
9617 public int getRadioHalVersion() {
9618 Phone phone = getDefaultPhone();
9619 if (phone == null) return -1;
9620 HalVersion hv = phone.getHalVersion();
9621 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9622 return hv.major * 100 + hv.minor;
9623 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009624
9625 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009626 * Get the current calling package name.
9627 * @return the current calling package name
9628 */
9629 @Override
9630 public String getCurrentPackageName() {
9631 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9632 }
9633
9634 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009635 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9636 * corresponding network requests on a subId.
9637 *
9638 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009639 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009640 * 2) APN is un-metered for this subscription, or
9641 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009642 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009643 *
9644 * @return whether data is allowed for a apn type.
9645 *
9646 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009647 */
9648 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009649 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009650 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9651 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009652
9653 // Now that all security checks passes, perform the operation as ourselves.
9654 final long identity = Binder.clearCallingIdentity();
9655 try {
9656 Phone phone = getPhone(subId);
9657 if (phone == null) return false;
9658
Jack Yu27422a52022-03-21 10:38:05 -07009659 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009660 boolean isDataEnabled;
Jack Yuabb10902022-07-31 00:43:21 -07009661 isMetered = phone.getDataNetworkController().getDataConfigManager()
9662 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9663 phone.getServiceState().getDataRoaming());
9664 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009665 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009666 } finally {
9667 Binder.restoreCallingIdentity(identity);
9668 }
9669 }
9670
9671 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009672 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009673 enforceReadPrivilegedPermission("isApnMetered");
9674
9675 // Now that all security checks passes, perform the operation as ourselves.
9676 final long identity = Binder.clearCallingIdentity();
9677 try {
9678 Phone phone = getPhone(subId);
9679 if (phone == null) return true; // By default return true.
Jack Yuabb10902022-07-31 00:43:21 -07009680 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9681 DataUtils.apnTypeToNetworkCapability(apnType),
9682 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009683 } finally {
9684 Binder.restoreCallingIdentity(identity);
9685 }
9686 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009687
9688 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009689 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9690 int subscriptionId, IBooleanConsumer resultCallback) {
9691 enforceModifyPermission();
9692 long token = Binder.clearCallingIdentity();
9693 try {
9694 Phone phone = getPhone(subscriptionId);
9695 if (phone == null) {
9696 try {
9697 if (resultCallback != null) {
9698 resultCallback.accept(false);
9699 }
9700 } catch (RemoteException e) {
9701 // ignore
9702 }
9703 return;
9704 }
9705 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9706 Pair.create(specifiers, (x) -> {
9707 try {
9708 if (resultCallback != null) {
9709 resultCallback.accept(x);
9710 }
9711 } catch (RemoteException e) {
9712 // ignore
9713 }
9714 });
9715 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9716 } finally {
9717 Binder.restoreCallingIdentity(token);
9718 }
9719 }
9720
9721 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009722 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9723 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009724 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009725 mApp, subId, "getSystemSelectionChannels");
9726 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9727 final long identity = Binder.clearCallingIdentity();
9728 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009729 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9730 if (result instanceof IllegalStateException) {
9731 throw (IllegalStateException) result;
9732 }
9733 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009734 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9735 return specifiers;
9736 } finally {
9737 Binder.restoreCallingIdentity(identity);
9738 }
9739 }
9740
9741 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009742 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009743 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009744 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009745 }
9746
9747 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009748 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9749 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009750 if (callingPackage == null) {
9751 callingPackage = getCurrentPackageName();
9752 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009753 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9754 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009755 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9756 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009757 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9758 }
9759 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9760 Intent intent = new Intent();
9761 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9762 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9763 // Bring up choose default SMS subscription dialog right now
9764 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9765 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9766 mApp.startActivity(intent);
9767 }
chen xud5ca2d52019-05-28 15:20:57 -07009768
9769 @Override
9770 public String getMmsUAProfUrl(int subId) {
9771 //TODO investigate if this API should require proper permission check in R b/133791609
9772 final long identity = Binder.clearCallingIdentity();
9773 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009774 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9775 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9776 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9777 return carrierUAProfUrl;
9778 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009779 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9780 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009781 } finally {
9782 Binder.restoreCallingIdentity(identity);
9783 }
9784 }
9785
9786 @Override
9787 public String getMmsUserAgent(int subId) {
9788 //TODO investigate if this API should require proper permission check in R b/133791609
9789 final long identity = Binder.clearCallingIdentity();
9790 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009791 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9792 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9793 if (!TextUtils.isEmpty(carrierUserAgent)) {
9794 return carrierUserAgent;
9795 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009796 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9797 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009798 } finally {
9799 Binder.restoreCallingIdentity(identity);
9800 }
9801 }
Jack Yub07d4972019-05-28 16:12:25 -07009802
9803 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009804 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9805 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009806
Jack Yub07d4972019-05-28 16:12:25 -07009807 final long identity = Binder.clearCallingIdentity();
9808 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009809 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009810 if (phone == null) return false;
9811
Ling Ma58448e42022-09-16 15:22:36 -07009812 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -07009813 } finally {
9814 Binder.restoreCallingIdentity(identity);
9815 }
9816 }
9817
9818 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009819 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009820 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009821 enforceModifyPermission();
9822
changbettyd5c246e2019-12-24 15:40:37 +08009823 final long identity = Binder.clearCallingIdentity();
9824 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009825 Phone phone = getPhone(subscriptionId);
9826 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009827
Ling Ma58448e42022-09-16 15:22:36 -07009828 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +08009829 } finally {
9830 Binder.restoreCallingIdentity(identity);
9831 }
9832 }
9833
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009834 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009835 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009836 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9837 * otherwise.
9838 */
9839 @Override
9840 public void setCepEnabled(boolean isCepEnabled) {
9841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9842
9843 final long identity = Binder.clearCallingIdentity();
9844 try {
9845 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9846 for (Phone phone : PhoneFactory.getPhones()) {
9847 Phone defaultPhone = phone.getImsPhone();
9848 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9849 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9850 ImsPhoneCallTracker imsPhoneCallTracker =
9851 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9852 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9853 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9854 + imsPhone.getMsisdn());
9855 }
9856 }
9857 } finally {
9858 Binder.restoreCallingIdentity(identity);
9859 }
9860 }
allenwtsu46dcc572020-01-08 18:24:03 +08009861
9862 /**
9863 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9864 *
9865 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9866 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9867 * before being read.
9868 */
9869 @Override
9870 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9871 isCompressed) {
9872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9873 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009874 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9875 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9876 }
9877 if (!isImsAvailableOnDevice()) {
9878 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9879 "IMS not available on device.");
9880 }
9881
9882 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009883 try {
Hui Wang761a6682020-10-31 05:12:53 +00009884 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9885 } finally {
9886 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009887 }
9888 }
zoey chene02881a2019-12-30 16:11:23 +08009889
9890 @Override
9891 public boolean isIccLockEnabled(int subId) {
9892 enforceReadPrivilegedPermission("isIccLockEnabled");
9893
9894 // Now that all security checks passes, perform the operation as ourselves.
9895 final long identity = Binder.clearCallingIdentity();
9896 try {
9897 Phone phone = getPhone(subId);
9898 if (phone != null && phone.getIccCard() != null) {
9899 return phone.getIccCard().getIccLockEnabled();
9900 } else {
9901 return false;
9902 }
9903 } finally {
9904 Binder.restoreCallingIdentity(identity);
9905 }
9906 }
9907
9908 /**
9909 * Set the ICC pin lock enabled or disabled.
9910 *
9911 * @return an integer representing the status of IccLock enabled or disabled in the following
9912 * three cases:
9913 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9914 * successfully.
9915 * - Positive number and zero for remaining password attempts.
9916 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9917 *
9918 */
9919 @Override
9920 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9921 enforceModifyPermission();
9922
9923 Phone phone = getPhone(subId);
9924 if (phone == null) {
9925 return 0;
9926 }
9927 // Now that all security checks passes, perform the operation as ourselves.
9928 final long identity = Binder.clearCallingIdentity();
9929 try {
9930 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9931 new Pair<Boolean, String>(enabled, password), phone, null);
9932 return attemptsRemaining;
9933
9934 } catch (Exception e) {
9935 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9936 } finally {
9937 Binder.restoreCallingIdentity(identity);
9938 }
9939 return 0;
9940 }
9941
9942 /**
9943 * Change the ICC password used in ICC pin lock.
9944 *
9945 * @return an integer representing the status of IccLock changed in the following three cases:
9946 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9947 * - Positive number and zero for remaining password attempts.
9948 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9949 *
9950 */
9951 @Override
9952 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9953 enforceModifyPermission();
9954
9955 Phone phone = getPhone(subId);
9956 if (phone == null) {
9957 return 0;
9958 }
9959 // Now that all security checks passes, perform the operation as ourselves.
9960 final long identity = Binder.clearCallingIdentity();
9961 try {
9962 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9963 new Pair<String, String>(oldPassword, newPassword), phone, null);
9964 return attemptsRemaining;
9965
9966 } catch (Exception e) {
9967 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9968 } finally {
9969 Binder.restoreCallingIdentity(identity);
9970 }
9971 return 0;
9972 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009973
9974 /**
9975 * Request for receiving user activity notification
9976 */
9977 @Override
9978 public void requestUserActivityNotification() {
9979 if (!mNotifyUserActivity.get()
9980 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9981 mNotifyUserActivity.set(true);
9982 }
9983 }
9984
9985 /**
9986 * Called when userActivity is signalled in the power manager.
9987 * This is safe to call from any thread, with any window manager locks held or not.
9988 */
9989 @Override
9990 public void userActivity() {
9991 // ***************************************
9992 // * Inherited from PhoneWindowManager *
9993 // ***************************************
9994 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9995 // WITH ITS LOCKS HELD.
9996 //
9997 // This code must be VERY careful about the locks
9998 // it acquires.
9999 // In fact, the current code acquires way too many,
10000 // and probably has lurking deadlocks.
10001
10002 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10003 throw new SecurityException("Only the OS may call notifyUserActivity()");
10004 }
10005
10006 if (mNotifyUserActivity.getAndSet(false)) {
10007 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10008 USER_ACTIVITY_NOTIFICATION_DELAY);
10009 }
10010 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010011
10012 @Override
10013 public boolean canConnectTo5GInDsdsMode() {
10014 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10015 }
Jack Yud10cdd42020-09-28 20:28:01 -070010016
10017 @Override
10018 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10019 String callingFeatureId) {
10020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10021 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10022 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10023 }
10024
10025 Phone phone = getPhone(subId);
10026 if (phone == null) {
10027 throw new RuntimeException("phone is not available");
10028 }
10029 // Now that all security checks passes, perform the operation as ourselves.
10030 final long identity = Binder.clearCallingIdentity();
10031 try {
10032 return phone.getEquivalentHomePlmns();
10033 } finally {
10034 Binder.restoreCallingIdentity(identity);
10035 }
10036 }
Daniel Bright59e67312020-11-13 11:49:37 -080010037
10038 @Override
10039 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010040 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10041 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010042 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010043 if (radioInterfaceCapabilities == null) {
10044 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010045 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010046 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010047 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010048
Hui Wang641e81c2020-10-12 12:14:23 -070010049 @Override
10050 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10051 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010052 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10053 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10054 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10055 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10056 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010057 if (DBG) {
10058 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10059 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10060 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10061 }
10062
10063 if (!SubscriptionManager.isValidSubscriptionId(subId)
10064 || appType < TelephonyManager.APPTYPE_UNKNOWN
10065 || appType > TelephonyManager.APPTYPE_ISIM
10066 || nafUrl == null || securityProtocol == null || callback == null) {
10067 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10068 if (callback != null) {
10069 try {
10070 callback.onAuthenticationFailure(
10071 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10072 } catch (RemoteException exception) {
10073 log("Fail to notify onAuthenticationFailure due to " + exception);
10074 }
10075 return;
10076 }
10077 }
10078
10079 final long token = Binder.clearCallingIdentity();
10080 try {
10081 getGbaManager(subId).bootstrapAuthenticationRequest(
10082 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10083 forceBootStrapping, callback));
10084 } finally {
10085 Binder.restoreCallingIdentity(token);
10086 }
10087 }
10088
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010089 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010090 * Attempts to set the radio power state for all phones for thermal reason.
10091 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010092 * requested radio power state will actually be set. See {@link
10093 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10094 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010095 * @param enable {@code true} if trying to turn radio on.
10096 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10097 * false}.
10098 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010099 private boolean setRadioPowerForThermal(boolean enable) {
10100 boolean isPhoneAvailable = false;
10101 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10102 Phone phone = PhoneFactory.getPhone(i);
10103 if (phone != null) {
10104 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10105 isPhoneAvailable = true;
10106 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010107 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010108
10109 // return true if successfully informed the phone object about the thermal radio power
10110 // request.
10111 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010112 }
10113
10114 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010115 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010116 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10117 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10118 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10119 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10120 throw new IllegalArgumentException("modem does not support data throttling");
10121 }
10122
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010123 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10124 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010125 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010126 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10127 }
10128
Sarah Chinecc78c42022-03-31 21:16:48 -070010129 setDataEnabledForReason(
10130 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010131
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010132 if (isDataThrottlingSupported) {
10133 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010134 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010135 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10136 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10137 } else if (thermalMitigationResult
10138 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010139 log("Modem likely does not support data throttling on secondary carrier. Data " +
10140 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10141 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010142 }
10143 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010144 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010145
10146 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010147 }
10148
Jack Nudelman644b91a2021-03-12 14:09:48 -080010149 private static List<String> getThermalMitigationAllowlist(Context context) {
10150 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10151 for (String pckg : context.getResources()
10152 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10153 sThermalMitigationAllowlistedPackages.add(pckg);
10154 }
10155 }
10156
10157 return sThermalMitigationAllowlistedPackages;
10158 }
10159
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010160 private boolean isAnyPhoneInEmergencyState() {
10161 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10162 if (tm.isInEmergencyCall()) {
10163 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10164 return true;
10165 }
10166 for (Phone phone : PhoneFactory.getPhones()) {
10167 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10168 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10169 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10170 + phone.isInEcm());
10171 return true;
10172 }
10173 }
10174
10175 return false;
10176 }
10177
Jack Nudelman644b91a2021-03-12 14:09:48 -080010178 /**
10179 * Used by shell commands to add an authorized package name for thermal mitigation.
10180 * @param packageName name of package to be allowlisted
10181 * @param context
10182 */
10183 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10184 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10185 sThermalMitigationAllowlistedPackages.add(packageName);
10186 }
10187
10188 /**
10189 * Used by shell commands to remove an authorized package name for thermal mitigation.
10190 * @param packageName name of package to remove from allowlist
10191 * @param context
10192 */
10193 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10194 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10195 sThermalMitigationAllowlistedPackages.remove(packageName);
10196 }
10197
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010198 /**
10199 * Thermal mitigation request to control functionalities at modem.
10200 *
10201 * @param subId the id of the subscription.
10202 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010203 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010204 *
10205 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10206 */
10207 @Override
10208 @ThermalMitigationResult
10209 public int sendThermalMitigationRequest(
10210 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010211 ThermalMitigationRequest thermalMitigationRequest,
10212 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010213 enforceModifyPermission();
10214
Jack Nudelman644b91a2021-03-12 14:09:48 -080010215 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10216 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10217 .contains(callingPackage)) {
10218 throw new SecurityException("Calling package must be configured in the device config. "
10219 + "calling package: " + callingPackage);
10220 }
10221
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010222 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10223 final long identity = Binder.clearCallingIdentity();
10224
10225 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10226 try {
10227 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10228 switch (thermalMitigationAction) {
10229 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10230 thermalMitigationResult =
10231 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010232 thermalMitigationRequest.getDataThrottlingRequest(),
10233 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010234 break;
10235 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10236 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10237 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10238 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10239 }
10240
10241 // Ensure that radio is on. If not able to power on due to phone being
10242 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010243 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010244 thermalMitigationResult =
10245 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10246 break;
10247 }
10248
10249 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010250 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010251 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10252 break;
10253 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10254 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10255 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10256 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10257 }
10258
10259 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10260 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010261 Phone phone = getPhone(subId);
10262 if (phone == null) {
10263 thermalMitigationResult =
10264 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10265 break;
10266 }
10267
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010268 TelephonyConnectionService service =
10269 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010270 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010271 Log.e(LOG_TAG, "An emergency call is pending");
10272 thermalMitigationResult =
10273 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10274 break;
10275 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010276 thermalMitigationResult =
10277 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10278 break;
10279 }
10280 } else {
10281 thermalMitigationResult =
10282 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10283 break;
10284 }
10285
10286 // Turn radio off. If not able to power off due to phone being unavailable,
10287 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010288 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010289 thermalMitigationResult =
10290 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10291 break;
10292 }
10293 thermalMitigationResult =
10294 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10295 break;
10296 default:
10297 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10298 + "not exist. Requested action: " + thermalMitigationAction);
10299 }
10300 } catch (IllegalArgumentException e) {
10301 throw e;
10302 } catch (Exception e) {
10303 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10304 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10305 } finally {
10306 Binder.restoreCallingIdentity(identity);
10307 }
10308
10309 if (DBG) {
10310 log("thermalMitigationRequest returning with thermalMitigationResult: "
10311 + thermalMitigationResult);
10312 }
10313
10314 return thermalMitigationResult;
10315 }
Hui Wang641e81c2020-10-12 12:14:23 -070010316
10317 /**
10318 * Set the GbaService Package Name that Telephony will bind to.
10319 *
10320 * @param subId The sim that the GbaService is associated with.
10321 * @param packageName The name of the package to be replaced with.
10322 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10323 */
10324 @Override
10325 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10326 enforceModifyPermission();
10327
10328 final long identity = Binder.clearCallingIdentity();
10329 try {
10330 return getGbaManager(subId).overrideServicePackage(packageName);
10331 } finally {
10332 Binder.restoreCallingIdentity(identity);
10333 }
10334 }
10335
10336 /**
10337 * Return the package name of the currently bound GbaService.
10338 *
10339 * @param subId The sim that the GbaService is associated with.
10340 * @return the package name of the GbaService configuration, null if GBA is not supported.
10341 */
10342 @Override
10343 public String getBoundGbaService(int subId) {
10344 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10345
10346 final long identity = Binder.clearCallingIdentity();
10347 try {
10348 return getGbaManager(subId).getServicePackage();
10349 } finally {
10350 Binder.restoreCallingIdentity(identity);
10351 }
10352 }
10353
10354 /**
10355 * Set the release time for telephony to unbind GbaService.
10356 *
10357 * @param subId The sim that the GbaService is associated with.
10358 * @param interval The release time to unbind GbaService by millisecond.
10359 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10360 */
10361 @Override
10362 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10363 enforceModifyPermission();
10364
10365 final long identity = Binder.clearCallingIdentity();
10366 try {
10367 return getGbaManager(subId).overrideReleaseTime(interval);
10368 } finally {
10369 Binder.restoreCallingIdentity(identity);
10370 }
10371 }
10372
10373 /**
10374 * Return the release time for telephony to unbind GbaService.
10375 *
10376 * @param subId The sim that the GbaService is associated with.
10377 * @return The release time to unbind GbaService by millisecond.
10378 */
10379 @Override
10380 public int getGbaReleaseTime(int subId) {
10381 enforceReadPrivilegedPermission("getGbaReleaseTime");
10382
10383 final long identity = Binder.clearCallingIdentity();
10384 try {
10385 return getGbaManager(subId).getReleaseTime();
10386 } finally {
10387 Binder.restoreCallingIdentity(identity);
10388 }
10389 }
10390
10391 private GbaManager getGbaManager(int subId) {
10392 GbaManager instance = GbaManager.getInstance(subId);
10393 if (instance == null) {
10394 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10395 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10396 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10397 }
10398 return instance;
10399 }
Hui Wang761a6682020-10-31 05:12:53 +000010400
10401 /**
10402 * indicate whether the device and the carrier can support
10403 * RCS VoLTE single registration.
10404 */
10405 @Override
10406 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010407 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10408 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10409 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10410 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010411
10412 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10413 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10414 }
10415
10416 final long identity = Binder.clearCallingIdentity();
10417 try {
10418 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10419 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010420 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10421 if (isCapable != null) {
10422 return isCapable;
10423 }
Hui Wang761a6682020-10-31 05:12:53 +000010424 }
Hui Wang67af90e2021-06-04 16:57:15 -070010425 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10426 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010427 } finally {
10428 Binder.restoreCallingIdentity(identity);
10429 }
10430 }
10431
10432 /**
10433 * Register RCS provisioning callback.
10434 */
10435 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010436 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010437 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010438 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010439 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010440 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10441 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010442
10443 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10444 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10445 }
10446 if (!isImsAvailableOnDevice()) {
10447 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10448 "IMS not available on device.");
10449 }
10450
10451 final long identity = Binder.clearCallingIdentity();
10452 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010453 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010454 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010455 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10456 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010457 }
Hui Wang761a6682020-10-31 05:12:53 +000010458 } finally {
10459 Binder.restoreCallingIdentity(identity);
10460 }
10461 }
10462
10463 /**
10464 * Unregister RCS provisioning callback.
10465 */
10466 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010467 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010468 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010469 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010470 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010471 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10472 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010473
10474 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10475 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10476 }
10477 if (!isImsAvailableOnDevice()) {
10478 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10479 "IMS not available on device.");
10480 }
10481
10482 final long identity = Binder.clearCallingIdentity();
10483 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010484 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010485 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010486 } finally {
10487 Binder.restoreCallingIdentity(identity);
10488 }
10489 }
10490
10491 /**
10492 * trigger RCS reconfiguration.
10493 */
10494 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010495 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10496 "triggerRcsReconfiguration",
10497 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010498
10499 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10500 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10501 }
10502 if (!isImsAvailableOnDevice()) {
10503 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10504 "IMS not available on device.");
10505 }
10506
10507 final long identity = Binder.clearCallingIdentity();
10508 try {
10509 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10510 } finally {
10511 Binder.restoreCallingIdentity(identity);
10512 }
10513 }
10514
10515 /**
10516 * Provide the client configuration parameters of the RCS application.
10517 */
10518 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010519 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10520 "setRcsClientConfiguration",
10521 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010522
10523 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10524 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10525 }
10526 if (!isImsAvailableOnDevice()) {
10527 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10528 "IMS not available on device.");
10529 }
10530
10531 final long identity = Binder.clearCallingIdentity();
10532
10533 try {
10534 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10535 if (configBinder == null) {
10536 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010537 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10538 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010539 } else {
10540 configBinder.setRcsClientConfiguration(rcc);
10541 }
joonhunshin3e154242021-09-17 06:33:39 +000010542
10543 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10544 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010545 } catch (RemoteException e) {
10546 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010547 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10548 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010549 } finally {
10550 Binder.restoreCallingIdentity(identity);
10551 }
10552 }
10553
10554 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010555 * Enables or disables the test mode for RCS VoLTE single registration.
10556 */
10557 @Override
10558 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10559 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10560 "setRcsSingleRegistrationTestModeEnabled");
10561
10562 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10563 }
10564
10565 /**
10566 * Gets the test mode for RCS VoLTE single registration.
10567 */
10568 @Override
10569 public boolean getRcsSingleRegistrationTestModeEnabled() {
10570 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10571 "getRcsSingleRegistrationTestModeEnabled");
10572
10573 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10574 }
10575
10576 /**
Hui Wang761a6682020-10-31 05:12:53 +000010577 * Overrides the config of RCS VoLTE single registration enabled for the device.
10578 */
10579 @Override
10580 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10581 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10582 "setDeviceSingleRegistrationEnabledOverride");
10583 enforceModifyPermission();
10584
10585 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10586 : Boolean.parseBoolean(enabledStr);
10587 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010588 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010589 }
10590
10591 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010592 * Sends a device to device communication message. Only usable via shell.
10593 * @param message message to send.
10594 * @param value message value.
10595 */
10596 @Override
10597 public void sendDeviceToDeviceMessage(int message, int value) {
10598 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010599 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010600 enforceModifyPermission();
10601
10602 final long identity = Binder.clearCallingIdentity();
10603 try {
10604 TelephonyConnectionService service =
10605 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10606 if (service == null) {
10607 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10608 return;
10609 }
10610 service.sendTestDeviceToDeviceMessage(message, value);
10611 } finally {
10612 Binder.restoreCallingIdentity(identity);
10613 }
10614 }
10615
Tyler Gunnbabbda02021-02-10 11:05:02 -080010616 /**
10617 * Sets the specified device to device transport active.
10618 * @param transport The transport to set active.
10619 */
10620 @Override
10621 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10622 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10623 "setActiveDeviceToDeviceTransport");
10624 enforceModifyPermission();
10625
10626 final long identity = Binder.clearCallingIdentity();
10627 try {
10628 TelephonyConnectionService service =
10629 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10630 if (service == null) {
10631 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10632 return;
10633 }
10634 service.setActiveDeviceToDeviceTransport(transport);
10635 } finally {
10636 Binder.restoreCallingIdentity(identity);
10637 }
10638 }
Tyler Gunn92479152021-01-20 16:30:10 -080010639
Tyler Gunnd4339262021-05-03 14:46:49 -070010640 @Override
10641 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10642 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10643 "setDeviceToDeviceForceEnabled");
10644
10645 final long identity = Binder.clearCallingIdentity();
10646 try {
10647 Arrays.stream(PhoneFactory.getPhones()).forEach(
10648 p -> {
10649 Phone thePhone = p.getImsPhone();
10650 if (thePhone != null && thePhone instanceof ImsPhone) {
10651 ImsPhone imsPhone = (ImsPhone) thePhone;
10652 CallTracker tracker = imsPhone.getCallTracker();
10653 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10654 ImsPhoneCallTracker imsPhoneCallTracker =
10655 (ImsPhoneCallTracker) tracker;
10656 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10657 }
10658 }
10659 }
10660 );
10661 } finally {
10662 Binder.restoreCallingIdentity(identity);
10663 }
10664 }
10665
Tyler Gunn92479152021-01-20 16:30:10 -080010666 /**
Hui Wang761a6682020-10-31 05:12:53 +000010667 * Gets the config of RCS VoLTE single registration enabled for the device.
10668 */
10669 @Override
10670 public boolean getDeviceSingleRegistrationEnabled() {
10671 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10672 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10673 }
10674
10675 /**
10676 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10677 */
10678 @Override
10679 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10680 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10681 "setCarrierSingleRegistrationEnabledOverride");
10682 enforceModifyPermission();
10683
10684 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10685 : Boolean.parseBoolean(enabledStr);
10686 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10687 subId, enabled);
10688 }
10689
10690 /**
10691 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10692 */
10693 @Override
10694 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10695 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10696 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10697 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010698
10699 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010700 * Overrides the ims feature validation result
10701 */
10702 @Override
10703 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10704 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10705 "setImsFeatureValidationOverride");
10706
10707 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10708 : Boolean.parseBoolean(enabledStr);
10709 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10710 subId, enabled);
10711 }
10712
10713 /**
10714 * Gets the ims feature validation override value
10715 */
10716 @Override
10717 public boolean getImsFeatureValidationOverride(int subId) {
10718 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10719 "getImsFeatureValidationOverride");
10720 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10721 }
10722
10723 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010724 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10725 * their mobile plan.
10726 */
10727 @Override
10728 public String getMobileProvisioningUrl() {
10729 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10730 final long identity = Binder.clearCallingIdentity();
10731 try {
10732 return getDefaultPhone().getMobileProvisioningUrl();
10733 } finally {
10734 Binder.restoreCallingIdentity(identity);
10735 }
10736 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010737
James.cf Linbcdf8b32021-01-14 16:44:13 +080010738 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010739 * Get the EAB contact from the EAB database.
10740 */
10741 @Override
10742 public String getContactFromEab(String contact) {
10743 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10744 enforceModifyPermission();
10745 final long identity = Binder.clearCallingIdentity();
10746 try {
10747 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10748 } finally {
10749 Binder.restoreCallingIdentity(identity);
10750 }
10751 }
10752
10753 /**
Calvin Pana1434322021-07-01 19:27:01 +080010754 * Get the EAB capability from the EAB database.
10755 */
10756 @Override
10757 public String getCapabilityFromEab(String contact) {
10758 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10759 enforceModifyPermission();
10760 final long identity = Binder.clearCallingIdentity();
10761 try {
10762 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10763 } finally {
10764 Binder.restoreCallingIdentity(identity);
10765 }
10766 }
10767
10768 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010769 * Remove the EAB contacts from the EAB database.
10770 */
10771 @Override
10772 public int removeContactFromEab(int subId, String contacts) {
10773 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10774 enforceModifyPermission();
10775 final long identity = Binder.clearCallingIdentity();
10776 try {
10777 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10778 } finally {
10779 Binder.restoreCallingIdentity(identity);
10780 }
10781 }
10782
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010783 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010784 public boolean getDeviceUceEnabled() {
10785 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10786 final long identity = Binder.clearCallingIdentity();
10787 try {
10788 return mApp.getDeviceUceEnabled();
10789 } finally {
10790 Binder.restoreCallingIdentity(identity);
10791 }
10792 }
10793
10794 @Override
10795 public void setDeviceUceEnabled(boolean isEnabled) {
10796 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10797 final long identity = Binder.clearCallingIdentity();
10798 try {
10799 mApp.setDeviceUceEnabled(isEnabled);
10800 } finally {
10801 Binder.restoreCallingIdentity(identity);
10802 }
10803 }
10804
Brad Ebinger14d467f2021-02-12 06:18:28 +000010805 /**
10806 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10807 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10808 */
10809 // Used for SHELL command only right now.
10810 @Override
10811 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10812 List<String> featureTags) {
10813 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10814 "addUceRegistrationOverrideShell");
10815 final long identity = Binder.clearCallingIdentity();
10816 try {
10817 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10818 new ArraySet<>(featureTags));
10819 } catch (ImsException e) {
10820 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10821 } finally {
10822 Binder.restoreCallingIdentity(identity);
10823 }
10824 }
10825
10826 /**
10827 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10828 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10829 */
10830 // Used for SHELL command only right now.
10831 @Override
10832 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10833 List<String> featureTags) {
10834 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10835 "removeUceRegistrationOverrideShell");
10836 final long identity = Binder.clearCallingIdentity();
10837 try {
10838 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10839 new ArraySet<>(featureTags));
10840 } catch (ImsException e) {
10841 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10842 } finally {
10843 Binder.restoreCallingIdentity(identity);
10844 }
10845 }
10846
10847 /**
10848 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10849 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10850 */
10851 // Used for SHELL command only right now.
10852 @Override
10853 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10854 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10855 "clearUceRegistrationOverrideShell");
10856 final long identity = Binder.clearCallingIdentity();
10857 try {
10858 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10859 } catch (ImsException e) {
10860 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10861 } finally {
10862 Binder.restoreCallingIdentity(identity);
10863 }
10864 }
10865
10866 /**
10867 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10868 */
10869 // Used for SHELL command only right now.
10870 @Override
10871 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10872 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10873 "getLatestRcsContactUceCapabilityShell");
10874 final long identity = Binder.clearCallingIdentity();
10875 try {
10876 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10877 } catch (ImsException e) {
10878 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10879 } finally {
10880 Binder.restoreCallingIdentity(identity);
10881 }
10882 }
10883
10884 /**
10885 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10886 * device does not have an active PUBLISH.
10887 */
10888 // Used for SHELL command only right now.
10889 @Override
10890 public String getLastUcePidfXmlShell(int subId) {
10891 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10892 final long identity = Binder.clearCallingIdentity();
10893 try {
10894 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10895 } catch (ImsException e) {
10896 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10897 } finally {
10898 Binder.restoreCallingIdentity(identity);
10899 }
10900 }
10901
James.cf Line8713a42021-04-29 16:04:26 +080010902 /**
10903 * Remove UCE requests cannot be sent to the network status.
10904 */
10905 // Used for SHELL command only right now.
10906 @Override
10907 public boolean removeUceRequestDisallowedStatus(int subId) {
10908 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10909 final long identity = Binder.clearCallingIdentity();
10910 try {
10911 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10912 } catch (ImsException e) {
10913 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10914 } finally {
10915 Binder.restoreCallingIdentity(identity);
10916 }
10917 }
10918
James.cf Lin18bb9002021-05-25 01:37:38 +080010919 /**
10920 * Remove UCE requests cannot be sent to the network status.
10921 */
10922 // Used for SHELL command only.
10923 @Override
10924 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10925 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10926 final long identity = Binder.clearCallingIdentity();
10927 try {
10928 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10929 } catch (ImsException e) {
10930 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10931 } finally {
10932 Binder.restoreCallingIdentity(identity);
10933 }
10934 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010935
James.cf Lin4b784aa2021-01-31 03:25:15 +080010936 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010937 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10938 String callingPackage) {
10939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10940 mApp, subId, "setSignalStrengthUpdateRequest");
10941
10942 final int callingUid = Binder.getCallingUid();
10943 // Verify that tha callingPackage belongs to the calling UID
10944 mApp.getSystemService(AppOpsManager.class)
10945 .checkPackage(callingUid, callingPackage);
10946
Rambo Wang3607f502021-02-01 21:51:40 -080010947 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010948
10949 final long identity = Binder.clearCallingIdentity();
10950 try {
10951 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10952 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10953
10954 if (result instanceof IllegalStateException) {
10955 throw (IllegalStateException) result;
10956 }
10957 } finally {
10958 Binder.restoreCallingIdentity(identity);
10959 }
10960 }
10961
10962 @Override
10963 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10964 String callingPackage) {
10965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10966 mApp, subId, "clearSignalStrengthUpdateRequest");
10967
10968 final int callingUid = Binder.getCallingUid();
10969 // Verify that tha callingPackage belongs to the calling UID
10970 mApp.getSystemService(AppOpsManager.class)
10971 .checkPackage(callingUid, callingPackage);
10972
10973 final long identity = Binder.clearCallingIdentity();
10974 try {
10975 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10976 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10977
10978 if (result instanceof IllegalStateException) {
10979 throw (IllegalStateException) result;
10980 }
10981 } finally {
10982 Binder.restoreCallingIdentity(identity);
10983 }
10984 }
10985
Rambo Wang3607f502021-02-01 21:51:40 -080010986 private static void validateSignalStrengthUpdateRequest(Context context,
10987 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010988 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10989 // phone/system process do not have further restriction on request
10990 return;
10991 }
10992
10993 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010994 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010995 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010996 context.enforceCallingOrSelfPermission(
10997 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10998 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010999 }
11000
11001 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11002 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11003 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11004 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11005 || info.isEnabled()) {
11006 throw new IllegalArgumentException(
11007 "Only system can set hide fields in SignalThresholdInfo");
11008 }
11009
11010 // Thresholds length for each RAN need in range. This has been validated in
11011 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11012 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11013 final int[] thresholds = info.getThresholds();
11014 Objects.requireNonNull(thresholds);
11015 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11016 || thresholds.length
11017 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11018 throw new IllegalArgumentException(
11019 "thresholds length is out of range: " + thresholds.length);
11020 }
11021 }
11022 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011023
11024 /**
11025 * Gets the current phone capability.
11026 *
11027 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11028 * @return the PhoneCapability which describes the data connection capability of modem.
11029 * It's used to evaluate possible phone config change, for example from single
11030 * SIM device to multi-SIM device.
11031 */
11032 @Override
11033 public PhoneCapability getPhoneCapability() {
11034 enforceReadPrivilegedPermission("getPhoneCapability");
11035 final long identity = Binder.clearCallingIdentity();
11036 try {
11037 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11038 } finally {
11039 Binder.restoreCallingIdentity(identity);
11040 }
11041 }
Michele Berionne5e411512020-11-13 02:36:59 +000011042
11043 /**
11044 * Prepare TelephonyManager for an unattended reboot. The reboot is
11045 * required to be done shortly after the API is invoked.
11046 */
11047 @Override
11048 @TelephonyManager.PrepareUnattendedRebootResult
11049 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011050 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011051 enforceRebootPermission();
11052
11053 final long identity = Binder.clearCallingIdentity();
11054 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011055 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011056 } finally {
11057 Binder.restoreCallingIdentity(identity);
11058 }
11059 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011060
11061 /**
11062 * Request to get the current slicing configuration including URSP rules and
11063 * NSSAIs (configured, allowed and rejected).
11064 *
11065 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11066 */
11067 @Override
11068 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011069 TelephonyPermissions
11070 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11071 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011072
11073 final long identity = Binder.clearCallingIdentity();
11074 try {
11075 Phone phone = getDefaultPhone();
11076 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11077 } finally {
11078 Binder.restoreCallingIdentity(identity);
11079 }
11080 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011081
11082 /**
11083 * Register an IMS connection state callback
11084 */
11085 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011086 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11087 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011088 if (feature == ImsFeature.FEATURE_MMTEL) {
11089 // ImsMmTelManager
11090 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11091 TelephonyPermissions
11092 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11093 mApp, subId, "registerImsStateCallback");
11094 } else if (feature == ImsFeature.FEATURE_RCS) {
11095 // ImsRcsManager or SipDelegateManager
11096 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11097 Binder.getCallingUid(), "registerImsStateCallback",
11098 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11099 Manifest.permission.READ_PRECISE_PHONE_STATE,
11100 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11101 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11102 }
11103
11104 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11105 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11106 "IMS not available on device.");
11107 }
11108
11109 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11110 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11111 }
11112
11113 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11114 if (controller == null) {
11115 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11116 "IMS not available on device.");
11117 }
11118
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011119 if (callingPackage == null) {
11120 callingPackage = getCurrentPackageName();
11121 }
11122
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011123 final long token = Binder.clearCallingIdentity();
11124 try {
11125 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011126 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011127 } catch (ImsException e) {
11128 throw new ServiceSpecificException(e.getCode());
11129 } finally {
11130 Binder.restoreCallingIdentity(token);
11131 }
11132 }
11133
11134 /**
11135 * Unregister an IMS connection state callback
11136 */
11137 @Override
11138 public void unregisterImsStateCallback(IImsStateCallback cb) {
11139 final long token = Binder.clearCallingIdentity();
11140 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11141 if (controller == null) {
11142 return;
11143 }
11144 try {
11145 controller.unregisterImsStateCallback(cb);
11146 } finally {
11147 Binder.restoreCallingIdentity(token);
11148 }
11149 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011150
11151 /**
11152 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11153 *
11154 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11155 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11156 * SecurityException.
11157 * If there is current registered network this value will be same as the registered cell
11158 * identity. If the device goes out of service the previous cell identity is cached and
11159 * will be returned. If the cache age of the Cell identity is more than 24 hours
11160 * it will be cleared and null will be returned.
11161 *
11162 */
11163 @Override
11164 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11165 String callingFeatureId) {
11166 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11167 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11168 LocationAccessPolicy.checkLocationPermission(mApp,
11169 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11170 .setCallingPackage(callingPackage)
11171 .setCallingFeatureId(callingFeatureId)
11172 .setCallingPid(Binder.getCallingPid())
11173 .setCallingUid(Binder.getCallingUid())
11174 .setMethod("getLastKnownCellIdentity")
11175 .setLogAsInfo(true)
11176 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11177 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11178 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11179 .build());
11180
11181 boolean hasFinePermission =
11182 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11183 if (!hasFinePermission
11184 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11185 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011186 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011187 }
11188
11189 final long identity = Binder.clearCallingIdentity();
11190 try {
11191 Phone phone = getPhone(subId);
11192 if (phone == null) return null;
11193 ServiceStateTracker sst = phone.getServiceStateTracker();
11194 if (sst == null) return null;
11195 return sst.getLastKnownCellIdentity();
11196 } finally {
11197 Binder.restoreCallingIdentity(identity);
11198 }
11199 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011200
jimsun3b9ccac2021-10-26 15:01:23 +080011201 /**
11202 * Sets the modem service class Name that Telephony will bind to.
11203 *
11204 * @param serviceName The class name of the modem service.
11205 * @return true if the operation is succeed, otherwise false.
11206 */
11207 public boolean setModemService(String serviceName) {
11208 Log.d(LOG_TAG, "setModemService - " + serviceName);
11209 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11211 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11212 "setModemService");
11213 return mPhoneConfigurationManager.setModemService(serviceName);
11214 }
11215
11216 /**
11217 * Return the class name of the currently bounded modem service.
11218 *
11219 * @return the class name of the modem service.
11220 */
11221 public String getModemService() {
11222 String result;
11223 Log.d(LOG_TAG, "getModemService");
11224 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11225 TelephonyPermissions
11226 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11227 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11228 "getModemService");
11229 result = mPhoneConfigurationManager.getModemService();
11230 Log.d(LOG_TAG, "result = " + result);
11231 return result;
11232 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011233
11234 @Override
11235 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11236 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11237 mApp.enforceCallingOrSelfPermission(
11238 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11239 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11240
11241 final long identity = Binder.clearCallingIdentity();
11242 try {
11243 Phone phone = getPhone(subId);
11244 if (phone == null) return;
11245 phone.setVoiceServiceStateOverride(hasService);
11246 } finally {
11247 Binder.restoreCallingIdentity(identity);
11248 }
11249 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011250
11251 /**
11252 * set removable eSIM as default eUICC.
11253 *
11254 * @hide
11255 */
11256 @Override
11257 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11258 enforceModifyPermission();
11259 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11260
11261 final long identity = Binder.clearCallingIdentity();
11262 try {
11263 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11264 } finally {
11265 Binder.restoreCallingIdentity(identity);
11266 }
11267 }
11268
11269 /**
11270 * Returns whether the removable eSIM is default eUICC or not.
11271 *
11272 * @hide
11273 */
11274 @Override
11275 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11276 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11277 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11278
11279 final long identity = Binder.clearCallingIdentity();
11280 try {
11281 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11282 } finally {
11283 Binder.restoreCallingIdentity(identity);
11284 }
11285 }
11286
11287
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011288}