blob: d57343c711d322f09f689c9e5286cd6ef8d8ba52 [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;
25
Brad Ebinger34c09a52021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000032import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080033import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070034import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070035import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.content.Context;
37import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070038import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070039import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080040import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070041import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.net.Uri;
43import android.os.AsyncResult;
44import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080045import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Bundle;
47import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Looper;
50import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080052import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070053import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070054import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080055import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080056import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070057import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070058import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080059import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070061import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070063import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070064import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080065import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070066import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090067import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080068import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080069import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070070import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070071import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080072import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080073import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070074import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080075import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070076import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080077import android.telephony.CellIdentityCdma;
78import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070080import android.telephony.CellInfoGsm;
81import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080083import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070084import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070085import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070086import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080087import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070088import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070090import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080091import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080092import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070093import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080096import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080097import android.telephony.SignalStrengthUpdateRequest;
98import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080099import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800101import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800105import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800106import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000107import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700108import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700109import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800111import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800112import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700113import android.telephony.gba.GbaAuthRequest;
114import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700115import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800116import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000117import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000118import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700119import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700120import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700122import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800123import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700124import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000125import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700126import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800128import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800129import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800130import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700133import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800135import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800136
Andrew Lee312e8172014-10-23 17:01:36 -0700137import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800138import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800139import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800140import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800141import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700143import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700144import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800145import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700146import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700150import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800151import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800152import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800153import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700154import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700155import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800156import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800158import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700159import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700160import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700161import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700163import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800164import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700165import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700166import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700167import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700168import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800169import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800170import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700172import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800174import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800175import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800176import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700177import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800178import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700179import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800180import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700181import com.android.internal.telephony.imsphone.ImsPhone;
182import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800183import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700184import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800186import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187import com.android.internal.telephony.uicc.IccUtils;
Grace Jia59437e82021-09-21 15:47:32 -0700188import com.android.internal.telephony.uicc.PinStorage;
Nathan Haroldb3014052017-01-25 15:57:32 -0800189import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700190import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800191import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700192import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000193import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800194import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000195import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800196import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700197import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700198import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800199import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800200import com.android.phone.callcomposer.CallComposerPictureManager;
201import com.android.phone.callcomposer.CallComposerPictureTransfer;
202import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700203import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700204import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800205import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700206import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700207import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800208import com.android.services.telephony.TelecomAccountRegistry;
209import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800210import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800211
Hall Liu82694d52020-12-11 18:22:04 -0800212import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700213import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800214import java.io.IOException;
215import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700216import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800218import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800219import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800220import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800221import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100222import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800223import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700224import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800226import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800227import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800228import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800229import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700230
231/**
232 * Implementation of the ITelephony interface.
233 */
Santos Cordon117fee72014-05-16 17:56:12 -0700234public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235 private static final String LOG_TAG = "PhoneInterfaceManager";
236 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
237 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800238 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239
240 // Message codes used with mMainThreadHandler
241 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700242 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
243 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700244 private static final int CMD_OPEN_CHANNEL = 9;
245 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
246 private static final int CMD_CLOSE_CHANNEL = 11;
247 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800248 private static final int CMD_NV_READ_ITEM = 13;
249 private static final int EVENT_NV_READ_ITEM_DONE = 14;
250 private static final int CMD_NV_WRITE_ITEM = 15;
251 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
252 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
253 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700254 private static final int CMD_RESET_MODEM_CONFIG = 19;
255 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800256 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
257 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800258 private static final int CMD_SEND_ENVELOPE = 25;
259 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000260 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
261 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700262 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
263 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
264 private static final int CMD_EXCHANGE_SIM_IO = 31;
265 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800266 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
267 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700268 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
269 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700270 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
271 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700272 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
273 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
274 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
275 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700276 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
277 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
278 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
279 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700280 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800281 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
282 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000283 private static final int CMD_SWITCH_SLOTS = 50;
284 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700285 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
286 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
287 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
288 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
289 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
290 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
291 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
292 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700293 private static final int CMD_GET_ALL_CELL_INFO = 60;
294 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
295 private static final int CMD_GET_CELL_LOCATION = 62;
296 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700297 private static final int CMD_MODEM_REBOOT = 64;
298 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700299 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
300 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800301 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
302 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700303 private static final int CMD_GET_MODEM_STATUS = 70;
304 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700305 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
306 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700307 private static final int CMD_ERASE_MODEM_CONFIG = 74;
308 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800309 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
310 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
311 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
312 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800313 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
314 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800315 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800316 private static final int CMD_GET_CALL_FORWARDING = 83;
317 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
318 private static final int CMD_SET_CALL_FORWARDING = 85;
319 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
320 private static final int CMD_GET_CALL_WAITING = 87;
321 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
322 private static final int CMD_SET_CALL_WAITING = 89;
323 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700324 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
325 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
326 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
327 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700328 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
329 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800330 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
331 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800332 private static final int CMD_SET_DATA_THROTTLING = 99;
333 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800334 private static final int CMD_SET_SIM_POWER = 101;
335 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800336 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
337 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
338 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
339 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800340 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
341 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000342 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800343 private static final int CMD_GET_SLICING_CONFIG = 110;
344 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800345 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700346 private static final int CMD_ENABLE_VONR = 113;
347 private static final int EVENT_ENABLE_VONR_DONE = 114;
348 private static final int CMD_IS_VONR_ENABLED = 115;
349 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800351 // Parameters of select command.
352 private static final int SELECT_COMMAND = 0xA4;
353 private static final int SELECT_P1 = 0x04;
354 private static final int SELECT_P2 = 0;
355 private static final int SELECT_P3 = 0x10;
356
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357 /** The singleton instance. */
358 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800359 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
Wink Saville3ab207e2014-11-20 13:07:20 -0800361 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800362 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800363 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700364 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800365 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700366 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800367 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800368 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800369 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700370 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800371 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
Peter Wangdafb9ac2020-01-15 14:13:38 -0800373 /** User Activity */
374 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800375 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
376
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700377 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
378
Derek Tan97ebb422014-09-05 16:55:38 -0700379 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
380 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800381 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800382 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700383
Michelecea4cf22018-12-21 15:00:11 -0800384 // String to store multi SIM allowed
385 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
386
Derek Tan740e1672017-06-27 14:56:27 -0700387 // The AID of ISD-R.
388 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
389
yinxub1bed742017-04-17 11:45:04 -0700390 private NetworkScanRequestTracker mNetworkScanRequestTracker;
391
David Kelly5e06a7f2018-03-12 14:10:59 +0000392 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
393 private static final int MANUFACTURER_CODE_LENGTH = 8;
394
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800395 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800396 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800397
Derek Tan89e89d42014-07-08 17:00:10 -0700398 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700399 * Experiment flag to enable erase modem config on reset network, default value is false
400 */
401 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
402 "reset_network_erase_modem_config_enabled";
403
Rambo Wang0f050d82021-02-12 11:43:36 -0800404 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
405
Naina Nallurid63128d2019-09-17 14:10:30 -0700406 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700407 * A request object to use for transmitting data to an ICC.
408 */
409 private static final class IccAPDUArgument {
410 public int channel, cla, command, p1, p2, p3;
411 public String data;
412
413 public IccAPDUArgument(int channel, int cla, int command,
414 int p1, int p2, int p3, String data) {
415 this.channel = channel;
416 this.cla = cla;
417 this.command = command;
418 this.p1 = p1;
419 this.p2 = p2;
420 this.p3 = p3;
421 this.data = data;
422 }
423 }
424
425 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700426 * A request object to use for transmitting data to an ICC.
427 */
428 private static final class ManualNetworkSelectionArgument {
429 public OperatorInfo operatorInfo;
430 public boolean persistSelection;
431
432 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
433 this.operatorInfo = operatorInfo;
434 this.persistSelection = persistSelection;
435 }
436 }
437
438 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
440 * request after sending. The main thread will notify the request when it is complete.
441 */
442 private static final class MainThreadRequest {
443 /** The argument to use for the request */
444 public Object argument;
445 /** The result of the request that is run on the main thread */
446 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800447 // The subscriber id that this request applies to. Defaults to
448 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
449 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450
Nathan Harold92bed182018-10-12 18:16:49 -0700451 // In cases where subId is unavailable, the caller needs to specify the phone.
452 public Phone phone;
453
vagdeviaf9a5b92018-08-15 16:01:53 -0700454 public WorkSource workSource;
455
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 public MainThreadRequest(Object argument) {
457 this.argument = argument;
458 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800459
Nathan Harold92bed182018-10-12 18:16:49 -0700460 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
461 this.argument = argument;
462 if (phone != null) {
463 this.phone = phone;
464 }
465 this.workSource = workSource;
466 }
467
vagdeviaf9a5b92018-08-15 16:01:53 -0700468 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800469 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800470 if (subId != null) {
471 this.subId = subId;
472 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700473 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800474 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 }
476
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800477 private static final class IncomingThirdPartyCallArgs {
478 public final ComponentName component;
479 public final String callId;
480 public final String callerDisplayName;
481
482 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
483 String callerDisplayName) {
484 this.component = component;
485 this.callId = callId;
486 this.callerDisplayName = callerDisplayName;
487 }
488 }
489
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490 /**
491 * A handler that processes messages on the main thread in the phone process. Since many
492 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
493 * inbound binder threads to the main thread in the phone process. The Binder thread
494 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
495 * on, which will be notified when the operation completes and will contain the result of the
496 * request.
497 *
498 * <p>If a MainThreadRequest object is provided in the msg.obj field,
499 * note that request.result must be set to something non-null for the calling thread to
500 * unblock.
501 */
502 private final class MainThreadHandler extends Handler {
503 @Override
504 public void handleMessage(Message msg) {
505 MainThreadRequest request;
506 Message onCompleted;
507 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000508 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800510 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511
512 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700513 case CMD_HANDLE_USSD_REQUEST: {
514 request = (MainThreadRequest) msg.obj;
515 final Phone phone = getPhoneFromRequest(request);
516 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
517 String ussdRequest = ussdObject.first;
518 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700519
Pengquan Menga1bb6272018-09-06 09:59:22 -0700520 if (!isUssdApiAllowed(request.subId)) {
521 // Carrier does not support use of this API, return failure.
522 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
523 UssdResponse response = new UssdResponse(ussdRequest, null);
524 Bundle returnData = new Bundle();
525 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
526 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700527
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 request.result = true;
529 notifyRequester(request);
530 return;
531 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700532
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 try {
534 request.result = phone != null
535 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
536 } catch (CallStateException cse) {
537 request.result = false;
538 }
539 // Wake up the requesting thread
540 notifyRequester(request);
541 break;
pkanwar32d516d2016-10-14 19:37:38 -0700542 }
543
Yorke Lee716f67e2015-06-17 15:39:16 -0700544 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700546 final Phone phone = getPhoneFromRequest(request);
547 request.result = phone != null ?
548 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
549 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700554
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000558 uiccPort = getUiccPortFromRequest(request);
559 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 loge("iccTransmitApduLogicalChannel: No UICC");
561 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700562 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
565 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000566 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 iccArgument.channel, iccArgument.cla, iccArgument.command,
568 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 break;
572
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 ar = (AsyncResult) msg.obj;
575 request = (MainThreadRequest) ar.userObj;
576 if (ar.exception == null && ar.result != null) {
577 request.result = ar.result;
578 } else {
579 request.result = new IccIoResult(0x6F, 0, (byte[])null);
580 if (ar.result == null) {
581 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800582 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800584 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 } else {
586 loge("iccTransmitApduLogicalChannel: Unknown exception");
587 }
588 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 break;
591
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
593 request = (MainThreadRequest) msg.obj;
594 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000595 uiccPort = getUiccPortFromRequest(request);
596 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 loge("iccTransmitApduBasicChannel: No UICC");
598 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 } else {
601 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
602 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000603 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
605 iccArgument.p3, iccArgument.data, onCompleted);
606 }
607 break;
608
609 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
610 ar = (AsyncResult) msg.obj;
611 request = (MainThreadRequest) ar.userObj;
612 if (ar.exception == null && ar.result != null) {
613 request.result = ar.result;
614 } else {
615 request.result = new IccIoResult(0x6F, 0, (byte[])null);
616 if (ar.result == null) {
617 loge("iccTransmitApduBasicChannel: Empty response");
618 } else if (ar.exception instanceof CommandException) {
619 loge("iccTransmitApduBasicChannel: CommandException: " +
620 ar.exception);
621 } else {
622 loge("iccTransmitApduBasicChannel: Unknown exception");
623 }
624 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700625 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 break;
627
628 case CMD_EXCHANGE_SIM_IO:
629 request = (MainThreadRequest) msg.obj;
630 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000631 uiccPort = getUiccPortFromRequest(request);
632 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 loge("iccExchangeSimIO: No UICC");
634 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700636 } else {
637 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
638 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000639 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
641 iccArgument.data, onCompleted);
642 }
643 break;
644
645 case EVENT_EXCHANGE_SIM_IO_DONE:
646 ar = (AsyncResult) msg.obj;
647 request = (MainThreadRequest) ar.userObj;
648 if (ar.exception == null && ar.result != null) {
649 request.result = ar.result;
650 } else {
651 request.result = new IccIoResult(0x6f, 0, (byte[])null);
652 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700653 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 break;
655
Derek Tan4d5e5c12014-02-04 11:54:58 -0800656 case CMD_SEND_ENVELOPE:
657 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000658 uiccPort = getUiccPortFromRequest(request);
659 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700660 loge("sendEnvelopeWithStatus: No UICC");
661 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700662 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700663 } else {
664 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000665 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700666 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800667 break;
668
669 case EVENT_SEND_ENVELOPE_DONE:
670 ar = (AsyncResult) msg.obj;
671 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700672 if (ar.exception == null && ar.result != null) {
673 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800674 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700675 request.result = new IccIoResult(0x6F, 0, (byte[])null);
676 if (ar.result == null) {
677 loge("sendEnvelopeWithStatus: Empty response");
678 } else if (ar.exception instanceof CommandException) {
679 loge("sendEnvelopeWithStatus: CommandException: " +
680 ar.exception);
681 } else {
682 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
683 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800684 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800686 break;
687
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 case CMD_OPEN_CHANNEL:
689 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000690 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800691 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000692 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700693 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800694 request.result = new IccOpenLogicalChannelResponse(-1,
695 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 } else {
698 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000699 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800700 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700701 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 break;
703
704 case EVENT_OPEN_CHANNEL_DONE:
705 ar = (AsyncResult) msg.obj;
706 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 int[] result = (int[]) ar.result;
710 int channelId = result[0];
711 byte[] selectResponse = null;
712 if (result.length > 1) {
713 selectResponse = new byte[result.length - 1];
714 for (int i = 1; i < result.length; ++i) {
715 selectResponse[i - 1] = (byte) result[i];
716 }
717 }
718 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700719 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 if (ar.result == null) {
722 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700723 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700724 if (ar.exception != null) {
725 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
726 }
727
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700728 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700729 if (ar.exception instanceof CommandException) {
730 CommandException.Error error =
731 ((CommandException) (ar.exception)).getCommandError();
732 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700733 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700734 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700735 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700736 }
737 }
738 openChannelResp = new IccOpenLogicalChannelResponse(
739 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700741 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 break;
744
745 case CMD_CLOSE_CHANNEL:
746 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000747 uiccPort = getUiccPortFromRequest(request);
748 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700749 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900750 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700751 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700752 } else {
753 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000754 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700755 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 break;
757
758 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800759 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
760 break;
761
762 case CMD_NV_READ_ITEM:
763 request = (MainThreadRequest) msg.obj;
764 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800765 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
766 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800767 break;
768
769 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 ar = (AsyncResult) msg.obj;
771 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800772 if (ar.exception == null && ar.result != null) {
773 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700774 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800775 request.result = "";
776 if (ar.result == null) {
777 loge("nvReadItem: Empty response");
778 } else if (ar.exception instanceof CommandException) {
779 loge("nvReadItem: CommandException: " +
780 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800782 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700783 }
784 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700785 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700786 break;
787
Jake Hambye994d462014-02-03 13:10:13 -0800788 case CMD_NV_WRITE_ITEM:
789 request = (MainThreadRequest) msg.obj;
790 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
791 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800792 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700793 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800794 break;
795
796 case EVENT_NV_WRITE_ITEM_DONE:
797 handleNullReturnEvent(msg, "nvWriteItem");
798 break;
799
800 case CMD_NV_WRITE_CDMA_PRL:
801 request = (MainThreadRequest) msg.obj;
802 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800803 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800804 break;
805
806 case EVENT_NV_WRITE_CDMA_PRL_DONE:
807 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
808 break;
809
chen xu6dac5ab2018-10-26 17:39:23 -0700810 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800811 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700812 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800813 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800814 break;
815
chen xu6dac5ab2018-10-26 17:39:23 -0700816 case EVENT_RESET_MODEM_CONFIG_DONE:
817 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800818 break;
819
Sooraj Sasindran37444802020-08-11 10:40:43 -0700820 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
821 request = (MainThreadRequest) msg.obj;
822 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
823 request);
824 Phone phone = getPhoneFromRequest(request);
825 if (phone != null) {
826 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
827 } else {
828 loge("isNRDualConnectivityEnabled: No phone object");
829 request.result = false;
830 notifyRequester(request);
831 }
832 break;
833 }
834
835 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
836 ar = (AsyncResult) msg.obj;
837 request = (MainThreadRequest) ar.userObj;
838 if (ar.exception == null && ar.result != null) {
839 request.result = ar.result;
840 } else {
841 // request.result must be set to something non-null
842 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700843 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700844 request.result = ar.result;
845 } else {
846 request.result = false;
847 }
848 if (ar.result == null) {
849 loge("isNRDualConnectivityEnabled: Empty response");
850 } else if (ar.exception instanceof CommandException) {
851 loge("isNRDualConnectivityEnabled: CommandException: "
852 + ar.exception);
853 } else {
854 loge("isNRDualConnectivityEnabled: Unknown exception");
855 }
856 }
857 notifyRequester(request);
858 break;
859
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700860 case CMD_IS_VONR_ENABLED: {
861 request = (MainThreadRequest) msg.obj;
862 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
863 request);
864 Phone phone = getPhoneFromRequest(request);
865 if (phone != null) {
866 phone.isVoNrEnabled(onCompleted, request.workSource);
867 } else {
868 loge("isVoNrEnabled: No phone object");
869 request.result = false;
870 notifyRequester(request);
871 }
872 break;
873 }
874
875 case EVENT_IS_VONR_ENABLED_DONE:
876 ar = (AsyncResult) msg.obj;
877 request = (MainThreadRequest) ar.userObj;
878 if (ar.exception == null && ar.result != null) {
879 request.result = ar.result;
880 } else {
881 // request.result must be set to something non-null
882 // for the calling thread to unblock
883 if (ar.result != null) {
884 request.result = ar.result;
885 } else {
886 request.result = false;
887 }
888 if (ar.result == null) {
889 loge("isVoNrEnabled: Empty response");
890 } else if (ar.exception instanceof CommandException) {
891 loge("isVoNrEnabled: CommandException: "
892 + ar.exception);
893 } else {
894 loge("isVoNrEnabled: Unknown exception");
895 }
896 }
897 notifyRequester(request);
898 break;
899
Sooraj Sasindran37444802020-08-11 10:40:43 -0700900 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
901 request = (MainThreadRequest) msg.obj;
902 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
903 Phone phone = getPhoneFromRequest(request);
904 if (phone != null) {
905 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
906 request.workSource);
907 } else {
908 loge("enableNrDualConnectivity: No phone object");
909 request.result =
910 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
911 notifyRequester(request);
912 }
913 break;
914 }
915
916 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 if (ar.exception == null) {
920 request.result =
921 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
922 } else {
923 request.result =
924 TelephonyManager
925 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
926 if (ar.exception instanceof CommandException) {
927 CommandException.Error error =
928 ((CommandException) (ar.exception)).getCommandError();
929 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
930 request.result =
931 TelephonyManager
932 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000933 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
934 request.result =
935 TelephonyManager
936 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700937 }
938 loge("enableNrDualConnectivity" + ": CommandException: "
939 + ar.exception);
940 } else {
941 loge("enableNrDualConnectivity" + ": Unknown exception");
942 }
943 }
944 notifyRequester(request);
945 break;
946 }
947
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700948 case CMD_ENABLE_VONR: {
949 request = (MainThreadRequest) msg.obj;
950 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
951 Phone phone = getPhoneFromRequest(request);
952 if (phone != null) {
953 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
954 request.workSource);
955 } else {
956 loge("setVoNrEnabled: No phone object");
957 request.result =
958 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
959 notifyRequester(request);
960 }
961 break;
962 }
963
964 case EVENT_ENABLE_VONR_DONE: {
965 ar = (AsyncResult) msg.obj;
966 request = (MainThreadRequest) ar.userObj;
967 if (ar.exception == null) {
968 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
969 } else {
970 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
971 if (ar.exception instanceof CommandException) {
972 CommandException.Error error =
973 ((CommandException) (ar.exception)).getCommandError();
974 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
975 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
976 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
977 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
978 } else {
979 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
980 }
981 loge("setVoNrEnabled" + ": CommandException: "
982 + ar.exception);
983 } else {
984 loge("setVoNrEnabled" + ": Unknown exception");
985 }
986 }
987 notifyRequester(request);
988 break;
989 }
990
SongFerngWang3ef3e072020-12-21 16:41:52 +0800991 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800992 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800993 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
994 request);
995 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800996 break;
997
SongFerngWang3ef3e072020-12-21 16:41:52 +0800998 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 if (ar.exception == null && ar.result != null) {
1002 request.result = ar.result; // Integer
1003 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301004 // request.result must be set to something non-null
1005 // for the calling thread to unblock
1006 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001007 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001008 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001009 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001010 loge("getAllowedNetworkTypesBitmask: CommandException: "
1011 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001012 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001013 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001014 }
1015 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001016 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001017 break;
1018
SongFerngWang3ef3e072020-12-21 16:41:52 +08001019 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001020 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001021 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1022 request);
1023 Pair<Integer, Long> reasonWithNetworkTypes =
1024 (Pair<Integer, Long>) request.argument;
1025 getPhoneFromRequest(request).setAllowedNetworkTypes(
1026 reasonWithNetworkTypes.first,
1027 reasonWithNetworkTypes.second,
1028 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001029 break;
1030
SongFerngWang3ef3e072020-12-21 16:41:52 +08001031 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1032 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001033 break;
1034
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001035 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1036 request = (MainThreadRequest)msg.obj;
1037 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001038 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001039 break;
1040
1041 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1042 ar = (AsyncResult)msg.obj;
1043 request = (MainThreadRequest)ar.userObj;
1044 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001045 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001046 break;
1047
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001048 case CMD_SET_VOICEMAIL_NUMBER:
1049 request = (MainThreadRequest) msg.obj;
1050 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1051 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001052 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1053 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001054 break;
1055
1056 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1057 handleNullReturnEvent(msg, "setVoicemailNumber");
1058 break;
1059
Stuart Scott54788802015-03-30 13:18:01 -07001060 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1061 request = (MainThreadRequest) msg.obj;
1062 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1063 request);
1064 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1065 break;
1066
1067 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1068 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1069 break;
1070
Shishir Agrawal302c8692015-06-19 13:49:39 -07001071 case CMD_PERFORM_NETWORK_SCAN:
1072 request = (MainThreadRequest) msg.obj;
1073 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1074 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1075 break;
1076
Hall Liu27d24262020-09-18 19:04:59 -07001077 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001078 request = (MainThreadRequest) msg.obj;
1079 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001080 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1081 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1082 request.argument;
1083 int callForwardingReason = args.first;
1084 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001085 break;
Hall Liu27d24262020-09-18 19:04:59 -07001086 }
1087 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001088 ar = (AsyncResult) msg.obj;
1089 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001090 TelephonyManager.CallForwardingInfoCallback callback =
1091 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1092 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001093 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001094 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001095 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1096 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1097 // Service Class is a bit mask per 3gpp 27.007. Search for
1098 // any service for voice call.
1099 if ((callForwardInfo.serviceClass
1100 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001101 callForwardingInfo = new CallForwardingInfo(true,
1102 callForwardInfo.reason,
1103 callForwardInfo.number,
1104 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001105 break;
1106 }
1107 }
1108 // Didn't find a call forward info for voice call.
1109 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001110 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1111 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001112 }
Hall Liu27d24262020-09-18 19:04:59 -07001113 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001114 } else {
1115 if (ar.result == null) {
1116 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1117 }
1118 if (ar.exception != null) {
1119 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1120 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001121 int errorCode = TelephonyManager
1122 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001123 if (ar.exception instanceof CommandException) {
1124 CommandException.Error error =
1125 ((CommandException) (ar.exception)).getCommandError();
1126 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001127 errorCode = TelephonyManager
1128 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001129 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001130 errorCode = TelephonyManager
1131 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001132 }
1133 }
Hall Liu27d24262020-09-18 19:04:59 -07001134 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001135 }
Shuo Qian4a594052020-01-23 11:59:30 -08001136 break;
Hall Liu27d24262020-09-18 19:04:59 -07001137 }
Shuo Qian4a594052020-01-23 11:59:30 -08001138
Hall Liu27d24262020-09-18 19:04:59 -07001139 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001140 request = (MainThreadRequest) msg.obj;
1141 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001142 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001143 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001144 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1145 request.argument).first;
1146 request.phone.setCallForwardingOption(
1147 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001148 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001149 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001150 callForwardingInfoToSet.getReason(),
1151 callForwardingInfoToSet.getNumber(),
1152 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1153 break;
Hall Liu27d24262020-09-18 19:04:59 -07001154 }
Shuo Qian4a594052020-01-23 11:59:30 -08001155
Hall Liu27d24262020-09-18 19:04:59 -07001156 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001157 ar = (AsyncResult) msg.obj;
1158 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001159 Consumer<Integer> callback =
1160 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1161 request.argument).second;
1162 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001163 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001164 int errorCode = TelephonyManager.CallForwardingInfoCallback
1165 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001166 if (ar.exception instanceof CommandException) {
1167 CommandException.Error error =
1168 ((CommandException) (ar.exception)).getCommandError();
1169 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001170 errorCode = TelephonyManager.CallForwardingInfoCallback
1171 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001172 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001173 errorCode = TelephonyManager.CallForwardingInfoCallback
1174 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001175 }
1176 }
1177 callback.accept(errorCode);
1178 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001179 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001180 }
Shuo Qian4a594052020-01-23 11:59:30 -08001181 break;
Hall Liu27d24262020-09-18 19:04:59 -07001182 }
Shuo Qian4a594052020-01-23 11:59:30 -08001183
Hall Liu27d24262020-09-18 19:04:59 -07001184 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001185 request = (MainThreadRequest) msg.obj;
1186 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1187 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1188 break;
Hall Liu27d24262020-09-18 19:04:59 -07001189 }
Shuo Qian4a594052020-01-23 11:59:30 -08001190
Hall Liu27d24262020-09-18 19:04:59 -07001191 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001192 ar = (AsyncResult) msg.obj;
1193 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001194 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001195 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1196 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001197 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001198 // Service Class is a bit mask per 3gpp 27.007.
1199 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001200 if (callForwardResults.length > 1
1201 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001202 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001203 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001204 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1205 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001206 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001207 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001208 }
1209 } else {
1210 if (ar.result == null) {
1211 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1212 }
1213 if (ar.exception != null) {
1214 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1215 }
1216 if (ar.exception instanceof CommandException) {
1217 CommandException.Error error =
1218 ((CommandException) (ar.exception)).getCommandError();
1219 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1220 callForwardingStatus =
1221 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1222 }
1223 }
1224 }
Hall Liu27d24262020-09-18 19:04:59 -07001225 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001226 break;
Hall Liu27d24262020-09-18 19:04:59 -07001227 }
Shuo Qian4a594052020-01-23 11:59:30 -08001228
Hall Liu27d24262020-09-18 19:04:59 -07001229 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001230 request = (MainThreadRequest) msg.obj;
1231 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001232 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1233 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001234 break;
Hall Liu27d24262020-09-18 19:04:59 -07001235 }
Shuo Qian4a594052020-01-23 11:59:30 -08001236
Hall Liu27d24262020-09-18 19:04:59 -07001237 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001238 ar = (AsyncResult) msg.obj;
1239 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001240 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1241 Consumer<Integer> callback =
1242 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1243 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001244 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001245 if (ar.exception instanceof CommandException) {
1246 CommandException.Error error =
1247 ((CommandException) (ar.exception)).getCommandError();
1248 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1249 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1250 } else {
1251 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1252 }
1253 } else {
1254 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1255 }
1256 } else {
1257 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1258 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001259 }
Shuo Qian4a594052020-01-23 11:59:30 -08001260 break;
Hall Liu27d24262020-09-18 19:04:59 -07001261 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001262 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1263 ar = (AsyncResult) msg.obj;
1264 request = (MainThreadRequest) ar.userObj;
1265 CellNetworkScanResult cellScanResult;
1266 if (ar.exception == null && ar.result != null) {
1267 cellScanResult = new CellNetworkScanResult(
1268 CellNetworkScanResult.STATUS_SUCCESS,
1269 (List<OperatorInfo>) ar.result);
1270 } else {
1271 if (ar.result == null) {
1272 loge("getCellNetworkScanResults: Empty response");
1273 }
1274 if (ar.exception != null) {
1275 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1276 }
1277 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1278 if (ar.exception instanceof CommandException) {
1279 CommandException.Error error =
1280 ((CommandException) (ar.exception)).getCommandError();
1281 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1282 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1283 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1284 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1285 }
1286 }
1287 cellScanResult = new CellNetworkScanResult(errorCode, null);
1288 }
1289 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001290 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001291 break;
1292
1293 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1294 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001295 ManualNetworkSelectionArgument selArg =
1296 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001297 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1298 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001299 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1300 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001301 break;
1302
1303 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001304 ar = (AsyncResult) msg.obj;
1305 request = (MainThreadRequest) ar.userObj;
1306 if (ar.exception == null) {
1307 request.result = true;
1308 } else {
1309 request.result = false;
1310 loge("setNetworkSelectionModeManual " + ar.exception);
1311 }
1312 notifyRequester(request);
1313 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001314 break;
1315
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001316 case CMD_GET_MODEM_ACTIVITY_INFO:
1317 request = (MainThreadRequest) msg.obj;
1318 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001319 if (defaultPhone != null) {
1320 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001321 } else {
1322 ResultReceiver result = (ResultReceiver) request.argument;
1323 Bundle bundle = new Bundle();
1324 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001325 new ModemActivityInfo(0, 0, 0,
1326 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001327 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001328 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001329 break;
1330
Hall Liud0f208c2020-10-14 16:54:44 -07001331 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001332 ar = (AsyncResult) msg.obj;
1333 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001334 ResultReceiver result = (ResultReceiver) request.argument;
1335
Hall Liud0f208c2020-10-14 16:54:44 -07001336 ModemActivityInfo ret = null;
1337 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001338 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001339 // Update the last modem activity info and the result of the request.
1340 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1341 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001342 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001343 int[] txTimeMs = info.getTransmitTimeMillis();
1344 int[] lastModemTxTimeMs = mLastModemActivityInfo
1345 .getTransmitTimeMillis();
1346 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1347 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1348 }
Hall Liu49656c02020-10-09 19:00:11 -07001349 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001350 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1351 + mLastModemActivityInfo.getSleepTimeMillis());
1352 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1353 + mLastModemActivityInfo.getIdleTimeMillis());
1354 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1355 mLastModemActivityInfo.setReceiveTimeMillis(
1356 info.getReceiveTimeMillis()
1357 + mLastModemActivityInfo.getReceiveTimeMillis());
1358 }
Hall Liu49656c02020-10-09 19:00:11 -07001359 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001360 mLastModemActivityInfo.getSleepTimeMillis(),
1361 mLastModemActivityInfo.getIdleTimeMillis(),
1362 mLastModemActivityInfo.getTransmitTimeMillis(),
1363 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001364 } else {
1365 if (ar.result == null) {
1366 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001367 error = TelephonyManager.ModemActivityInfoException
1368 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001369 } else if (ar.exception instanceof CommandException) {
1370 loge("queryModemActivityInfo: CommandException: " +
1371 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001372 error = TelephonyManager.ModemActivityInfoException
1373 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001374 } else {
1375 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001376 error = TelephonyManager.ModemActivityInfoException
1377 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001378 }
1379 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001380 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001381 if (ret != null) {
1382 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1383 } else {
1384 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1385 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001386 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001387 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001388 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001389 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001390
Meng Wang1a7c35a2016-05-05 20:56:15 -07001391 case CMD_SET_ALLOWED_CARRIERS:
1392 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001393 CarrierRestrictionRules argument =
1394 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001395 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001396 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001397 break;
1398
1399 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 if (ar.exception == null && ar.result != null) {
1403 request.result = ar.result;
1404 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001405 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1406 if (ar.exception instanceof CommandException) {
1407 loge("setAllowedCarriers: CommandException: " + ar.exception);
1408 CommandException.Error error =
1409 ((CommandException) (ar.exception)).getCommandError();
1410 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1411 request.result =
1412 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1413 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001414 } else {
1415 loge("setAllowedCarriers: Unknown exception");
1416 }
1417 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001418 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001419 break;
1420
1421 case CMD_GET_ALLOWED_CARRIERS:
1422 request = (MainThreadRequest) msg.obj;
1423 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001424 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001425 break;
1426
1427 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1428 ar = (AsyncResult) msg.obj;
1429 request = (MainThreadRequest) ar.userObj;
1430 if (ar.exception == null && ar.result != null) {
1431 request.result = ar.result;
1432 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001433 request.result = new IllegalStateException(
1434 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001435 if (ar.result == null) {
1436 loge("getAllowedCarriers: Empty response");
1437 } else if (ar.exception instanceof CommandException) {
1438 loge("getAllowedCarriers: CommandException: " +
1439 ar.exception);
1440 } else {
1441 loge("getAllowedCarriers: Unknown exception");
1442 }
1443 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001444 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001445 break;
1446
Nathan Haroldb3014052017-01-25 15:57:32 -08001447 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 if (ar.exception == null && ar.result != null) {
1451 request.result = ar.result;
1452 } else {
1453 request.result = new IllegalArgumentException(
1454 "Failed to retrieve Forbidden Plmns");
1455 if (ar.result == null) {
1456 loge("getForbiddenPlmns: Empty response");
1457 } else {
1458 loge("getForbiddenPlmns: Unknown exception");
1459 }
1460 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001461 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001462 break;
1463
1464 case CMD_GET_FORBIDDEN_PLMNS:
1465 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001466 uiccPort = getUiccPortFromRequest(request);
1467 if (uiccPort == null) {
1468 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001469 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001470 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001471 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001472 break;
1473 }
1474 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001475 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001476 if (uiccApp == null) {
1477 loge("getForbiddenPlmns() no app with specified type -- "
1478 + appType);
1479 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001480 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001481 break;
1482 } else {
1483 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1484 + " specified type -- " + appType);
1485 }
1486 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1487 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1488 onCompleted);
1489 break;
1490
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001491 case CMD_SWITCH_SLOTS:
1492 request = (MainThreadRequest) msg.obj;
1493 int[] physicalSlots = (int[]) request.argument;
1494 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1495 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1496 break;
1497
1498 case EVENT_SWITCH_SLOTS_DONE:
1499 ar = (AsyncResult) msg.obj;
1500 request = (MainThreadRequest) ar.userObj;
1501 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001502 notifyRequester(request);
1503 break;
1504 case CMD_GET_NETWORK_SELECTION_MODE:
1505 request = (MainThreadRequest) msg.obj;
1506 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1507 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1508 break;
1509
1510 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1511 ar = (AsyncResult) msg.obj;
1512 request = (MainThreadRequest) ar.userObj;
1513 if (ar.exception != null) {
1514 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1515 } else {
1516 int mode = ((int[]) ar.result)[0];
1517 if (mode == 0) {
1518 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1519 } else {
1520 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1521 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001523 notifyRequester(request);
1524 break;
1525 case CMD_GET_CDMA_ROAMING_MODE:
1526 request = (MainThreadRequest) msg.obj;
1527 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1528 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1529 break;
1530 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1531 ar = (AsyncResult) msg.obj;
1532 request = (MainThreadRequest) ar.userObj;
1533 if (ar.exception != null) {
1534 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1535 } else {
1536 request.result = ((int[]) ar.result)[0];
1537 }
1538 notifyRequester(request);
1539 break;
1540 case CMD_SET_CDMA_ROAMING_MODE:
1541 request = (MainThreadRequest) msg.obj;
1542 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1543 int mode = (int) request.argument;
1544 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1545 break;
1546 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1547 ar = (AsyncResult) msg.obj;
1548 request = (MainThreadRequest) ar.userObj;
1549 request.result = ar.exception == null;
1550 notifyRequester(request);
1551 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001552 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1553 request = (MainThreadRequest) msg.obj;
1554 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1555 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1556 break;
1557 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1558 ar = (AsyncResult) msg.obj;
1559 request = (MainThreadRequest) ar.userObj;
1560 if (ar.exception != null) {
1561 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1562 } else {
1563 request.result = ((int[]) ar.result)[0];
1564 }
1565 notifyRequester(request);
1566 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001567 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1568 request = (MainThreadRequest) msg.obj;
1569 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1570 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001571 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1572 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001573 break;
1574 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1575 ar = (AsyncResult) msg.obj;
1576 request = (MainThreadRequest) ar.userObj;
1577 request.result = ar.exception == null;
1578 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001579 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001580 case CMD_GET_ALL_CELL_INFO:
1581 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001582 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001583 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001584 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001585 case EVENT_GET_ALL_CELL_INFO_DONE:
1586 ar = (AsyncResult) msg.obj;
1587 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001588 // If a timeout occurs, the response will be null
1589 request.result = (ar.exception == null && ar.result != null)
1590 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001591 synchronized (request) {
1592 request.notifyAll();
1593 }
1594 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001595 case CMD_REQUEST_CELL_INFO_UPDATE:
1596 request = (MainThreadRequest) msg.obj;
1597 request.phone.requestCellInfoUpdate(request.workSource,
1598 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1599 break;
1600 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1601 ar = (AsyncResult) msg.obj;
1602 request = (MainThreadRequest) ar.userObj;
1603 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1604 try {
1605 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001606 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001607 cb.onError(
1608 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1609 ar.exception.getClass().getName(),
1610 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001611 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001612 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001613 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001614 } else {
1615 // use the result as returned
1616 cb.onCellInfo((List<CellInfo>) ar.result);
1617 }
1618 } catch (RemoteException re) {
1619 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1620 }
1621 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001622 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001623 request = (MainThreadRequest) msg.obj;
1624 WorkSource ws = (WorkSource) request.argument;
1625 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001626 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001627 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001628 }
1629 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001630 ar = (AsyncResult) msg.obj;
1631 request = (MainThreadRequest) ar.userObj;
1632 if (ar.exception == null) {
1633 request.result = ar.result;
1634 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001635 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001636 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001637 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001638 }
1639
1640 synchronized (request) {
1641 request.notifyAll();
1642 }
1643 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001644 }
chen xu6dac5ab2018-10-26 17:39:23 -07001645 case CMD_MODEM_REBOOT:
1646 request = (MainThreadRequest) msg.obj;
1647 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001648 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001649 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001650 case EVENT_CMD_MODEM_REBOOT_DONE:
1651 handleNullReturnEvent(msg, "rebootModem");
1652 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001653 case CMD_REQUEST_ENABLE_MODEM:
1654 request = (MainThreadRequest) msg.obj;
1655 boolean enable = (boolean) request.argument;
1656 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001657 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001658 PhoneConfigurationManager.getInstance()
1659 .enablePhone(request.phone, enable, onCompleted);
1660 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001661 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001662 ar = (AsyncResult) msg.obj;
1663 request = (MainThreadRequest) ar.userObj;
1664 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001665 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001666 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001667 if ((boolean) request.result) {
1668 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1669 updateModemStateMetrics();
1670 } else {
1671 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1672 + ar.exception);
1673 }
1674 notifyRequester(request);
1675 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001676 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001677 case CMD_GET_MODEM_STATUS:
1678 request = (MainThreadRequest) msg.obj;
1679 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1680 PhoneConfigurationManager.getInstance()
1681 .getPhoneStatusFromModem(request.phone, onCompleted);
1682 break;
1683 case EVENT_GET_MODEM_STATUS_DONE:
1684 ar = (AsyncResult) msg.obj;
1685 request = (MainThreadRequest) ar.userObj;
1686 int id = request.phone.getPhoneId();
1687 if (ar.exception == null && ar.result != null) {
1688 request.result = ar.result;
1689 //update the cache as modem status has changed
1690 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1691 (boolean) request.result);
1692 } else {
1693 // Return true if modem status cannot be retrieved. For most cases,
1694 // modem status is on. And for older version modems, GET_MODEM_STATUS
1695 // and disable modem are not supported. Modem is always on.
1696 // TODO: this should be fixed in R to support a third
1697 // status UNKNOWN b/131631629
1698 request.result = true;
1699 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1700 + ar.exception);
1701 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001702 notifyRequester(request);
1703 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001704 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1705 request = (MainThreadRequest) msg.obj;
1706 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1707 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1708 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1709 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1710 break;
1711 }
1712 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1716 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1717 args.second.accept(ar.exception == null);
1718 notifyRequester(request);
1719 break;
1720 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001721 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1722 request = (MainThreadRequest) msg.obj;
1723 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1724 Phone phone = getPhoneFromRequest(request);
1725 if (phone != null) {
1726 phone.getSystemSelectionChannels(onCompleted);
1727 } else {
1728 loge("getSystemSelectionChannels: No phone object");
1729 request.result = new ArrayList<RadioAccessSpecifier>();
1730 notifyRequester(request);
1731 }
1732 break;
1733 }
1734 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1735 ar = (AsyncResult) msg.obj;
1736 request = (MainThreadRequest) ar.userObj;
1737 if (ar.exception == null && ar.result != null) {
1738 request.result = ar.result;
1739 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001740 request.result = new IllegalStateException(
1741 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001742 if (ar.result == null) {
1743 loge("getSystemSelectionChannels: Empty response");
1744 } else {
1745 loge("getSystemSelectionChannels: Unknown exception");
1746 }
1747 }
1748 notifyRequester(request);
1749 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001750 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1751 ar = (AsyncResult) msg.obj;
1752 request = (MainThreadRequest) ar.userObj;
1753 if (ar.exception == null && ar.result != null) {
1754 request.result = ar.result;
1755 } else {
1756 request.result = -1;
1757 loge("Failed to set Forbidden Plmns");
1758 if (ar.result == null) {
1759 loge("setForbidenPlmns: Empty response");
1760 } else if (ar.exception != null) {
1761 loge("setForbiddenPlmns: Exception: " + ar.exception);
1762 request.result = -1;
1763 } else {
1764 loge("setForbiddenPlmns: Unknown exception");
1765 }
1766 }
1767 notifyRequester(request);
1768 break;
1769 case CMD_SET_FORBIDDEN_PLMNS:
1770 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001771 uiccPort = getUiccPortFromRequest(request);
1772 if (uiccPort == null) {
1773 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001774 request.result = -1;
1775 notifyRequester(request);
1776 break;
1777 }
1778 Pair<Integer, List<String>> setFplmnsArgs =
1779 (Pair<Integer, List<String>>) request.argument;
1780 appType = setFplmnsArgs.first;
1781 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001782 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001783 if (uiccApp == null) {
1784 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1785 request.result = -1;
1786 loge("Failed to get UICC App");
1787 notifyRequester(request);
1788 } else {
1789 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1790 ((SIMRecords) uiccApp.getIccRecords())
1791 .setForbiddenPlmns(onCompleted, fplmns);
1792 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001793 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001794 case CMD_ERASE_MODEM_CONFIG:
1795 request = (MainThreadRequest) msg.obj;
1796 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1797 defaultPhone.eraseModemConfig(onCompleted);
1798 break;
1799 case EVENT_ERASE_MODEM_CONFIG_DONE:
1800 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001801 break;
zoey chene02881a2019-12-30 16:11:23 +08001802
Kai Shif70f46f2021-03-03 13:59:46 -08001803 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1804 request = (MainThreadRequest) msg.obj;
1805 request.result = defaultPhone.eraseDataInSharedPreferences();
1806 notifyRequester(request);
1807 break;
1808
zoey chene02881a2019-12-30 16:11:23 +08001809 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1810 request = (MainThreadRequest) msg.obj;
1811 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1812 Pair<String, String> changed = (Pair<String, String>) request.argument;
1813 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1814 changed.first, changed.second, onCompleted);
1815 break;
1816 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1817 ar = (AsyncResult) msg.obj;
1818 request = (MainThreadRequest) ar.userObj;
1819 if (ar.exception == null) {
1820 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001821 // If the operation is successful, update the PIN storage
1822 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1823 int phoneId = getPhoneFromRequest(request).getPhoneId();
Grace Jia59437e82021-09-21 15:47:32 -07001824 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
1825 pinStorage.storePin(passwords.second, phoneId,
1826 pinStorage.getIccid(phoneId));
zoey chene02881a2019-12-30 16:11:23 +08001827 } else {
1828 request.result = msg.arg1;
1829 }
1830 notifyRequester(request);
1831 break;
1832
Michele Berionne5e411512020-11-13 02:36:59 +00001833 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001834 request = (MainThreadRequest) msg.obj;
1835 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1836 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1837 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1838 enabled.first, enabled.second, onCompleted);
1839 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001840 }
zoey chene02881a2019-12-30 16:11:23 +08001841 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1842 ar = (AsyncResult) msg.obj;
1843 request = (MainThreadRequest) ar.userObj;
1844 if (ar.exception == null) {
1845 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001846 // If the operation is successful, update the PIN storage
1847 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1848 int phoneId = getPhoneFromRequest(request).getPhoneId();
1849 if (enabled.first) {
Grace Jia59437e82021-09-21 15:47:32 -07001850 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
1851 pinStorage.storePin(enabled.second, phoneId,
1852 pinStorage.getIccid(phoneId));
Michele Berionne5e411512020-11-13 02:36:59 +00001853 } else {
1854 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1855 }
zoey chene02881a2019-12-30 16:11:23 +08001856 } else {
1857 request.result = msg.arg1;
1858 }
Michele Berionne5e411512020-11-13 02:36:59 +00001859
1860
zoey chene02881a2019-12-30 16:11:23 +08001861 notifyRequester(request);
1862 break;
1863
Peter Wangdafb9ac2020-01-15 14:13:38 -08001864 case MSG_NOTIFY_USER_ACTIVITY:
1865 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001866 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001867 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1868 getDefaultPhone().getContext().sendBroadcastAsUser(
1869 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1870 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001871
1872 case CMD_SET_DATA_THROTTLING: {
1873 request = (MainThreadRequest) msg.obj;
1874 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1875 DataThrottlingRequest dataThrottlingRequest =
1876 (DataThrottlingRequest) request.argument;
1877 Phone phone = getPhoneFromRequest(request);
1878 if (phone != null) {
1879 phone.setDataThrottling(onCompleted,
1880 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1881 dataThrottlingRequest.getCompletionDurationMillis());
1882 } else {
1883 loge("setDataThrottling: No phone object");
1884 request.result =
1885 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1886 notifyRequester(request);
1887 }
1888
1889 break;
1890 }
1891 case EVENT_SET_DATA_THROTTLING_DONE:
1892 ar = (AsyncResult) msg.obj;
1893 request = (MainThreadRequest) ar.userObj;
1894
1895 if (ar.exception == null) {
1896 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1897 } else if (ar.exception instanceof CommandException) {
1898 loge("setDataThrottling: CommandException: " + ar.exception);
1899 CommandException.Error error =
1900 ((CommandException) (ar.exception)).getCommandError();
1901
1902 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1903 request.result = TelephonyManager
1904 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1905 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1906 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001907 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1908 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001909 } else {
1910 request.result =
1911 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1912 }
1913 } else {
1914 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1915 }
1916 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1917 notifyRequester(request);
1918 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001919
1920 case CMD_SET_SIM_POWER: {
1921 request = (MainThreadRequest) msg.obj;
1922 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1923 request = (MainThreadRequest) msg.obj;
1924 int stateToSet =
1925 ((Pair<Integer, IIntegerConsumer>)
1926 request.argument).first;
1927 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1928 break;
1929 }
1930 case EVENT_SET_SIM_POWER_DONE: {
1931 ar = (AsyncResult) msg.obj;
1932 request = (MainThreadRequest) ar.userObj;
1933 IIntegerConsumer callback =
1934 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1935 if (ar.exception != null) {
1936 loge("setSimPower exception: " + ar.exception);
1937 int errorCode = TelephonyManager.CallForwardingInfoCallback
1938 .RESULT_ERROR_UNKNOWN;
1939 if (ar.exception instanceof CommandException) {
1940 CommandException.Error error =
1941 ((CommandException) (ar.exception)).getCommandError();
1942 if (error == CommandException.Error.SIM_ERR) {
1943 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1944 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1945 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1946 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1947 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1948 } else {
1949 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1950 }
1951 }
1952 try {
1953 callback.accept(errorCode);
1954 } catch (RemoteException e) {
1955 // Ignore if the remote process is no longer available to call back.
1956 Log.w(LOG_TAG, "setSimPower: callback not available.");
1957 }
1958 } else {
1959 try {
1960 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1961 } catch (RemoteException e) {
1962 // Ignore if the remote process is no longer available to call back.
1963 Log.w(LOG_TAG, "setSimPower: callback not available.");
1964 }
1965 }
1966 break;
1967 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001968 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1969 request = (MainThreadRequest) msg.obj;
1970
1971 final Phone phone = getPhoneFromRequest(request);
1972 if (phone == null || phone.getServiceStateTracker() == null) {
1973 request.result = new IllegalStateException("Phone or SST is null");
1974 notifyRequester(request);
1975 break;
1976 }
1977
1978 Pair<Integer, SignalStrengthUpdateRequest> pair =
1979 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1980 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1981 request);
1982 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1983 request.subId, pair.first /*callingUid*/,
1984 pair.second /*request*/, onCompleted);
1985 break;
1986 }
1987 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1988 ar = (AsyncResult) msg.obj;
1989 request = (MainThreadRequest) ar.userObj;
1990 // request.result will be the exception of ar if present, true otherwise.
1991 // Be cautious not to leave result null which will wait() forever
1992 request.result = ar.exception != null ? ar.exception : true;
1993 notifyRequester(request);
1994 break;
1995 }
1996 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1997 request = (MainThreadRequest) msg.obj;
1998
1999 Phone phone = getPhoneFromRequest(request);
2000 if (phone == null || phone.getServiceStateTracker() == null) {
2001 request.result = new IllegalStateException("Phone or SST is null");
2002 notifyRequester(request);
2003 break;
2004 }
2005
2006 Pair<Integer, SignalStrengthUpdateRequest> pair =
2007 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2008 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2009 request);
2010 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
2011 request.subId, pair.first /*callingUid*/,
2012 pair.second /*request*/, onCompleted);
2013 break;
2014 }
2015 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2016 ar = (AsyncResult) msg.obj;
2017 request = (MainThreadRequest) ar.userObj;
2018 request.result = ar.exception != null ? ar.exception : true;
2019 notifyRequester(request);
2020 break;
2021 }
Jordan Liu109698e2020-11-24 14:50:34 -08002022
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002023 case CMD_GET_SLICING_CONFIG: {
2024 request = (MainThreadRequest) msg.obj;
2025 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2026 request.phone.getSlicingConfig(onCompleted);
2027 break;
2028 }
2029 case EVENT_GET_SLICING_CONFIG_DONE: {
2030 ar = (AsyncResult) msg.obj;
2031 request = (MainThreadRequest) ar.userObj;
2032 ResultReceiver result = (ResultReceiver) request.argument;
2033
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002034 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002035 Bundle bundle = new Bundle();
2036 int resultCode = 0;
2037 if (ar.exception != null) {
2038 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2039 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002040 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002041 } else if (ar.result == null) {
2042 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002043 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002044 } else {
2045 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002046 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2047 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002048 }
2049
2050 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002051 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002052 }
2053 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2054 result.send(resultCode, bundle);
2055 notifyRequester(request);
2056 break;
2057 }
2058
Michele Berionne5e411512020-11-13 02:36:59 +00002059 case CMD_PREPARE_UNATTENDED_REBOOT:
2060 request = (MainThreadRequest) msg.obj;
2061 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002062 UiccController.getInstance().getPinStorage()
2063 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002064 notifyRequester(request);
2065 break;
2066
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067 default:
2068 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2069 break;
2070 }
2071 }
Jake Hambye994d462014-02-03 13:10:13 -08002072
Pengquan Menga1bb6272018-09-06 09:59:22 -07002073 private void notifyRequester(MainThreadRequest request) {
2074 synchronized (request) {
2075 request.notifyAll();
2076 }
2077 }
2078
Jake Hambye994d462014-02-03 13:10:13 -08002079 private void handleNullReturnEvent(Message msg, String command) {
2080 AsyncResult ar = (AsyncResult) msg.obj;
2081 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2082 if (ar.exception == null) {
2083 request.result = true;
2084 } else {
2085 request.result = false;
2086 if (ar.exception instanceof CommandException) {
2087 loge(command + ": CommandException: " + ar.exception);
2088 } else {
2089 loge(command + ": Unknown exception");
2090 }
2091 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002092 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 }
2095
2096 /**
2097 * Posts the specified command to be executed on the main thread,
2098 * waits for the request to complete, and returns the result.
2099 * @see #sendRequestAsync
2100 */
2101 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002102 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2103 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002104 }
2105
2106 /**
2107 * Posts the specified command to be executed on the main thread,
2108 * waits for the request to complete, and returns the result.
2109 * @see #sendRequestAsync
2110 */
2111 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2112 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002113 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002114 }
2115
2116 /**
2117 * Posts the specified command to be executed on the main thread,
2118 * waits for the request to complete, and returns the result.
2119 * @see #sendRequestAsync
2120 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002121 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002122 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2123 }
2124
2125 /**
2126 * Posts the specified command to be executed on the main thread,
2127 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2128 * if not timeout or null otherwise.
2129 * @see #sendRequestAsync
2130 */
2131 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2132 long timeoutInMs) {
2133 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002134 }
2135
2136 /**
2137 * Posts the specified command to be executed on the main thread,
2138 * waits for the request to complete, and returns the result.
2139 * @see #sendRequestAsync
2140 */
Nathan Harold92bed182018-10-12 18:16:49 -07002141 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002142 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002143 }
2144
2145 /**
2146 * Posts the specified command to be executed on the main thread,
2147 * waits for the request to complete, and returns the result.
2148 * @see #sendRequestAsync
2149 */
2150 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002151 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2152 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002153 }
2154
2155 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002156 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2157 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2158 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002159 * @see #sendRequestAsync
2160 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002161 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2162 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2164 throw new RuntimeException("This method will deadlock if called from the main thread.");
2165 }
2166
Nathan Harold92bed182018-10-12 18:16:49 -07002167 MainThreadRequest request = null;
2168 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2169 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2170 } else if (phone != null) {
2171 request = new MainThreadRequest(argument, phone, workSource);
2172 } else {
2173 request = new MainThreadRequest(argument, subId, workSource);
2174 }
2175
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176 Message msg = mMainThreadHandler.obtainMessage(command, request);
2177 msg.sendToTarget();
2178
Rambo Wang0f050d82021-02-12 11:43:36 -08002179
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002181 if (timeoutInMs >= 0) {
2182 // Wait for at least timeoutInMs before returning null request result
2183 long now = SystemClock.elapsedRealtime();
2184 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002185 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002186 try {
2187 request.wait(deadline - now);
2188 } catch (InterruptedException e) {
2189 // Do nothing, go back and check if request is completed or timeout
2190 } finally {
2191 now = SystemClock.elapsedRealtime();
2192 }
2193 }
2194 } else {
2195 // Wait for the request to complete
2196 while (request.result == null) {
2197 try {
2198 request.wait();
2199 } catch (InterruptedException e) {
2200 // Do nothing, go back and wait until the request is complete
2201 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 }
2203 }
2204 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002205 if (request.result == null) {
2206 Log.wtf(LOG_TAG,
2207 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 return request.result;
2210 }
2211
2212 /**
2213 * Asynchronous ("fire and forget") version of sendRequest():
2214 * Posts the specified command to be executed on the main thread, and
2215 * returns immediately.
2216 * @see #sendRequest
2217 */
2218 private void sendRequestAsync(int command) {
2219 mMainThreadHandler.sendEmptyMessage(command);
2220 }
2221
2222 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002223 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002224 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002225 */
2226 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002227 sendRequestAsync(command, argument, null, null);
2228 }
2229
2230 /**
2231 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2232 * @see {@link #sendRequest(int,Object)}
2233 */
2234 private void sendRequestAsync(
2235 int command, Object argument, Phone phone, WorkSource workSource) {
2236 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002237 Message msg = mMainThreadHandler.obtainMessage(command, request);
2238 msg.sendToTarget();
2239 }
2240
2241 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 * Initialize the singleton PhoneInterfaceManager instance.
2243 * This is only done once, at startup, from PhoneApp.onCreate().
2244 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002245 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 synchronized (PhoneInterfaceManager.class) {
2247 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002248 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 } else {
2250 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2251 }
2252 return sInstance;
2253 }
2254 }
2255
2256 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002257 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002260 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002261 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002263 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002265 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002266 mTelephonySharedPreferences =
2267 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002268 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002269 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002270 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002271 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002272
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 publish();
2274 }
2275
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002276 private Phone getDefaultPhone() {
2277 Phone thePhone = getPhone(getDefaultSubscription());
2278 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2279 }
2280
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 private void publish() {
2282 if (DBG) log("publish: " + this);
2283
Peter Wangc035ce42020-01-08 21:00:22 -08002284 TelephonyFrameworkInitializer
2285 .getTelephonyServiceManager()
2286 .getTelephonyServiceRegisterer()
2287 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 }
2289
Stuart Scott584921c2015-01-15 17:10:34 -08002290 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002291 if (request.phone != null) {
2292 return request.phone;
2293 } else {
2294 return getPhoneFromSubId(request.subId);
2295 }
2296 }
2297
2298 private Phone getPhoneFromSubId(int subId) {
2299 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2300 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002301 }
2302
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002303 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002304 Phone phone = getPhoneFromRequest(request);
2305 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002306 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002307 }
2308
Wink Saville36469e72014-06-11 15:17:00 -07002309 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002310 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002311 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313
Kai Shif70f46f2021-03-03 13:59:46 -08002314 private void sendEraseModemConfig(@NonNull Phone phone) {
2315 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2316 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2317 }
2318
2319 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2320 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2321 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002322 }
2323
Peter Wang44b186e2020-01-13 23:33:09 -08002324 private boolean isImsAvailableOnDevice() {
2325 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2326 if (pm == null) {
2327 // For some reason package manger is not available.. This will fail internally anyway,
2328 // so do not throw error and allow.
2329 return true;
2330 }
2331 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2332 }
2333
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002335 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002336 }
2337
Wink Savilleb564aae2014-10-23 10:18:09 -07002338 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 if (DBG) log("dial: " + number);
2340 // No permission check needed here: This is just a wrapper around the
2341 // ACTION_DIAL intent, which is available to any app since it puts up
2342 // the UI before it does anything.
2343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344 final long identity = Binder.clearCallingIdentity();
2345 try {
2346 String url = createTelUrl(number);
2347 if (url == null) {
2348 return;
2349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002351 // PENDING: should we just silently fail if phone is offhook or ringing?
2352 PhoneConstants.State state = mCM.getState(subId);
2353 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2354 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2355 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2356 mApp.startActivity(intent);
2357 }
2358 } finally {
2359 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
2361 }
2362
2363 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002364 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002365 }
2366
Wink Savilleb564aae2014-10-23 10:18:09 -07002367 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 if (DBG) log("call: " + number);
2369
2370 // This is just a wrapper around the ACTION_CALL intent, but we still
2371 // need to do a permission check since we're calling startActivity()
2372 // from the context of the phone app.
2373 enforceCallPermission();
2374
Jordan Liu1617b712019-07-10 15:06:26 -07002375 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 != AppOpsManager.MODE_ALLOWED) {
2377 return;
2378 }
2379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 String url = createTelUrl(number);
2383 if (url == null) {
2384 return;
2385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387 boolean isValid = false;
2388 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2389 if (slist != null) {
2390 for (SubscriptionInfo subInfoRecord : slist) {
2391 if (subInfoRecord.getSubscriptionId() == subId) {
2392 isValid = true;
2393 break;
2394 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002395 }
Wink Saville08874612014-08-31 19:19:58 -07002396 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397 if (!isValid) {
2398 return;
2399 }
Wink Saville08874612014-08-31 19:19:58 -07002400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002401 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2402 intent.putExtra(SUBSCRIPTION_KEY, subId);
2403 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2404 mApp.startActivity(intent);
2405 } finally {
2406 Binder.restoreCallingIdentity(identity);
2407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 }
2409
Wink Savilleb564aae2014-10-23 10:18:09 -07002410 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002411 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002412 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2413 }
2414
Wink Savilleb564aae2014-10-23 10:18:09 -07002415 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002416 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002417 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2418 }
2419
Wink Savilleb564aae2014-10-23 10:18:09 -07002420 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002422
2423 final long identity = Binder.clearCallingIdentity();
2424 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002425 Phone phone = getPhone(subId);
2426 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002427 checkSimPin.start();
2428 return checkSimPin.unlockSim(null, pin);
2429 } finally {
2430 Binder.restoreCallingIdentity(identity);
2431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 }
2433
Wink Savilleb564aae2014-10-23 10:18:09 -07002434 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002436
2437 final long identity = Binder.clearCallingIdentity();
2438 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002439 Phone phone = getPhone(subId);
2440 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002441 checkSimPuk.start();
2442 return checkSimPuk.unlockSim(puk, pin);
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
2445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 }
2447
2448 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002449 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 * a synchronous one.
2451 */
2452 private static class UnlockSim extends Thread {
2453
2454 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002455 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456
2457 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002458 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2459 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460
2461 // For replies from SimCard interface
2462 private Handler mHandler;
2463
2464 // For async handler to identify request type
2465 private static final int SUPPLY_PIN_COMPLETE = 100;
2466
Michele Berionne5e411512020-11-13 02:36:59 +00002467 UnlockSim(int phoneId, IccCard simCard) {
2468 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 mSimCard = simCard;
2470 }
2471
2472 @Override
2473 public void run() {
2474 Looper.prepare();
2475 synchronized (UnlockSim.this) {
2476 mHandler = new Handler() {
2477 @Override
2478 public void handleMessage(Message msg) {
2479 AsyncResult ar = (AsyncResult) msg.obj;
2480 switch (msg.what) {
2481 case SUPPLY_PIN_COMPLETE:
2482 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2483 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002484 mRetryCount = msg.arg1;
2485 if (ar.exception != null) {
2486 if (ar.exception instanceof CommandException &&
2487 ((CommandException)(ar.exception)).getCommandError()
2488 == CommandException.Error.PASSWORD_INCORRECT) {
2489 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002490 } //When UiccCardApp dispose,handle message and return exception
2491 else if (ar.exception instanceof CommandException &&
2492 ((CommandException) (ar.exception)).getCommandError()
2493 == CommandException.Error.ABORTED) {
2494 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002495 } else {
2496 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2497 }
2498 } else {
2499 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 mDone = true;
2502 UnlockSim.this.notifyAll();
2503 }
2504 break;
2505 }
2506 }
2507 };
2508 UnlockSim.this.notifyAll();
2509 }
2510 Looper.loop();
2511 }
2512
2513 /*
2514 * Use PIN or PUK to unlock SIM card
2515 *
2516 * If PUK is null, unlock SIM card with PIN
2517 *
2518 * If PUK is not null, unlock SIM card with PUK and set PIN code
2519 */
Wink Saville9de0f752013-10-22 19:04:03 -07002520 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521
2522 while (mHandler == null) {
2523 try {
2524 wait();
2525 } catch (InterruptedException e) {
2526 Thread.currentThread().interrupt();
2527 }
2528 }
2529 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2530
2531 if (puk == null) {
2532 mSimCard.supplyPin(pin, callback);
2533 } else {
2534 mSimCard.supplyPuk(puk, pin, callback);
2535 }
2536
2537 while (!mDone) {
2538 try {
2539 Log.d(LOG_TAG, "wait for done");
2540 wait();
2541 } catch (InterruptedException e) {
2542 // Restore the interrupted status
2543 Thread.currentThread().interrupt();
2544 }
2545 }
2546 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002547 int[] resultArray = new int[2];
2548 resultArray[0] = mResult;
2549 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002550
2551 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Grace Jia59437e82021-09-21 15:47:32 -07002552 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
2553 pinStorage.storePin(pin, mPhoneId, pinStorage.getIccid(mPhoneId));
Michele Berionne5e411512020-11-13 02:36:59 +00002554 }
2555
Wink Saville9de0f752013-10-22 19:04:03 -07002556 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 }
2558 }
2559
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002560 /**
2561 * This method has been removed due to privacy and stability concerns.
2562 */
2563 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002565 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2566 return;
Wink Saville36469e72014-06-11 15:17:00 -07002567 }
2568
Nathan Harold1f889d82020-06-04 17:05:26 -07002569 @Override
2570 public void updateServiceLocationWithPackageName(String callingPackage) {
2571 mApp.getSystemService(AppOpsManager.class)
2572 .checkPackage(Binder.getCallingUid(), callingPackage);
2573
Nathan Haroldf096d982020-11-18 17:18:06 -08002574 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002575 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2576 // Callers targeting S have no business invoking this method.
2577 return;
2578 }
2579
2580 LocationAccessPolicy.LocationPermissionResult locationResult =
2581 LocationAccessPolicy.checkLocationPermission(mApp,
2582 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2583 .setCallingPackage(callingPackage)
2584 .setCallingFeatureId(null)
2585 .setCallingPid(Binder.getCallingPid())
2586 .setCallingUid(Binder.getCallingUid())
2587 .setMethod("updateServiceLocation")
2588 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2589 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2590 .build());
2591 // Apps that lack location permission have no business calling this method;
2592 // however, because no permission was declared in the public API, denials must
2593 // all be "soft".
2594 switch (locationResult) {
2595 case DENIED_HARD: /* fall through */
2596 case DENIED_SOFT:
2597 return;
2598 }
2599
2600 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 final long identity = Binder.clearCallingIdentity();
2602 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002603 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002605 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606 }
2607 } finally {
2608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610 }
2611
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002612 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002613 @Override
2614 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002615 return isRadioOnWithFeature(callingPackage, null);
2616 }
2617
2618
2619 @Override
2620 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2621 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2622 callingFeatureId);
2623 }
2624
2625 @Deprecated
2626 @Override
2627 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2628 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002629 }
2630
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002631 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002632 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2633 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002635 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002636 return false;
2637 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638
2639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 return isRadioOnForSubscriber(subId);
2642 } finally {
2643 Binder.restoreCallingIdentity(identity);
2644 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002645 }
2646
2647 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 final long identity = Binder.clearCallingIdentity();
2649 try {
2650 final Phone phone = getPhone(subId);
2651 if (phone != null) {
2652 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2653 } else {
2654 return false;
2655 }
2656 } finally {
2657 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 }
2660
2661 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002662 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663 }
Wink Saville36469e72014-06-11 15:17:00 -07002664
Wink Savilleb564aae2014-10-23 10:18:09 -07002665 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667
2668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 final Phone phone = getPhone(subId);
2671 if (phone != null) {
2672 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2673 }
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002676 }
Wink Saville36469e72014-06-11 15:17:00 -07002677 }
2678
2679 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002680 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002681 }
2682
Wink Savilleb564aae2014-10-23 10:18:09 -07002683 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685
2686 final long identity = Binder.clearCallingIdentity();
2687 try {
2688 final Phone phone = getPhone(subId);
2689 if (phone == null) {
2690 return false;
2691 }
2692 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2693 toggleRadioOnOffForSubscriber(subId);
2694 }
2695 return true;
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 }
Wink Saville36469e72014-06-11 15:17:00 -07002700
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002701 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002702 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002703 /*
2704 * If any of the Radios are available, it will need to be
2705 * shutdown. So return true if any Radio is available.
2706 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707 final long identity = Binder.clearCallingIdentity();
2708 try {
2709 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2710 Phone phone = PhoneFactory.getPhone(i);
2711 if (phone != null && phone.isRadioAvailable()) return true;
2712 }
2713 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2714 return false;
2715 } finally {
2716 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002717 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002718 }
2719
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002721 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 enforceModifyPermission();
2723
2724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2727 logv("Shutting down Phone " + i);
2728 shutdownRadioUsingPhoneId(i);
2729 }
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002732 }
2733 }
2734
2735 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002736 Phone phone = PhoneFactory.getPhone(phoneId);
2737 if (phone != null && phone.isRadioAvailable()) {
2738 phone.shutdownRadio();
2739 }
2740 }
2741
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002743 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744
2745 final long identity = Binder.clearCallingIdentity();
2746 try {
2747 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2748 if (defaultPhone != null) {
2749 defaultPhone.setRadioPower(turnOn);
2750 return true;
2751 } else {
2752 loge("There's no default phone.");
2753 return false;
2754 }
2755 } finally {
2756 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002757 }
Wink Saville36469e72014-06-11 15:17:00 -07002758 }
2759
Wink Savilleb564aae2014-10-23 10:18:09 -07002760 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 final Phone phone = getPhone(subId);
2766 if (phone != null) {
2767 phone.setRadioPower(turnOn);
2768 return true;
2769 } else {
2770 return false;
2771 }
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 }
2776
Wink Saville36469e72014-06-11 15:17:00 -07002777 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002778 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 public boolean enableDataConnectivity() {
2780 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 int subId = mSubscriptionController.getDefaultDataSubId();
2785 final Phone phone = getPhone(subId);
2786 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002787 phone.getDataEnabledSettings().setDataEnabled(
2788 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 return true;
2790 } else {
2791 return false;
2792 }
2793 } finally {
2794 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 }
2797
Wink Saville36469e72014-06-11 15:17:00 -07002798 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002799 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002800 public boolean disableDataConnectivity() {
2801 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 int subId = mSubscriptionController.getDefaultDataSubId();
2806 final Phone phone = getPhone(subId);
2807 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002808 phone.getDataEnabledSettings().setDataEnabled(
2809 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810 return true;
2811 } else {
2812 return false;
2813 }
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002816 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 }
2818
Sanket Padawe356d7632015-06-22 14:03:32 -07002819 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002820 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 final Phone phone = getPhone(subId);
2824 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002825 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826 } else {
2827 return false;
2828 }
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 }
2833
2834 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002835 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002836 }
2837
pkanwarae03a6b2016-11-06 20:37:09 -08002838 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002839 enforceCallPermission();
2840
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2844 return;
2845 }
2846 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2847 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2848 } finally {
2849 Binder.restoreCallingIdentity(identity);
2850 }
pkanwar32d516d2016-10-14 19:37:38 -07002851 };
2852
Wink Savilleb564aae2014-10-23 10:18:09 -07002853 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002854 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002855
2856 final long identity = Binder.clearCallingIdentity();
2857 try {
2858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2859 return false;
2860 }
2861 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002865 }
2866
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002867 /**
2868 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2869 * tag on getCallState Binder call.
2870 */
2871 @Deprecated
2872 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002874 if (CompatChanges.isChangeEnabled(
2875 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2876 Binder.getCallingUid())) {
2877 // Do not allow this API to be called on API version 31+, it should only be
2878 // called on old apps using this Binder call directly.
2879 throw new SecurityException("This method can only be used for applications "
2880 + "targeting API version 30 or less.");
2881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882 final long identity = Binder.clearCallingIdentity();
2883 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002884 Phone phone = getPhone(getDefaultSubscription());
2885 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2886 PhoneConstantConversions.convertCallState(phone.getState());
2887 } finally {
2888 Binder.restoreCallingIdentity(identity);
2889 }
2890 }
2891
2892 @Override
2893 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2894 if (CompatChanges.isChangeEnabled(
2895 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2896 Binder.getCallingUid())) {
2897 // Check READ_PHONE_STATE for API version 31+
2898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2899 featureId, "getCallStateForSubscription")) {
2900 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2901 + "targeting API level 31+.");
2902 }
2903 }
2904 final long identity = Binder.clearCallingIdentity();
2905 try {
2906 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2908 PhoneConstantConversions.convertCallState(phone.getState());
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
2911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 }
2913
Sanket Padawe356d7632015-06-22 14:03:32 -07002914 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002915 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002916 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2917 }
2918
2919 @Override
2920 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 final long identity = Binder.clearCallingIdentity();
2922 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002923 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 if (phone != null) {
2925 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2926 } else {
2927 return PhoneConstantConversions.convertDataState(
2928 PhoneConstants.DataState.DISCONNECTED);
2929 }
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 }
2934
Sanket Padawe356d7632015-06-22 14:03:32 -07002935 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002936 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002937 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2938 }
2939
2940 @Override
2941 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942 final long identity = Binder.clearCallingIdentity();
2943 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002944 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 if (phone != null) {
2946 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2947 } else {
2948 return TelephonyManager.DATA_ACTIVITY_NONE;
2949 }
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 }
2954
2955 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002956 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002957 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002958 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002959
2960 LocationAccessPolicy.LocationPermissionResult locationResult =
2961 LocationAccessPolicy.checkLocationPermission(mApp,
2962 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2963 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002964 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002965 .setCallingPid(Binder.getCallingPid())
2966 .setCallingUid(Binder.getCallingUid())
2967 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002968 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002969 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2970 .build());
2971 switch (locationResult) {
2972 case DENIED_HARD:
2973 throw new SecurityException("Not allowed to access cell location");
2974 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002975 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2976 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002977 }
2978
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002979 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002983 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002984 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
Svetoslav64fad262015-04-14 14:35:21 -07002988 }
2989
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002990 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002991 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002992 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2993 // registered cell info, so return a NULL country instead.
2994 final long identity = Binder.clearCallingIdentity();
2995 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002996 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2997 // Get default phone in this case.
2998 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2999 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003000 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003002 if (phone == null) return "";
3003 ServiceStateTracker sst = phone.getServiceStateTracker();
3004 if (sst == null) return "";
3005 LocaleTracker lt = sst.getLocaleTracker();
3006 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003007 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003011 }
3012
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003013 /**
3014 * This method was removed due to potential issues caused by performing partial
3015 * updates of service state, and lack of a credible use case.
3016 *
3017 * This has the ability to break the telephony implementation by disabling notification of
3018 * changes in device connectivity. DO NOT USE THIS!
3019 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003020 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003021 public void enableLocationUpdates() {
3022 mApp.enforceCallingOrSelfPermission(
3023 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003024 }
3025
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003026 /**
3027 * This method was removed due to potential issues caused by performing partial
3028 * updates of service state, and lack of a credible use case.
3029 *
3030 * This has the ability to break the telephony implementation by disabling notification of
3031 * changes in device connectivity. DO NOT USE THIS!
3032 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003033 @Override
3034 public void disableLocationUpdates() {
3035 mApp.enforceCallingOrSelfPermission(
3036 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003037 }
3038
3039 @Override
3040 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003041 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3042 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003043 try {
3044 mApp.getSystemService(AppOpsManager.class)
3045 .checkPackage(Binder.getCallingUid(), callingPackage);
3046 } catch (SecurityException e) {
3047 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3048 throw e;
3049 }
3050
Nathan Haroldf096d982020-11-18 17:18:06 -08003051 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003052 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3053 throw new SecurityException(
3054 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3055 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003056
Jordan Liu1617b712019-07-10 15:06:26 -07003057 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003058 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3059 return null;
3060 }
Svetoslav64fad262015-04-14 14:35:21 -07003061
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003062 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003063
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003064 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003065 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003066
Nathan Haroldf180aac2018-06-01 18:43:55 -07003067 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3068 for (CellInfo ci : info) {
3069 if (ci instanceof CellInfoGsm) {
3070 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3071 } else if (ci instanceof CellInfoWcdma) {
3072 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3073 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003075 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003076 }
3077
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003078 private List<CellInfo> getCachedCellInfo() {
3079 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3080 for (Phone phone : PhoneFactory.getPhones()) {
3081 List<CellInfo> info = phone.getAllCellInfo();
3082 if (info != null) cellInfos.addAll(info);
3083 }
3084 return cellInfos;
3085 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003086
3087 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003088 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003089 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003090 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003091
3092 LocationAccessPolicy.LocationPermissionResult locationResult =
3093 LocationAccessPolicy.checkLocationPermission(mApp,
3094 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3095 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003096 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003097 .setCallingPid(Binder.getCallingPid())
3098 .setCallingUid(Binder.getCallingUid())
3099 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003100 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003101 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3102 .build());
3103 switch (locationResult) {
3104 case DENIED_HARD:
3105 throw new SecurityException("Not allowed to access cell info");
3106 case DENIED_SOFT:
3107 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 }
3109
Nathan Haroldf096d982020-11-18 17:18:06 -08003110 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003111 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3112 return getCachedCellInfo();
3113 }
3114
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003115 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003116 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117 final long identity = Binder.clearCallingIdentity();
3118 try {
3119 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3120 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003121 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003122 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123 if (info != null) cellInfos.addAll(info);
3124 }
3125 return cellInfos;
3126 } finally {
3127 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003128 }
3129 }
3130
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003131 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003132 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3133 String callingFeatureId) {
3134 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3135 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003136 }
3137
3138 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003139 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3140 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003141 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003142 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003143 }
3144
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003145 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3146 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003147 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003148 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003149
3150 LocationAccessPolicy.LocationPermissionResult locationResult =
3151 LocationAccessPolicy.checkLocationPermission(mApp,
3152 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3153 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003154 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003155 .setCallingPid(Binder.getCallingPid())
3156 .setCallingUid(Binder.getCallingUid())
3157 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003158 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3159 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003160 .build());
3161 switch (locationResult) {
3162 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003163 if (TelephonyPermissions
3164 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003165 // Safetynet logging for b/154934934
3166 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3167 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003168 throw new SecurityException("Not allowed to access cell info");
3169 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003170 if (TelephonyPermissions
3171 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003172 // Safetynet logging for b/154934934
3173 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3174 }
Nathan Harold5320c422019-05-09 10:26:08 -07003175 try {
3176 cb.onCellInfo(new ArrayList<CellInfo>());
3177 } catch (RemoteException re) {
3178 // Drop without consequences
3179 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003180 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003181 }
3182
Nathan Harolda939a962019-05-09 10:13:47 -07003183
3184 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003185 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3186
3187 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3188 }
3189
3190 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003192 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003193 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194
3195 final long identity = Binder.clearCallingIdentity();
3196 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003197 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003201 }
3202
Shishir Agrawala9f32182016-04-12 12:00:16 -07003203 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003204 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003205 Phone phone = PhoneFactory.getPhone(slotIndex);
3206 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003207 return null;
3208 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003209 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003210 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003211 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003212 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003213 return null;
3214 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215
3216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 return phone.getImei();
3219 } finally {
3220 Binder.restoreCallingIdentity(identity);
3221 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003222 }
3223
3224 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003225 public String getTypeAllocationCodeForSlot(int slotIndex) {
3226 Phone phone = PhoneFactory.getPhone(slotIndex);
3227 String tac = null;
3228 if (phone != null) {
3229 String imei = phone.getImei();
3230 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3231 }
3232 return tac;
3233 }
3234
3235 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003236 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003237 try {
3238 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3239 } catch (SecurityException se) {
3240 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3241 throw new SecurityException("Package " + callingPackage + " does not belong to "
3242 + Binder.getCallingUid());
3243 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003244 Phone phone = PhoneFactory.getPhone(slotIndex);
3245 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003246 return null;
3247 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003248
Jeff Davidson913390f2018-02-23 17:11:49 -08003249 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003250 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003251 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003252 return null;
3253 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254
3255 final long identity = Binder.clearCallingIdentity();
3256 try {
3257 return phone.getMeid();
3258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
Jack Yu2af8d712017-03-15 17:14:14 -07003261 }
3262
3263 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003264 public String getManufacturerCodeForSlot(int slotIndex) {
3265 Phone phone = PhoneFactory.getPhone(slotIndex);
3266 String manufacturerCode = null;
3267 if (phone != null) {
3268 String meid = phone.getMeid();
3269 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3270 }
3271 return manufacturerCode;
3272 }
3273
3274 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003275 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3276 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003277 Phone phone = PhoneFactory.getPhone(slotIndex);
3278 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003279 return null;
3280 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003281 int subId = phone.getSubId();
3282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003283 mApp, subId, callingPackage, callingFeatureId,
3284 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003285 return null;
3286 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003287
3288 final long identity = Binder.clearCallingIdentity();
3289 try {
3290 return phone.getDeviceSvn();
3291 } finally {
3292 Binder.restoreCallingIdentity(identity);
3293 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003294 }
3295
fionaxu43304da2017-11-27 22:51:16 -08003296 @Override
3297 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 final Phone phone = getPhone(subId);
3301 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3302 } finally {
3303 Binder.restoreCallingIdentity(identity);
3304 }
fionaxu43304da2017-11-27 22:51:16 -08003305 }
3306
3307 @Override
3308 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 final Phone phone = getPhone(subId);
3312 return phone == null ? null : phone.getCarrierName();
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
fionaxu43304da2017-11-27 22:51:16 -08003316 }
3317
calvinpanffe225e2018-11-01 19:43:06 +08003318 @Override
chen xu0026ca62019-03-06 15:28:50 -08003319 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003320 final long identity = Binder.clearCallingIdentity();
3321 try {
3322 final Phone phone = getPhone(subId);
3323 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003324 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003325 } finally {
3326 Binder.restoreCallingIdentity(identity);
3327 }
3328 }
3329
3330 @Override
chen xu0026ca62019-03-06 15:28:50 -08003331 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003332 final long identity = Binder.clearCallingIdentity();
3333 try {
3334 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003335 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003336 } finally {
3337 Binder.restoreCallingIdentity(identity);
3338 }
3339 }
3340
chen xu651eec72018-11-11 19:03:44 -08003341 @Override
chen xu864e11c2018-12-06 22:10:03 -08003342 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3343 if (!isSubscriptionMccMnc) {
3344 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3345 }
chen xu651eec72018-11-11 19:03:44 -08003346 final Phone phone = PhoneFactory.getPhone(slotIndex);
3347 if (phone == null) {
3348 return TelephonyManager.UNKNOWN_CARRIER_ID;
3349 }
3350 final long identity = Binder.clearCallingIdentity();
3351 try {
3352 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3353 } finally {
3354 Binder.restoreCallingIdentity(identity);
3355 }
3356 }
3357
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003358 //
3359 // Internal helper methods.
3360 //
3361
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003362 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003363 * Make sure the caller is the calling package itself
3364 *
3365 * @throws SecurityException if the caller is not the calling package
3366 */
3367 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3368 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003369 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3370 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003371 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003372 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003373 } catch (PackageManager.NameNotFoundException e) {
3374 // packageUid is -1
3375 }
3376 if (packageUid != callingUid) {
3377 throw new SecurityException(message + ": Package " + callingPackage
3378 + " does not belong to " + callingUid);
3379 }
3380 }
3381
3382 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003383 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3384 *
3385 * @throws SecurityException if the caller does not have the required permission
3386 */
3387 private void enforceModifyPermission() {
3388 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3389 }
3390
Shuo Qiancd19c462020-01-16 20:51:11 -08003391 /**
3392 * Make sure the caller is system.
3393 *
3394 * @throws SecurityException if the caller is not system.
3395 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003396 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003397 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3398 throw new SecurityException("Caller must be system");
3399 }
3400 }
3401
Shuo Qian3b6ee772019-11-13 17:43:31 -08003402 private void enforceActiveEmergencySessionPermission() {
3403 mApp.enforceCallingOrSelfPermission(
3404 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3405 }
3406
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003407 /**
3408 * Make sure the caller has the CALL_PHONE permission.
3409 *
3410 * @throws SecurityException if the caller does not have the required permission
3411 */
3412 private void enforceCallPermission() {
3413 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3414 }
3415
paulhu5a773602019-08-23 19:17:33 +08003416 private void enforceSettingsPermission() {
3417 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003418 }
3419
Michele Berionne5e411512020-11-13 02:36:59 +00003420 private void enforceRebootPermission() {
3421 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3422 }
3423
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003424 private String createTelUrl(String number) {
3425 if (TextUtils.isEmpty(number)) {
3426 return null;
3427 }
3428
Jake Hambye994d462014-02-03 13:10:13 -08003429 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003430 }
3431
Ihab Awadf9e92732013-12-05 18:02:52 -08003432 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003433 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3434 }
3435
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003436 private static void logv(String msg) {
3437 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3438 }
3439
Ihab Awadf9e92732013-12-05 18:02:52 -08003440 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003441 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3442 }
3443
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003444 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003445 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003446 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003447 }
3448
Sanket Padawe356d7632015-06-22 14:03:32 -07003449 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003450 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003451 final long identity = Binder.clearCallingIdentity();
3452 try {
3453 final Phone phone = PhoneFactory.getPhone(slotIndex);
3454 if (phone == null) {
3455 return PhoneConstants.PHONE_TYPE_NONE;
3456 } else {
3457 return phone.getPhoneType();
3458 }
3459 } finally {
3460 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003461 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003462 }
3463
3464 /**
3465 * Returns the CDMA ERI icon index to display
3466 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003467 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003468 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3469 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3470 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003471 }
3472
Sanket Padawe356d7632015-06-22 14:03:32 -07003473 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003474 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3475 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003477 mApp, subId, callingPackage, callingFeatureId,
3478 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003479 return -1;
3480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003481
3482 final long identity = Binder.clearCallingIdentity();
3483 try {
3484 final Phone phone = getPhone(subId);
3485 if (phone != null) {
3486 return phone.getCdmaEriIconIndex();
3487 } else {
3488 return -1;
3489 }
3490 } finally {
3491 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003493 }
3494
3495 /**
3496 * Returns the CDMA ERI icon mode,
3497 * 0 - ON
3498 * 1 - FLASHING
3499 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003500 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003501 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3502 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3503 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003504 }
3505
Sanket Padawe356d7632015-06-22 14:03:32 -07003506 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003507 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3508 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003509 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003510 mApp, subId, callingPackage, callingFeatureId,
3511 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003512 return -1;
3513 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003514
3515 final long identity = Binder.clearCallingIdentity();
3516 try {
3517 final Phone phone = getPhone(subId);
3518 if (phone != null) {
3519 return phone.getCdmaEriIconMode();
3520 } else {
3521 return -1;
3522 }
3523 } finally {
3524 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003526 }
3527
3528 /**
3529 * Returns the CDMA ERI text,
3530 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003531 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003532 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3533 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3534 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003535 }
3536
Sanket Padawe356d7632015-06-22 14:03:32 -07003537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003538 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3539 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003541 mApp, subId, callingPackage, callingFeatureId,
3542 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003543 return null;
3544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545
3546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 final Phone phone = getPhone(subId);
3549 if (phone != null) {
3550 return phone.getCdmaEriText();
3551 } else {
3552 return null;
3553 }
3554 } finally {
3555 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003557 }
3558
3559 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003560 * Returns the CDMA MDN.
3561 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003562 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003563 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3565 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003566
3567 final long identity = Binder.clearCallingIdentity();
3568 try {
3569 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003570 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571 return phone.getLine1Number();
3572 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003573 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003574 return null;
3575 }
3576 } finally {
3577 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003578 }
3579 }
3580
3581 /**
3582 * Returns the CDMA MIN.
3583 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003584 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003585 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3587 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003588
3589 final long identity = Binder.clearCallingIdentity();
3590 try {
3591 final Phone phone = getPhone(subId);
3592 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3593 return phone.getCdmaMin();
3594 } else {
3595 return null;
3596 }
3597 } finally {
3598 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003599 }
3600 }
3601
Hall Liud892bec2018-11-30 14:51:45 -08003602 @Override
3603 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3604 INumberVerificationCallback callback, String callingPackage) {
3605 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3606 != PERMISSION_GRANTED) {
3607 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3608 }
3609 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3610
3611 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3612 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003613 throw new SecurityException("Calling package must be configured in the device config: "
3614 + "calling package: " + callingPackage
3615 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003616 }
3617
3618 if (range == null) {
3619 throw new NullPointerException("Range must be non-null");
3620 }
3621
3622 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003623 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003624
3625 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3626 }
3627
Junda Liuca05d5d2014-08-14 22:36:34 -07003628 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003629 * Returns true if CDMA provisioning needs to run.
3630 */
3631 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003632 final long identity = Binder.clearCallingIdentity();
3633 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003634 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003635 } finally {
3636 Binder.restoreCallingIdentity(identity);
3637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003638 }
3639
3640 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003641 * Sets the voice mail number of a given subId.
3642 */
3643 @Override
3644 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003645 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3646 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003647
3648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3651 new Pair<String, String>(alphaTag, number), new Integer(subId));
3652 return success;
3653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003656 }
3657
Ta-wei Yen87c49842016-05-13 21:19:52 -07003658 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003659 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3660 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003661 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3662 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003663 if (!TextUtils.equals(callingPackage, systemDialer)) {
3664 throw new SecurityException("caller must be system dialer");
3665 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003666
3667 final long identity = Binder.clearCallingIdentity();
3668 try {
3669 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3670 if (phoneAccountHandle == null) {
3671 return null;
3672 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003673 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003674 } finally {
3675 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003676 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003677 }
3678
3679 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003680 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3681 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003682 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003683 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003684 mApp, subId, callingPackage, callingFeatureId,
3685 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003686 return null;
3687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003688
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003689 final long identity = Binder.clearCallingIdentity();
3690 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003691 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003692 } finally {
3693 Binder.restoreCallingIdentity(identity);
3694 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003695 }
3696
3697 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003698 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3699 VisualVoicemailSmsFilterSettings settings) {
3700 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003701
3702 final long identity = Binder.clearCallingIdentity();
3703 try {
3704 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003705 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003706 } finally {
3707 Binder.restoreCallingIdentity(identity);
3708 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003709 }
3710
3711 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003712 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3713 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003714
3715 final long identity = Binder.clearCallingIdentity();
3716 try {
3717 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003718 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719 } finally {
3720 Binder.restoreCallingIdentity(identity);
3721 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003722 }
3723
3724 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003725 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3726 String callingPackage, int subId) {
3727 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728
3729 final long identity = Binder.clearCallingIdentity();
3730 try {
3731 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003732 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003733 } finally {
3734 Binder.restoreCallingIdentity(identity);
3735 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003736 }
3737
3738 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003739 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003740 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003741
3742 final long identity = Binder.clearCallingIdentity();
3743 try {
3744 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003745 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746 } finally {
3747 Binder.restoreCallingIdentity(identity);
3748 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003749 }
3750
3751 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003752 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3753 String callingAttributionTag, int subId, String number, int port, String text,
3754 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003755 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003756 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003757 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003758 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003759 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3760 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003761 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003762
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003763 /**
fionaxu0152e512016-11-14 13:36:14 -08003764 * Sets the voice activation state of a given subId.
3765 */
3766 @Override
3767 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3769 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003770
3771 final long identity = Binder.clearCallingIdentity();
3772 try {
3773 final Phone phone = getPhone(subId);
3774 if (phone != null) {
3775 phone.setVoiceActivationState(activationState);
3776 } else {
3777 loge("setVoiceActivationState fails with invalid subId: " + subId);
3778 }
3779 } finally {
3780 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003781 }
3782 }
3783
3784 /**
3785 * Sets the data activation state of a given subId.
3786 */
3787 @Override
3788 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3790 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 final Phone phone = getPhone(subId);
3795 if (phone != null) {
3796 phone.setDataActivationState(activationState);
3797 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003798 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799 }
3800 } finally {
3801 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003802 }
3803 }
3804
3805 /**
3806 * Returns the voice activation state of a given subId.
3807 */
3808 @Override
3809 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003810 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811
fionaxu0152e512016-11-14 13:36:14 -08003812 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 if (phone != null) {
3816 return phone.getVoiceActivationState();
3817 } else {
3818 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3819 }
3820 } finally {
3821 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003822 }
3823 }
3824
3825 /**
3826 * Returns the data activation state of a given subId.
3827 */
3828 @Override
3829 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003830 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831
fionaxu0152e512016-11-14 13:36:14 -08003832 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003833 final long identity = Binder.clearCallingIdentity();
3834 try {
3835 if (phone != null) {
3836 return phone.getDataActivationState();
3837 } else {
3838 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3839 }
3840 } finally {
3841 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003842 }
3843 }
3844
3845 /**
Wink Saville36469e72014-06-11 15:17:00 -07003846 * Returns the unread count of voicemails for a subId
3847 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003848 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003849 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3850 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003851 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003852 mApp, subId, callingPackage, callingFeatureId,
3853 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003854 return 0;
3855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003856 final long identity = Binder.clearCallingIdentity();
3857 try {
3858 final Phone phone = getPhone(subId);
3859 if (phone != null) {
3860 return phone.getVoiceMessageCount();
3861 } else {
3862 return 0;
3863 }
3864 } finally {
3865 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003866 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003867 }
3868
3869 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003870 * returns true, if the device is in a state where both voice and data
3871 * are supported simultaneously. This can change based on location or network condition.
3872 */
3873 @Override
3874 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003875 final long identity = Binder.clearCallingIdentity();
3876 try {
3877 final Phone phone = getPhone(subId);
3878 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3879 } finally {
3880 Binder.restoreCallingIdentity(identity);
3881 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003882 }
3883
3884 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003885 * Send the dialer code if called from the current default dialer or the caller has
3886 * carrier privilege.
3887 * @param inputCode The dialer code to send
3888 */
3889 @Override
3890 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003891 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003892 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003893 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3894 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003895 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003896 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003897 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003898 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003899
3900 final long identity = Binder.clearCallingIdentity();
3901 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003902 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003903 } finally {
3904 Binder.restoreCallingIdentity(identity);
3905 }
fionaxu235cc5e2017-03-06 22:25:57 -08003906 }
3907
Pengquan Menga1bb6272018-09-06 09:59:22 -07003908 @Override
3909 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003910 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003911 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003912 mApp, subId, "getNetworkSelectionMode");
3913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 if (!isActiveSubscription(subId)) {
3916 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3917 }
3918 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3919 } finally {
3920 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003921 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003922 }
3923
Brad Ebinger35c841c2018-10-01 10:40:55 -07003924 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003925 public boolean isInEmergencySmsMode() {
3926 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3927 final long identity = Binder.clearCallingIdentity();
3928 try {
3929 for (Phone phone : PhoneFactory.getPhones()) {
3930 if (phone.isInEmergencySmsMode()) {
3931 return true;
3932 }
3933 }
3934 } finally {
3935 Binder.restoreCallingIdentity(identity);
3936 }
3937 return false;
3938 }
3939
shilu366312e2019-12-17 09:28:10 -08003940 /**
3941 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3942 * @param subId The subscription to use to check the configuration.
3943 * @param c The callback that will be used to send the result.
3944 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003945 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003946 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3947 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003948 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003949 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003950
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003951 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3952 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3953 "IMS not available on device.");
3954 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003955 final long token = Binder.clearCallingIdentity();
3956 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003957 int slotId = getSlotIndexOrException(subId);
3958 verifyImsMmTelConfiguredOrThrow(slotId);
3959 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003960 } catch (ImsException e) {
3961 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003962 } finally {
3963 Binder.restoreCallingIdentity(token);
3964 }
3965 }
3966
shilu366312e2019-12-17 09:28:10 -08003967 /**
3968 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3969 * @param subId The subscription to use to check the configuration.
3970 * @param c The callback that will be used to send the result.
3971 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003973 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003974 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003975 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003976 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3977 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3978 }
Meng Wangafbc5852019-09-19 17:37:13 -07003979 final long token = Binder.clearCallingIdentity();
3980 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003981 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3982 .removeRegistrationCallbackForSubscription(c, subId);
3983 } catch (ImsException e) {
3984 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3985 + "is inactive, ignoring unregister.");
3986 // If the subscription is no longer active, just return, since the callback
3987 // will already have been removed internally.
3988 } finally {
3989 Binder.restoreCallingIdentity(token);
3990 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003991 }
3992
Brad Ebingera34a6c22019-10-22 17:36:18 -07003993 /**
3994 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3995 */
3996 @Override
3997 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3998 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3999 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4000 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4001 "IMS not available on device.");
4002 }
4003 final long token = Binder.clearCallingIdentity();
4004 try {
4005 Phone phone = getPhone(subId);
4006 if (phone == null) {
4007 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4008 + subId + "'");
4009 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4010 }
4011 phone.getImsRegistrationState(regState -> {
4012 try {
4013 consumer.accept((regState == null)
4014 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4015 } catch (RemoteException e) {
4016 // Ignore if the remote process is no longer available to call back.
4017 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4018 }
4019 });
4020 } finally {
4021 Binder.restoreCallingIdentity(token);
4022 }
4023 }
4024
4025 /**
4026 * Get the transport type for the IMS service registration state.
4027 */
4028 @Override
4029 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004030 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004031 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004032 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4033 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4034 "IMS not available on device.");
4035 }
4036 final long token = Binder.clearCallingIdentity();
4037 try {
4038 Phone phone = getPhone(subId);
4039 if (phone == null) {
4040 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4041 + subId + "'");
4042 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4043 }
4044 phone.getImsRegistrationTech(regTech -> {
4045 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4046 int regTechConverted = (regTech == null)
4047 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4048 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4049 regTechConverted);
4050 try {
4051 consumer.accept(regTechConverted);
4052 } catch (RemoteException e) {
4053 // Ignore if the remote process is no longer available to call back.
4054 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4055 }
4056 });
4057 } finally {
4058 Binder.restoreCallingIdentity(token);
4059 }
4060 }
4061
shilu366312e2019-12-17 09:28:10 -08004062 /**
4063 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4064 * @param subId The subscription to use to check the configuration.
4065 * @param c The callback that will be used to send the result.
4066 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004067 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004068 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4069 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004070 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004071 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004072 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4073 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4074 "IMS not available on device.");
4075 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004076 final long token = Binder.clearCallingIdentity();
4077 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004078 int slotId = getSlotIndexOrException(subId);
4079 verifyImsMmTelConfiguredOrThrow(slotId);
4080 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004081 } catch (ImsException e) {
4082 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004083 } finally {
4084 Binder.restoreCallingIdentity(token);
4085 }
4086 }
4087
shilu366312e2019-12-17 09:28:10 -08004088 /**
4089 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4090 * @param subId The subscription to use to check the configuration.
4091 * @param c The callback that will be used to send the result.
4092 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004093 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004094 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004095 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004096 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004097 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4098 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4099 }
Meng Wangafbc5852019-09-19 17:37:13 -07004100
4101 final long token = Binder.clearCallingIdentity();
4102 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004103 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004104 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004105 } catch (ImsException e) {
4106 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4107 + "is inactive, ignoring unregister.");
4108 // If the subscription is no longer active, just return, since the callback
4109 // will already have been removed internally.
4110 } finally {
4111 Binder.restoreCallingIdentity(token);
4112 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004113 }
4114
4115 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004116 public boolean isCapable(int subId, int capability, int regTech) {
4117 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 final long token = Binder.clearCallingIdentity();
4119 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004120 int slotId = getSlotIndexOrException(subId);
4121 verifyImsMmTelConfiguredOrThrow(slotId);
4122 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004123 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004124 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4125 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004126 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004127 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4128 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004129 } finally {
4130 Binder.restoreCallingIdentity(token);
4131 }
4132 }
4133
4134 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004135 public boolean isAvailable(int subId, int capability, int regTech) {
4136 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004137 final long token = Binder.clearCallingIdentity();
4138 try {
4139 Phone phone = getPhone(subId);
4140 if (phone == null) return false;
4141 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004142 } catch (com.android.ims.ImsException e) {
4143 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4144 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004145 } finally {
4146 Binder.restoreCallingIdentity(token);
4147 }
4148 }
4149
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004150 /**
4151 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4152 * subscription.
4153 * @param subId The subscription to use to check the configuration.
4154 * @param callback The callback that will be used to send the result.
4155 * @param capability The MmTelFeature capability that will be used to send the result.
4156 * @param transportType The transport type of the MmTelFeature capability.
4157 */
4158 @Override
4159 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4160 int transportType) {
4161 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4162 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4163 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4164 "IMS not available on device.");
4165 }
4166 final long token = Binder.clearCallingIdentity();
4167 try {
4168 int slotId = getSlotIndex(subId);
4169 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4170 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4171 + subId + "'");
4172 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4173 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004174 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004175 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4176 transportType, aBoolean -> {
4177 try {
4178 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4179 } catch (RemoteException e) {
4180 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4181 + "running. Ignore");
4182 }
4183 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004184 } catch (ImsException e) {
4185 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004186 } finally {
4187 Binder.restoreCallingIdentity(token);
4188 }
4189 }
4190
shilu366312e2019-12-17 09:28:10 -08004191 /**
4192 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4193 * @param subId The subscription to use to check the configuration.
4194 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 @Override
4196 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004197 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004198 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004199
Brad Ebinger35c841c2018-10-01 10:40:55 -07004200 final long token = Binder.clearCallingIdentity();
4201 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004202 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004203 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004204 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004205 } catch (ImsException e) {
4206 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 } finally {
4208 Binder.restoreCallingIdentity(token);
4209 }
4210 }
4211
4212 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004213 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004215 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 final long identity = Binder.clearCallingIdentity();
4217 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004218 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004219 // This setting doesn't require an active ImsService connection, so do not verify. The
4220 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004221 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004222 } catch (ImsException e) {
4223 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004224 } finally {
4225 Binder.restoreCallingIdentity(identity);
4226 }
4227 }
4228
shilu366312e2019-12-17 09:28:10 -08004229 /**
4230 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4231 * @param subId The subscription to use to check the configuration.
4232 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004233 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004234 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004235 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004236 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004237 final long identity = Binder.clearCallingIdentity();
4238 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004239 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004240 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004241 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004242 } catch (ImsException e) {
4243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 } finally {
4245 Binder.restoreCallingIdentity(identity);
4246 }
4247 }
4248
4249 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004250 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004252 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004253 final long identity = Binder.clearCallingIdentity();
4254 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004255 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004256 // This setting doesn't require an active ImsService connection, so do not verify. The
4257 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004258 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004259 } catch (ImsException e) {
4260 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004261 } finally {
4262 Binder.restoreCallingIdentity(identity);
4263 }
4264 }
4265
shilu366312e2019-12-17 09:28:10 -08004266 /**
4267 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4268 * @param subId The subscription to use to check the configuration.
4269 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004270 @Override
4271 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004272 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004273 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004274 final long identity = Binder.clearCallingIdentity();
4275 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004276 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004277 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004278 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004279 } catch (ImsException e) {
4280 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
4284 }
4285
4286 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004287 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004289 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004290 final long identity = Binder.clearCallingIdentity();
4291 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004292 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004293 // This setting doesn't require an active ImsService connection, so do not verify. The
4294 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004295 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004296 } catch (ImsException e) {
4297 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 } finally {
4299 Binder.restoreCallingIdentity(identity);
4300 }
4301 }
4302
shilu366312e2019-12-17 09:28:10 -08004303 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004304 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4305 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4306 * @param subId The subscription to use to check the configuration.
4307 */
4308 @Override
4309 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004310 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004311 mApp, subId, "isCrossSimCallingEnabledByUser");
4312 final long identity = Binder.clearCallingIdentity();
4313 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004314 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004315 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004316 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004317 } catch (ImsException e) {
4318 throw new ServiceSpecificException(e.getCode());
4319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
4322 }
4323
4324 /**
4325 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4326 * Requires MODIFY_PHONE_STATE permission.
4327 * @param subId The subscription to use to check the configuration.
4328 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4329 * false otherwise
4330 */
4331 @Override
4332 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4333 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4334 "setCrossSimCallingEnabled");
4335 final long identity = Binder.clearCallingIdentity();
4336 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004337 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004338 // This setting doesn't require an active ImsService connection, so do not verify. The
4339 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004340 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004341 } catch (ImsException e) {
4342 throw new ServiceSpecificException(e.getCode());
4343 } finally {
4344 Binder.restoreCallingIdentity(identity);
4345 }
4346 }
4347
4348 /**
shilu366312e2019-12-17 09:28:10 -08004349 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4350 * @param subId The subscription to use to check the configuration.
4351 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004352 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004353
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004355 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004356 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004357 final long identity = Binder.clearCallingIdentity();
4358 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004359 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004360 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004361 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004362 } catch (ImsException e) {
4363 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 } finally {
4365 Binder.restoreCallingIdentity(identity);
4366 }
4367 }
4368
4369 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004370 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004372 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004373 final long identity = Binder.clearCallingIdentity();
4374 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004375 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004376 // This setting doesn't require an active ImsService connection, so do not verify. The
4377 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004378 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004379 } catch (ImsException e) {
4380 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004381 } finally {
4382 Binder.restoreCallingIdentity(identity);
4383 }
4384 }
4385
4386 @Override
4387 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4389 "setVoWiFiNonPersistent");
4390 final long identity = Binder.clearCallingIdentity();
4391 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004392 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004393 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004394 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004395 } catch (ImsException e) {
4396 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
4400 }
4401
shilu366312e2019-12-17 09:28:10 -08004402 /**
4403 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4404 * @param subId The subscription to use to check the configuration.
4405 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004406 @Override
4407 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004408 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004409 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004410 final long identity = Binder.clearCallingIdentity();
4411 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004412 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004413 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004414 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004415 } catch (ImsException e) {
4416 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004417 } finally {
4418 Binder.restoreCallingIdentity(identity);
4419 }
4420 }
4421
4422 @Override
4423 public void setVoWiFiModeSetting(int subId, int mode) {
4424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4425 "setVoWiFiModeSetting");
4426 final long identity = Binder.clearCallingIdentity();
4427 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004428 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004429 // This setting doesn't require an active ImsService connection, so do not verify. The
4430 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004431 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004432 } catch (ImsException e) {
4433 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004434 } finally {
4435 Binder.restoreCallingIdentity(identity);
4436 }
4437 }
4438
4439 @Override
4440 public int getVoWiFiRoamingModeSetting(int subId) {
4441 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4442 final long identity = Binder.clearCallingIdentity();
4443 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004444 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004445 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004446 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004447 } catch (ImsException e) {
4448 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004449 } finally {
4450 Binder.restoreCallingIdentity(identity);
4451 }
4452 }
4453
4454 @Override
4455 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4457 "setVoWiFiRoamingModeSetting");
4458 final long identity = Binder.clearCallingIdentity();
4459 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004460 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004461 // This setting doesn't require an active ImsService connection, so do not verify. The
4462 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004463 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004464 } catch (ImsException e) {
4465 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
4469 }
4470
4471 @Override
4472 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4474 "setRttCapabilityEnabled");
4475 final long identity = Binder.clearCallingIdentity();
4476 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004477 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004478 // This setting doesn't require an active ImsService connection, so do not verify. The
4479 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004480 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004481 } catch (ImsException e) {
4482 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004483 } finally {
4484 Binder.restoreCallingIdentity(identity);
4485 }
4486 }
4487
shilu366312e2019-12-17 09:28:10 -08004488 /**
4489 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4490 * @param subId The subscription to use to check the configuration.
4491 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 @Override
4493 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004494 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004495 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004496 final long identity = Binder.clearCallingIdentity();
4497 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004498 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004499 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004500 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004501 } catch (ImsException e) {
4502 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
4506 }
4507
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004508 @Override
4509 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4510 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4511 final long identity = Binder.clearCallingIdentity();
4512 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004513 if (!isImsAvailableOnDevice()) {
4514 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4515 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004516 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004517 int slotId = getSlotIndexOrException(subId);
4518 verifyImsMmTelConfiguredOrThrow(slotId);
4519 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004520 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004521 } catch (ImsException e) {
4522 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004523 } finally {
4524 Binder.restoreCallingIdentity(identity);
4525 }
4526 }
4527
4528 @Override
4529 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4530 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4531 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004532 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4533 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4534 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004535 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004536 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004537 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004538 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004539 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4540 + "is inactive, ignoring unregister.");
4541 // If the subscription is no longer active, just return, since the callback will already
4542 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004543 } finally {
4544 Binder.restoreCallingIdentity(identity);
4545 }
4546 }
4547
allenwtsu99c623b2020-01-03 18:24:23 +08004548
4549 private void checkModifyPhoneStatePermission(int subId, String message) {
4550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4551 message);
4552 }
4553
4554 private boolean isImsProvisioningRequired(int subId, int capability,
4555 boolean isMmtelCapability) {
4556 Phone phone = getPhone(subId);
4557 if (phone == null) {
4558 loge("phone instance null for subid " + subId);
4559 return false;
4560 }
4561 if (isMmtelCapability) {
4562 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4563 return false;
4564 }
4565 } else {
4566 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4567 return false;
4568 }
4569 }
4570 return true;
4571 }
4572
4573 @Override
4574 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4575 boolean isProvisioned) {
4576 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4577
4578 final long identity = Binder.clearCallingIdentity();
4579 try {
4580 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4581 if (!isImsProvisioningRequired(subId, capability, false)) {
4582 return;
4583 }
4584
4585 // this capability requires provisioning, route to the correct API.
4586 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4587 switch (capability) {
4588 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4589 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4590 ims.setEabProvisioned(isProvisioned);
4591 break;
4592 default: {
4593 throw new IllegalArgumentException("Tried to set provisioning for "
4594 + "rcs capability '" + capability + "', which does not require "
4595 + "provisioning.");
4596 }
4597 }
4598 } finally {
4599 Binder.restoreCallingIdentity(identity);
4600 }
4601
4602 }
4603
4604
4605 @Override
4606 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4607 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4608 final long identity = Binder.clearCallingIdentity();
4609 try {
4610 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4611 if (!isImsProvisioningRequired(subId, capability, false)) {
4612 return true;
4613 }
4614
4615 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4616 switch (capability) {
4617 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4618 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4619 return ims.isEabProvisionedOnDevice();
4620
4621 default: {
4622 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4623 + "capability '" + capability + "', which does not require "
4624 + "provisioning.");
4625 }
4626 }
4627
4628 } finally {
4629 Binder.restoreCallingIdentity(identity);
4630 }
4631 }
4632
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004633 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004634 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4635 boolean isProvisioned) {
4636 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004637 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4638 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4639 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004640 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4641 }
allenwtsu99c623b2020-01-03 18:24:23 +08004642 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004643 final long identity = Binder.clearCallingIdentity();
4644 try {
4645 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004646 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004647 return;
4648 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004649 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4650 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4651 loge("setImsProvisioningStatusForCapability: called for technology that does "
4652 + "not support provisioning - " + tech);
4653 return;
4654 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004655
4656 // this capability requires provisioning, route to the correct API.
4657 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4658 switch (capability) {
4659 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4660 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4661 ims.setVolteProvisioned(isProvisioned);
4662 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4663 ims.setWfcProvisioned(isProvisioned);
4664 }
4665 break;
4666 }
4667 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4668 // There is currently no difference in VT provisioning type.
4669 ims.setVtProvisioned(isProvisioned);
4670 break;
4671 }
4672 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4673 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4674 // change the capability of the feature instead if needed.
4675 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4676 == isProvisioned) {
4677 // No change in provisioning.
4678 return;
4679 }
4680 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4681 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004682 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004683 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004684 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4685 + ", Exception" + e.getMessage());
4686 }
4687 break;
4688 }
4689 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004690 throw new IllegalArgumentException("Tried to set provisioning for "
4691 + "MmTel capability '" + capability + "', which does not require "
4692 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004693 }
4694 }
4695
4696 } finally {
4697 Binder.restoreCallingIdentity(identity);
4698 }
4699 }
4700
4701 @Override
4702 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4703 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004704 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4705 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4706 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004707 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4708 }
4709 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4710 final long identity = Binder.clearCallingIdentity();
4711 try {
4712 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004713 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004714 return true;
4715 }
4716
Brad Ebinger0d79c572021-04-17 15:20:49 -07004717 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4718 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4719 loge("getImsProvisioningStatusForCapability: called for technology that does "
4720 + "not support provisioning - " + tech);
4721 return true;
4722 }
4723
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004724 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4725 switch (capability) {
4726 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4727 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4728 return ims.isVolteProvisionedOnDevice();
4729 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4730 return ims.isWfcProvisionedOnDevice();
4731 }
4732 // This should never happen, since we are checking tech above to make sure it
4733 // is either LTE or IWLAN.
4734 throw new IllegalArgumentException("Invalid radio technology for voice "
4735 + "capability.");
4736 }
4737 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4738 // There is currently no difference in VT provisioning type.
4739 return ims.isVtProvisionedOnDevice();
4740 }
4741 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4742 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4743 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4744 }
4745 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004746 throw new IllegalArgumentException(
4747 "Tried to get provisioning for MmTel capability '" + capability
4748 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004749 }
4750 }
4751
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
4754 }
4755 }
4756
4757 @Override
4758 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4759 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4760 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4761 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4762 }
4763 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4764 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4765 return (provisionedBits & capability) > 0;
4766 }
4767
4768 @Override
4769 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4770 boolean isProvisioned) {
4771 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4772 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4773 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4774 }
4775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4776 "setProvisioningStatusForCapability");
4777 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4778 // If the current provisioning status for capability already matches isProvisioned,
4779 // do nothing.
4780 if (((provisionedBits & capability) > 0) == isProvisioned) {
4781 return;
4782 }
4783 if (isProvisioned) {
4784 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4785 } else {
4786 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4787 }
4788 }
4789
4790 /**
4791 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4792 * technology. The bitfield should mirror the bitfield defined by
4793 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4794 */
4795 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4796 String key = getMmTelProvisioningKey(subId, tech);
4797 // Default is no capabilities are provisioned.
4798 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4799 }
4800
4801 /**
4802 * Sets the MmTel capability provisioning bitfield (defined by
4803 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4804 * technology specified.
4805 *
4806 * Note: This is a synchronous command and should not be called on UI thread.
4807 */
4808 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4809 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4810 String key = getMmTelProvisioningKey(subId, tech);
4811 editor.putInt(key, newField);
4812 editor.commit();
4813 }
4814
4815 private static String getMmTelProvisioningKey(int subId, int tech) {
4816 // resulting key is provision_ims_mmtel_{subId}_{tech}
4817 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4818 }
4819
4820 /**
4821 * Query CarrierConfig to see if the specified capability requires provisioning for the
4822 * carrier associated with the subscription id.
4823 */
4824 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4825 int capability) {
4826 CarrierConfigManager configManager = new CarrierConfigManager(context);
4827 PersistableBundle c = configManager.getConfigForSubId(subId);
4828 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004829 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004830 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4831 false);
4832 boolean requireVoiceVtProvisioning = c.getBoolean(
4833 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4834
4835 // First check to make sure that the capability requires provisioning.
4836 switch (capability) {
4837 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4838 // intentional fallthrough
4839 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4840 if (requireVoiceVtProvisioning) {
4841 // Voice and Video requires provisioning
4842 return true;
4843 }
4844 break;
4845 }
4846 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4847 if (requireUtProvisioning) {
4848 // UT requires provisioning
4849 return true;
4850 }
4851 break;
4852 }
4853 }
4854 return false;
4855 }
4856
allenwtsu99c623b2020-01-03 18:24:23 +08004857 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4858 int capability) {
4859 CarrierConfigManager configManager = new CarrierConfigManager(context);
4860 PersistableBundle c = configManager.getConfigForSubId(subId);
4861
4862 boolean requireRcsProvisioning = c.getBoolean(
4863 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4864
4865 // First check to make sure that the capability requires provisioning.
4866 switch (capability) {
4867 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4868 // intentional fallthrough
4869 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4870 if (requireRcsProvisioning) {
4871 // OPTION or PRESENCE requires provisioning
4872 return true;
4873 }
4874 break;
4875 }
4876 }
4877 return false;
4878 }
4879
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004880 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004881 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004882 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4883 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4884 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004885 enforceReadPrivilegedPermission("getImsProvisioningInt");
4886 final long identity = Binder.clearCallingIdentity();
4887 try {
4888 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004889 int slotId = getSlotIndex(subId);
4890 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4891 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4892 + subId + "' for key:" + key);
4893 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4894 }
calvinpanb5a34062021-02-08 19:59:36 +08004895 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004896 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004897 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4898 + subId + "' for key:" + key);
4899 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004900 } finally {
4901 Binder.restoreCallingIdentity(identity);
4902 }
4903 }
4904
4905 @Override
4906 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004907 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4908 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4909 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004910 enforceReadPrivilegedPermission("getImsProvisioningString");
4911 final long identity = Binder.clearCallingIdentity();
4912 try {
4913 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004914 int slotId = getSlotIndex(subId);
4915 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4916 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4917 + subId + "' for key:" + key);
4918 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4919 }
calvinpanb5a34062021-02-08 19:59:36 +08004920 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004921 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004922 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4923 + subId + "' for key:" + key);
4924 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004925 } finally {
4926 Binder.restoreCallingIdentity(identity);
4927 }
4928 }
4929
4930 @Override
4931 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004932 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4933 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4934 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4936 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004937 final long identity = Binder.clearCallingIdentity();
4938 try {
4939 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004940 int slotId = getSlotIndex(subId);
4941 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4942 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4943 + subId + "' for key:" + key);
4944 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4945 }
calvinpanb5a34062021-02-08 19:59:36 +08004946 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4947 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004948 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004949 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004950 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004951 } finally {
4952 Binder.restoreCallingIdentity(identity);
4953 }
4954 }
4955
4956 @Override
4957 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004958 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4959 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4960 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4962 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004963 final long identity = Binder.clearCallingIdentity();
4964 try {
4965 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004966 int slotId = getSlotIndex(subId);
4967 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4968 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4969 + subId + "' for key:" + key);
4970 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4971 }
calvinpanb5a34062021-02-08 19:59:36 +08004972 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4973 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004974 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004975 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004976 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004977 } finally {
4978 Binder.restoreCallingIdentity(identity);
4979 }
4980 }
4981
Brad Ebinger919631e2021-06-02 17:46:35 -07004982 /**
4983 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4984 * for the given slot ID or no ImsResolver instance has been created.
4985 * @param slotId The slot ID that the IMS service is created for.
4986 * @throws ImsException If there is no ImsService configured for this slot.
4987 */
4988 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4989 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4990 ImsFeature.FEATURE_MMTEL)) {
4991 throw new ImsException("This subscription does not support MMTEL over IMS",
4992 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4993 }
4994 }
4995
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004996 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004997 int slotId = SubscriptionManager.getSlotIndex(subId);
4998 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004999 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5000 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005001 }
5002 return slotId;
5003 }
5004
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005005 private int getSlotIndex(int subId) {
5006 int slotId = SubscriptionManager.getSlotIndex(subId);
5007 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5008 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5009 }
5010 return slotId;
5011 }
5012
Wink Saville36469e72014-06-11 15:17:00 -07005013 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005014 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005015 */
5016 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005017 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5018 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005019 try {
5020 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5021 } catch (SecurityException se) {
5022 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5023 throw new SecurityException("Package " + callingPackage + " does not belong to "
5024 + Binder.getCallingUid());
5025 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005026 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005027 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005028 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005029 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005030 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005031 mApp, subId, callingPackage, callingFeatureId,
5032 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005033 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5034 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005035
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036 final long identity = Binder.clearCallingIdentity();
5037 try {
5038 final Phone phone = getPhone(subId);
5039 if (phone != null) {
5040 return phone.getServiceState().getDataNetworkType();
5041 } else {
5042 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5043 }
5044 } finally {
5045 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005046 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005047 }
5048
5049 /**
5050 * Returns the data network type
5051 */
5052 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005053 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005054 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5055 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005056 }
5057
5058 /**
5059 * Returns the data network type for a subId
5060 */
5061 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005062 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5063 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005065 mApp, subId, callingPackage, callingFeatureId,
5066 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005067 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5068 }
5069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070 final long identity = Binder.clearCallingIdentity();
5071 try {
5072 final Phone phone = getPhone(subId);
5073 if (phone != null) {
5074 return phone.getServiceState().getDataNetworkType();
5075 } else {
5076 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5077 }
5078 } finally {
5079 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005081 }
5082
5083 /**
Wink Saville36469e72014-06-11 15:17:00 -07005084 * Returns the Voice network type for a subId
5085 */
5086 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005087 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5088 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005089 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005090 mApp, subId, callingPackage, callingFeatureId,
5091 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005092 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5093 }
5094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 final long identity = Binder.clearCallingIdentity();
5096 try {
5097 final Phone phone = getPhone(subId);
5098 if (phone != null) {
5099 return phone.getServiceState().getVoiceNetworkType();
5100 } else {
5101 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5102 }
5103 } finally {
5104 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005106 }
5107
5108 /**
5109 * @return true if a ICC card is present
5110 */
5111 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005112 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005113 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5114 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005115 }
5116
5117 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005118 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005119 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005120 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005121 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005122 final long identity = Binder.clearCallingIdentity();
5123 try {
5124 final Phone phone = PhoneFactory.getPhone(slotIndex);
5125 if (phone != null) {
5126 return phone.getIccCard().hasIccCard();
5127 } else {
5128 return false;
5129 }
5130 } finally {
5131 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005132 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005133 }
5134
5135 /**
5136 * Return if the current radio is LTE on CDMA. This
5137 * is a tri-state return value as for a period of time
5138 * the mode may be unknown.
5139 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005140 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005141 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005142 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005143 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005144 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005145 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5146 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5147 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005148 }
5149
Sanket Padawe356d7632015-06-22 14:03:32 -07005150 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005151 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5152 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005153 try {
5154 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5155 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005156 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5157 }
5158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 final long identity = Binder.clearCallingIdentity();
5160 try {
5161 final Phone phone = getPhone(subId);
5162 if (phone == null) {
5163 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5164 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005165 return TelephonyProperties.lte_on_cdma_device()
5166 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167 }
5168 } finally {
5169 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005170 }
Wink Saville36469e72014-06-11 15:17:00 -07005171 }
5172
Wink Saville36469e72014-06-11 15:17:00 -07005173 /**
5174 * {@hide}
5175 * Returns Default subId, 0 in the case of single standby.
5176 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005177 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005178 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005179 }
5180
Shishir Agrawala9f32182016-04-12 12:00:16 -07005181 private int getSlotForDefaultSubscription() {
5182 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5183 }
5184
Wink Savilleb564aae2014-10-23 10:18:09 -07005185 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005186 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005187 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005188
Pengquan Menge92a50d2018-09-21 15:54:48 -07005189 private boolean isActiveSubscription(int subId) {
5190 return mSubscriptionController.isActiveSubId(subId);
5191 }
5192
Ihab Awadf2177b72013-11-25 13:33:23 -08005193 /**
5194 * @see android.telephony.TelephonyManager.WifiCallingChoices
5195 */
5196 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005197 final long identity = Binder.clearCallingIdentity();
5198 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005199 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005200 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5201 getWhenToMakeWifiCallsDefaultPreference());
5202 } finally {
5203 Binder.restoreCallingIdentity(identity);
5204 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005205 }
5206
5207 /**
5208 * @see android.telephony.TelephonyManager.WifiCallingChoices
5209 */
5210 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211 final long identity = Binder.clearCallingIdentity();
5212 try {
5213 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005214 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5216 } finally {
5217 Binder.restoreCallingIdentity(identity);
5218 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005219 }
5220
Sailesh Nepald1e68152013-12-12 19:08:02 -08005221 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005222 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005223 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005224 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005225
Jordan Liu4c733742019-02-28 12:03:40 -08005226 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5227 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5228 if (phoneId == -1) {
5229 throw new IllegalArgumentException("Given slot index: " + slotIndex
5230 + " does not correspond to an active phone");
5231 }
5232 return PhoneFactory.getPhone(phoneId);
5233 }
5234
Shishir Agrawal566b7612013-10-28 14:41:00 -07005235 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005236 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5237 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5239 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005240 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005241 if (DBG) {
5242 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5243 }
5244 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5245 p2);
5246 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005247
Jordan Liu4c733742019-02-28 12:03:40 -08005248
5249 @Override
5250 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5251 int slotIndex, String callingPackage, String aid, int p2) {
5252 enforceModifyPermission();
5253 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5254 if (DBG) {
5255 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5256 }
5257 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5258 callingPackage, aid, p2);
5259 }
5260
5261 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5262 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 final long identity = Binder.clearCallingIdentity();
5264 try {
5265 if (TextUtils.equals(ISDR_AID, aid)) {
5266 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005267 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5268 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 if (bestComponent == null
5270 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5271 loge("The calling package is not allowed to access ISD-R.");
5272 throw new SecurityException(
5273 "The calling package is not allowed to access ISD-R.");
5274 }
Derek Tan740e1672017-06-27 14:56:27 -07005275 }
Derek Tan740e1672017-06-27 14:56:27 -07005276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005277 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005278 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5279 null /* workSource */);
5280 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 return response;
5282 } finally {
5283 Binder.restoreCallingIdentity(identity);
5284 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005285 }
5286
5287 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005288 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5290 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005291 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5292 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5293 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005294
Jordan Liu4c733742019-02-28 12:03:40 -08005295 @Override
5296 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5297 enforceModifyPermission();
5298 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5299 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5300 channel);
5301 }
5302
5303 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005304 final long identity = Binder.clearCallingIdentity();
5305 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005306 if (channel < 0) {
5307 return false;
5308 }
Jordan Liu4c733742019-02-28 12:03:40 -08005309 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5310 null /* workSource */);
5311 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312 return success;
5313 } finally {
5314 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005315 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005316 }
5317
5318 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005319 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005320 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5322 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005323 if (DBG) {
5324 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5325 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5326 + p3 + " data=" + data);
5327 }
5328 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5329 command, p1, p2, p3, data);
5330 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005331
Jordan Liu4c733742019-02-28 12:03:40 -08005332 @Override
5333 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5334 int command, int p1, int p2, int p3, String data) {
5335 enforceModifyPermission();
5336 if (DBG) {
5337 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5338 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5339 + p3 + " data=" + data);
5340 }
5341 return iccTransmitApduLogicalChannelWithPermission(
5342 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5343 data);
5344 }
5345
5346 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5347 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 final long identity = Binder.clearCallingIdentity();
5349 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005350 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351 return "";
5352 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005355 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5356 null /* workSource */);
5357 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 // Append the returned status code to the end of the response payload.
5360 String s = Integer.toHexString(
5361 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5362 if (response.payload != null) {
5363 s = IccUtils.bytesToHexString(response.payload) + s;
5364 }
5365 return s;
5366 } finally {
5367 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005368 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005369 }
Jake Hambye994d462014-02-03 13:10:13 -08005370
Evan Charltonc66da362014-05-16 14:06:40 -07005371 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005372 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5373 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5375 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005377 if (DBG) {
5378 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5379 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5380 }
5381 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5382 cla, command, p1, p2, p3, data);
5383 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005384
Jordan Liu4c733742019-02-28 12:03:40 -08005385 @Override
5386 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5387 int command, int p1, int p2, int p3, String data) {
5388 enforceModifyPermission();
5389 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5390 if (DBG) {
5391 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5392 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5393 + " data=" + data);
5394 }
5395
5396 return iccTransmitApduBasicChannelWithPermission(
5397 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5398 p2, p3, data);
5399 }
5400
5401 // open APDU basic channel assuming the caller has sufficient permissions
5402 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5403 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 final long identity = Binder.clearCallingIdentity();
5405 try {
5406 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5407 && TextUtils.equals(ISDR_AID, data)) {
5408 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005409 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5410 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 if (bestComponent == null
5412 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5413 loge("The calling package is not allowed to select ISD-R.");
5414 throw new SecurityException(
5415 "The calling package is not allowed to select ISD-R.");
5416 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005417 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005420 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5421 null /* workSource */);
5422 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 // Append the returned status code to the end of the response payload.
5425 String s = Integer.toHexString(
5426 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5427 if (response.payload != null) {
5428 s = IccUtils.bytesToHexString(response.payload) + s;
5429 }
5430 return s;
5431 } finally {
5432 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005433 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005434 }
5435
5436 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005437 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005438 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5440 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442 final long identity = Binder.clearCallingIdentity();
5443 try {
5444 if (DBG) {
5445 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5446 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5447 }
5448
5449 IccIoResult response =
5450 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5451 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5452 subId);
5453
5454 if (DBG) {
5455 log("Exchange SIM_IO [R]" + response);
5456 }
5457
5458 byte[] result = null;
5459 int length = 2;
5460 if (response.payload != null) {
5461 length = 2 + response.payload.length;
5462 result = new byte[length];
5463 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5464 } else {
5465 result = new byte[length];
5466 }
5467
5468 result[length - 1] = (byte) response.sw2;
5469 result[length - 2] = (byte) response.sw1;
5470 return result;
5471 } finally {
5472 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005473 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005474 }
5475
Nathan Haroldb3014052017-01-25 15:57:32 -08005476 /**
5477 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5478 * on a particular subscription
5479 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005480 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5481 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005482 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005483 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005484 return null;
5485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486
5487 final long identity = Binder.clearCallingIdentity();
5488 try {
5489 if (appType != TelephonyManager.APPTYPE_USIM
5490 && appType != TelephonyManager.APPTYPE_SIM) {
5491 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5492 return null;
5493 }
5494 Object response = sendRequest(
5495 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5496 if (response instanceof String[]) {
5497 return (String[]) response;
5498 }
yincheng zhao2737e882019-09-06 17:06:54 -07005499 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005501 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 } finally {
5503 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005504 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005505 }
5506
yincheng zhao2737e882019-09-06 17:06:54 -07005507 /**
5508 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5509 * subscription.
5510 *
5511 * @param subId the id of the subscription.
5512 * @param appType the uicc app type, must be USIM or SIM.
5513 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5514 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005515 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005516 * @return number of fplmns that is successfully written to the SIM.
5517 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005518 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5519 String callingFeatureId) {
5520 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5521 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005522 if (DBG) logv("no permissions for setForbiddenplmns");
5523 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5524 }
5525 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5526 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5527 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5528 }
5529 if (fplmns == null) {
5530 throw new IllegalArgumentException("Fplmn List provided is null");
5531 }
5532 for (String fplmn : fplmns) {
5533 if (!CellIdentity.isValidPlmn(fplmn)) {
5534 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5535 }
5536 }
5537 final long identity = Binder.clearCallingIdentity();
5538 try {
5539 Object response = sendRequest(
5540 CMD_SET_FORBIDDEN_PLMNS,
5541 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5542 subId);
5543 return (int) response;
5544 } finally {
5545 Binder.restoreCallingIdentity(identity);
5546 }
5547 }
5548
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005549 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005550 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5552 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554 final long identity = Binder.clearCallingIdentity();
5555 try {
5556 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5557 if (response.payload == null) {
5558 return "";
5559 }
Evan Charltonc66da362014-05-16 14:06:40 -07005560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561 // Append the returned status code to the end of the response payload.
5562 String s = Integer.toHexString(
5563 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5564 s = IccUtils.bytesToHexString(response.payload) + s;
5565 return s;
5566 } finally {
5567 Binder.restoreCallingIdentity(identity);
5568 }
Evan Charltonc66da362014-05-16 14:06:40 -07005569 }
5570
Jake Hambye994d462014-02-03 13:10:13 -08005571 /**
5572 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5573 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5574 *
5575 * @param itemID the ID of the item to read
5576 * @return the NV item as a String, or null on error.
5577 */
5578 @Override
5579 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005580 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5582 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583
5584 final long identity = Binder.clearCallingIdentity();
5585 try {
5586 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005587 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5589 return value;
5590 } finally {
5591 Binder.restoreCallingIdentity(identity);
5592 }
Jake Hambye994d462014-02-03 13:10:13 -08005593 }
5594
5595 /**
5596 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5597 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5598 *
5599 * @param itemID the ID of the item to read
5600 * @param itemValue the value to write, as a String
5601 * @return true on success; false on any failure
5602 */
5603 @Override
5604 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005605 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5607 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608
5609 final long identity = Binder.clearCallingIdentity();
5610 try {
5611 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5612 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005613 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5615 return success;
5616 } finally {
5617 Binder.restoreCallingIdentity(identity);
5618 }
Jake Hambye994d462014-02-03 13:10:13 -08005619 }
5620
5621 /**
5622 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5623 * Used for device configuration by some CDMA operators.
5624 *
5625 * @param preferredRoamingList byte array containing the new PRL
5626 * @return true on success; false on any failure
5627 */
5628 @Override
5629 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5631 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005632
5633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5636 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5637 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5638 return success;
5639 } finally {
5640 Binder.restoreCallingIdentity(identity);
5641 }
Jake Hambye994d462014-02-03 13:10:13 -08005642 }
5643
5644 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005645 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005646 * Used for device configuration by some CDMA operators.
5647 *
chen xu6dac5ab2018-10-26 17:39:23 -07005648 * @param slotIndex - device slot.
5649 *
Jake Hambye994d462014-02-03 13:10:13 -08005650 * @return true on success; false on any failure
5651 */
5652 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005653 public boolean resetModemConfig(int slotIndex) {
5654 Phone phone = PhoneFactory.getPhone(slotIndex);
5655 if (phone != null) {
5656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5657 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658
chen xu6dac5ab2018-10-26 17:39:23 -07005659 final long identity = Binder.clearCallingIdentity();
5660 try {
5661 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5662 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5663 return success;
5664 } finally {
5665 Binder.restoreCallingIdentity(identity);
5666 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 }
chen xu6dac5ab2018-10-26 17:39:23 -07005668 return false;
5669 }
5670
5671 /**
5672 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5673 *
5674 * @param slotIndex - device slot.
5675 *
5676 * @return true on success; false on any failure
5677 */
5678 @Override
5679 public boolean rebootModem(int slotIndex) {
5680 Phone phone = PhoneFactory.getPhone(slotIndex);
5681 if (phone != null) {
5682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5683 mApp, phone.getSubId(), "rebootModem");
5684
5685 final long identity = Binder.clearCallingIdentity();
5686 try {
5687 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5688 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5689 return success;
5690 } finally {
5691 Binder.restoreCallingIdentity(identity);
5692 }
5693 }
5694 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005695 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005696
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005697 public String[] getPcscfAddress(String apnType, String callingPackage,
5698 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005699 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5701 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005702 return new String[0];
5703 }
5704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 final long identity = Binder.clearCallingIdentity();
5706 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005707 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
Wink Saville36469e72014-06-11 15:17:00 -07005711 }
5712
Brad Ebinger51f743a2017-01-23 13:50:20 -08005713 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005714 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5715 * {@link #disableIms(int)}.
5716 * @param slotIndex device slot.
5717 */
5718 public void resetIms(int slotIndex) {
5719 enforceModifyPermission();
5720
5721 final long identity = Binder.clearCallingIdentity();
5722 try {
5723 if (mImsResolver == null) {
5724 // may happen if the does not support IMS.
5725 return;
5726 }
5727 mImsResolver.disableIms(slotIndex);
5728 mImsResolver.enableIms(slotIndex);
5729 } finally {
5730 Binder.restoreCallingIdentity(identity);
5731 }
5732 }
5733
5734 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005735 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5736 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005737 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005738 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005739 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740
5741 final long identity = Binder.clearCallingIdentity();
5742 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005743 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005744 // may happen if the device does not support IMS.
5745 return;
5746 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005747 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748 } finally {
5749 Binder.restoreCallingIdentity(identity);
5750 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005751 }
5752
5753 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005754 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5755 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005756 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005757 public void disableIms(int slotId) {
5758 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005759
5760 final long identity = Binder.clearCallingIdentity();
5761 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005762 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005763 // may happen if the device does not support IMS.
5764 return;
5765 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005766 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767 } finally {
5768 Binder.restoreCallingIdentity(identity);
5769 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005770 }
5771
5772 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005773 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5774 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005775 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005776 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005777 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005778 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005779
5780 final long identity = Binder.clearCallingIdentity();
5781 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005782 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005783 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5784 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005785 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005786 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 } finally {
5788 Binder.restoreCallingIdentity(identity);
5789 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005790 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005791 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005792 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5793 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005794 @Override
5795 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005796 enforceModifyPermission();
5797
5798 final long identity = Binder.clearCallingIdentity();
5799 try {
5800 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005801 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005802 } finally {
5803 Binder.restoreCallingIdentity(identity);
5804 }
5805 }
5806
5807 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005808 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005809 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005810 */
5811 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5812 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813
5814 final long identity = Binder.clearCallingIdentity();
5815 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005816 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005817 // may happen if the device does not support IMS.
5818 return null;
5819 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005820 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005821 } finally {
5822 Binder.restoreCallingIdentity(identity);
5823 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005824 }
5825
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005826 /**
5827 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005828 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005829 */
5830 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5831 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832
5833 final long identity = Binder.clearCallingIdentity();
5834 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005835 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005836 // may happen if the device does not support IMS.
5837 return null;
5838 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005839 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005840 } finally {
5841 Binder.restoreCallingIdentity(identity);
5842 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005843 }
5844
Brad Ebinger884c07b2018-02-15 16:17:40 -08005845 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005846 * Sets the ImsService Package Name that Telephony will bind to.
5847 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005848 * @param slotIndex the slot ID that the ImsService should bind for.
5849 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005850 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005851 * @param featureTypes An integer array of feature types associated with a packageName.
5852 * @param packageName The name of the package that the current configuration will be replaced
5853 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005854 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005855 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005856 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5857 int[] featureTypes, String packageName) {
5858 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5859 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5861 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005862 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005863
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005864 final long identity = Binder.clearCallingIdentity();
5865 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005866 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005867 // may happen if the device does not support IMS.
5868 return false;
5869 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005870 Map<Integer, String> featureConfig = new HashMap<>();
5871 for (int featureType : featureTypes) {
5872 featureConfig.put(featureType, packageName);
5873 }
5874 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5875 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005876 } finally {
5877 Binder.restoreCallingIdentity(identity);
5878 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005879 }
5880
5881 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005882 * Clears any carrier ImsService overrides for the slot index specified that were previously
5883 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5884 *
5885 * This should only be used for testing.
5886 *
5887 * @param slotIndex the slot ID that the ImsService should bind for.
5888 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5889 */
5890 @Override
5891 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5892 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5893 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5894 "clearCarrierImsServiceOverride");
5895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5896 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5897 "clearCarrierImsServiceOverride");
5898
5899 final long identity = Binder.clearCallingIdentity();
5900 try {
5901 if (mImsResolver == null) {
5902 // may happen if the device does not support IMS.
5903 return false;
5904 }
5905 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5906 } finally {
5907 Binder.restoreCallingIdentity(identity);
5908 }
5909 }
5910
5911 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005912 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005913 *
5914 * @param slotId The slot that the ImsService is associated with.
5915 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5916 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005917 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005918 * @return the package name of the ImsService configuration.
5919 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005920 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5921 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005922 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005923 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005924 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005925 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5926 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928 final long identity = Binder.clearCallingIdentity();
5929 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005930 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005931 // may happen if the device does not support IMS.
5932 return "";
5933 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005934 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005935 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5936 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005940 }
5941
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005942 /**
5943 * Get the MmTelFeature state associated with the requested subscription id.
5944 * @param subId The subscription that the MmTelFeature is associated with.
5945 * @param callback A callback with an integer containing the
5946 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5947 */
5948 @Override
5949 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5950 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5951 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5952 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5953 "IMS not available on device.");
5954 }
5955 final long token = Binder.clearCallingIdentity();
5956 try {
5957 int slotId = getSlotIndex(subId);
5958 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5959 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5960 + subId + "'");
5961 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5962 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005963 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005964 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5965 try {
5966 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5967 } catch (RemoteException e) {
5968 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5969 + "Ignore");
5970 }
5971 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005972 } catch (ImsException e) {
5973 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005974 } finally {
5975 Binder.restoreCallingIdentity(token);
5976 }
5977 }
5978
Daniel Brightbb5840b2021-01-12 15:48:18 -08005979 /**
5980 * Sets the ims registration state on all valid {@link Phone}s.
5981 */
5982 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005983 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984
5985 final long identity = Binder.clearCallingIdentity();
5986 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005987 // NOTE: Before S, this method only set the default phone.
5988 for (final Phone phone : PhoneFactory.getPhones()) {
5989 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5990 phone.setImsRegistrationState(registered);
5991 }
5992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 } finally {
5994 Binder.restoreCallingIdentity(identity);
5995 }
Wink Saville36469e72014-06-11 15:17:00 -07005996 }
5997
5998 /**
Stuart Scott54788802015-03-30 13:18:01 -07005999 * Set the network selection mode to automatic.
6000 *
6001 */
6002 @Override
6003 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6005 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006
6007 final long identity = Binder.clearCallingIdentity();
6008 try {
shilufc958392020-01-20 11:36:01 -08006009 if (!isActiveSubscription(subId)) {
6010 return;
6011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006013 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6014 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 } finally {
6016 Binder.restoreCallingIdentity(identity);
6017 }
Stuart Scott54788802015-03-30 13:18:01 -07006018 }
6019
Jack Yud10cdd42020-09-28 20:28:01 -07006020 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006021 * Ask the radio to connect to the input network and change selection mode to manual.
6022 *
6023 * @param subId the id of the subscription.
6024 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6025 * the operator to attach to.
6026 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6027 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6028 * normal network selection next time.
6029 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006030 */
6031 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006032 public boolean setNetworkSelectionModeManual(
6033 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6035 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006036
6037 if (!isActiveSubscription(subId)) {
6038 return false;
6039 }
6040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 final long identity = Binder.clearCallingIdentity();
6042 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006043 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006045 if (DBG) {
6046 log("setNetworkSelectionModeManual: subId: " + subId
6047 + " operator: " + operatorInfo);
6048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6050 } finally {
6051 Binder.restoreCallingIdentity(identity);
6052 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006053 }
shilu84f6e8b2019-12-19 13:58:01 -08006054 /**
6055 * Get the manual network selection
6056 *
6057 * @param subId the id of the subscription.
6058 *
6059 * @return the previously saved user selected PLMN
6060 */
6061 @Override
6062 public String getManualNetworkSelectionPlmn(int subId) {
6063 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006064 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006065 mApp, subId, "getManualNetworkSelectionPlmn");
6066
6067 final long identity = Binder.clearCallingIdentity();
6068 try {
6069 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006070 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006071 }
6072
6073 final Phone phone = getPhone(subId);
6074 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006075 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006076 }
6077 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6078 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6079 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6080 } finally {
6081 Binder.restoreCallingIdentity(identity);
6082 }
6083 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006084
6085 /**
6086 * Scans for available networks.
6087 */
6088 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006089 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6090 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6092 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006093 LocationAccessPolicy.LocationPermissionResult locationResult =
6094 LocationAccessPolicy.checkLocationPermission(mApp,
6095 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6096 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006097 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006098 .setCallingPid(Binder.getCallingPid())
6099 .setCallingUid(Binder.getCallingUid())
6100 .setMethod("getCellNetworkScanResults")
6101 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006102 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6103 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006104 .build());
6105 switch (locationResult) {
6106 case DENIED_HARD:
6107 throw new SecurityException("Not allowed to access scan results -- location");
6108 case DENIED_SOFT:
6109 return null;
6110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111
Pengquan Menga1bb6272018-09-06 09:59:22 -07006112 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 try {
6114 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006115 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 } finally {
6118 Binder.restoreCallingIdentity(identity);
6119 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006120 }
6121
6122 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006123 * Get the call forwarding info, given the call forwarding reason.
6124 */
6125 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006126 public void getCallForwarding(int subId, int callForwardingReason,
6127 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006128 enforceReadPrivilegedPermission("getCallForwarding");
6129 long identity = Binder.clearCallingIdentity();
6130 try {
6131 if (DBG) {
6132 log("getCallForwarding: subId " + subId
6133 + " callForwardingReason" + callForwardingReason);
6134 }
Hall Liu27d24262020-09-18 19:04:59 -07006135
6136 Phone phone = getPhone(subId);
6137 if (phone == null) {
6138 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006139 callback.onError(
6140 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006141 } catch (RemoteException e) {
6142 // ignore
6143 }
6144 return;
6145 }
6146
6147 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6148 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6149 @Override
6150 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6151 try {
6152 callback.onCallForwardingInfoAvailable(info);
6153 } catch (RemoteException e) {
6154 // ignore
6155 }
6156 }
6157
6158 @Override
6159 public void onError(int error) {
6160 try {
6161 callback.onError(error);
6162 } catch (RemoteException e) {
6163 // ignore
6164 }
6165 }
6166 });
6167 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006168 } finally {
6169 Binder.restoreCallingIdentity(identity);
6170 }
6171 }
6172
6173 /**
6174 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6175 * reason, the number to forward, and the timeout before the forwarding is attempted.
6176 */
6177 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006178 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6179 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006180 enforceModifyPermission();
6181 long identity = Binder.clearCallingIdentity();
6182 try {
6183 if (DBG) {
6184 log("setCallForwarding: subId " + subId
6185 + " callForwardingInfo" + callForwardingInfo);
6186 }
Hall Liu27d24262020-09-18 19:04:59 -07006187
6188 Phone phone = getPhone(subId);
6189 if (phone == null) {
6190 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006191 callback.accept(
6192 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006193 } catch (RemoteException e) {
6194 // ignore
6195 }
6196 return;
6197 }
6198
6199 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6200 FunctionalUtils.ignoreRemoteException(callback::accept));
6201
6202 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
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 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006210 */
6211 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006212 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006213 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006214 long identity = Binder.clearCallingIdentity();
6215 try {
Hall Liu27d24262020-09-18 19:04:59 -07006216 Phone phone = getPhone(subId);
6217 if (phone == null) {
6218 try {
6219 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6220 } catch (RemoteException e) {
6221 // ignore
6222 }
6223 return;
6224 }
SongFerngWang0e767992021-03-31 22:08:45 +08006225 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6226 PersistableBundle c = configManager.getConfigForSubId(subId);
6227 boolean requireUssd = c.getBoolean(
6228 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006229
Shuo Qian4a594052020-01-23 11:59:30 -08006230 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006231 if (requireUssd) {
6232 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6233 getSubscriptionCarrierId(subId));
6234 String newUssdCommand = "";
6235 try {
6236 newUssdCommand = carrierXmlParser.getFeature(
6237 CarrierXmlParser.FEATURE_CALL_WAITING)
6238 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6239 } catch (NullPointerException e) {
6240 loge("Failed to generate USSD number" + e);
6241 }
6242 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6243 mMainThreadHandler, callback, carrierXmlParser,
6244 CarrierXmlParser.SsEntry.SSAction.QUERY);
6245 final String ussdCommand = newUssdCommand;
6246 Executors.newSingleThreadExecutor().execute(() -> {
6247 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6248 });
6249 } else {
6250 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6251 callback::accept);
6252 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6253 }
Shuo Qian4a594052020-01-23 11:59:30 -08006254 } finally {
6255 Binder.restoreCallingIdentity(identity);
6256 }
6257 }
6258
6259 /**
Hall Liu27d24262020-09-18 19:04:59 -07006260 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006261 */
6262 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006263 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006264 enforceModifyPermission();
6265 long identity = Binder.clearCallingIdentity();
6266 try {
Hall Liu27d24262020-09-18 19:04:59 -07006267 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6268
6269 Phone phone = getPhone(subId);
6270 if (phone == null) {
6271 try {
6272 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6273 } catch (RemoteException e) {
6274 // ignore
6275 }
6276 return;
6277 }
6278
SongFerngWang0e767992021-03-31 22:08:45 +08006279 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6280 PersistableBundle c = configManager.getConfigForSubId(subId);
6281 boolean requireUssd = c.getBoolean(
6282 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006283
SongFerngWang0e767992021-03-31 22:08:45 +08006284 if (DBG) log("getCallWaitingStatus: subId " + subId);
6285 if (requireUssd) {
6286 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6287 getSubscriptionCarrierId(subId));
6288 CarrierXmlParser.SsEntry.SSAction ssAction =
6289 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6290 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6291 String newUssdCommand = "";
6292 try {
6293 newUssdCommand = carrierXmlParser.getFeature(
6294 CarrierXmlParser.FEATURE_CALL_WAITING)
6295 .makeCommand(ssAction, null);
6296 } catch (NullPointerException e) {
6297 loge("Failed to generate USSD number" + e);
6298 }
6299 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6300 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6301 final String ussdCommand = newUssdCommand;
6302 Executors.newSingleThreadExecutor().execute(() -> {
6303 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6304 });
6305 } else {
6306 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6307 FunctionalUtils.ignoreRemoteException(callback::accept));
6308
6309 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6310 }
Shuo Qian4a594052020-01-23 11:59:30 -08006311 } finally {
6312 Binder.restoreCallingIdentity(identity);
6313 }
6314 }
6315
6316 /**
yinxub1bed742017-04-17 11:45:04 -07006317 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006318 *
yinxub1bed742017-04-17 11:45:04 -07006319 * @param subId id of the subscription
6320 * @param request contains the radio access networks with bands/channels to scan
6321 * @param messenger callback messenger for scan results or errors
6322 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006323 * @return the id of the requested scan which can be used to stop the scan.
6324 */
6325 @Override
6326 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006327 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6329 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006330 LocationAccessPolicy.LocationPermissionResult locationResult =
6331 LocationAccessPolicy.checkLocationPermission(mApp,
6332 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6333 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006334 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006335 .setCallingPid(Binder.getCallingPid())
6336 .setCallingUid(Binder.getCallingUid())
6337 .setMethod("requestNetworkScan")
6338 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006339 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6340 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006341 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006342 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006343 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6344 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006345 if (e != null) {
6346 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6347 throw e;
6348 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006349 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006350 return TelephonyScanManager.INVALID_SCAN_ID;
6351 }
6352 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 }
Hall Liu912dfd32019-04-25 14:02:26 -07006354 int callingUid = Binder.getCallingUid();
6355 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006356 final long identity = Binder.clearCallingIdentity();
6357 try {
6358 return mNetworkScanRequestTracker.startNetworkScan(
6359 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006360 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006361 } finally {
6362 Binder.restoreCallingIdentity(identity);
6363 }
yinxu504e1392017-04-12 16:03:22 -07006364 }
6365
Hall Liub2ac8ef2019-02-28 15:56:23 -08006366 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006367 NetworkScanRequest request, int subId, String callingPackage) {
6368 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006369 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6370 boolean hasNetworkScanPermission =
6371 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6372 == PERMISSION_GRANTED;
6373
6374 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6375 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6376 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006377 }
6378
6379 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6380 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006381 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6382 return new SecurityException("Specific channels must not be"
6383 + " scanned without location access.");
6384 }
6385 }
6386 }
6387
Hall Liub2ac8ef2019-02-28 15:56:23 -08006388 return null;
6389 }
6390
yinxu504e1392017-04-12 16:03:22 -07006391 /**
6392 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006393 *
6394 * @param subId id of the subscription
6395 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006396 */
6397 @Override
6398 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6400 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401
Hall Liu912dfd32019-04-25 14:02:26 -07006402 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403 final long identity = Binder.clearCallingIdentity();
6404 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006405 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406 } finally {
6407 Binder.restoreCallingIdentity(identity);
6408 }
yinxu504e1392017-04-12 16:03:22 -07006409 }
6410
6411 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006412 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006413 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006414 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006415 */
6416 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006417 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006418 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006419 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006420 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421
6422 final long identity = Binder.clearCallingIdentity();
6423 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006424 if (DBG) log("getAllowedNetworkTypesBitmask");
6425 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6426 int networkTypesBitmask = (result != null ? result[0] : -1);
6427 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6428 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429 } finally {
6430 Binder.restoreCallingIdentity(identity);
6431 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006432 }
6433
6434 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006435 * Get the allowed network types for certain reason.
6436 *
6437 * @param subId the id of the subscription.
6438 * @param reason the reason the allowed network type change is taking place
6439 * @return the allowed network types.
6440 */
6441 @Override
6442 public long getAllowedNetworkTypesForReason(int subId,
6443 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006444 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006445 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006446 final long identity = Binder.clearCallingIdentity();
6447 try {
6448 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6449 } finally {
6450 Binder.restoreCallingIdentity(identity);
6451 }
6452 }
6453
6454 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006455 * Enable/Disable E-UTRA-NR Dual Connectivity
6456 * @param subId subscription id of the sim card
6457 * @param nrDualConnectivityState expected NR dual connectivity state
6458 * This can be passed following states
6459 * <ol>
6460 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6461 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6462 * <li>Disable NR dual connectivity and force secondary cell to be released
6463 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6464 * </ol>
6465 * @return operation result.
6466 */
6467 @Override
6468 public int setNrDualConnectivityState(int subId,
6469 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6471 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006472 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006473 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6474 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6475 }
6476
Sooraj Sasindran37444802020-08-11 10:40:43 -07006477 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6478 final long identity = Binder.clearCallingIdentity();
6479 try {
6480 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6481 nrDualConnectivityState, subId,
6482 workSource);
6483 if (DBG) log("enableNRDualConnectivity result: " + result);
6484 return result;
6485 } finally {
6486 Binder.restoreCallingIdentity(identity);
6487 }
6488 }
6489
6490 /**
6491 * Is E-UTRA-NR Dual Connectivity enabled
6492 * @return true if dual connectivity is enabled else false
6493 */
6494 @Override
6495 public boolean isNrDualConnectivityEnabled(int subId) {
6496 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006497 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006498 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006499 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006500 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6501 return false;
6502 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006503 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6504 final long identity = Binder.clearCallingIdentity();
6505 try {
6506 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6507 null, subId, workSource);
6508 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6509 return isEnabled;
6510 } finally {
6511 Binder.restoreCallingIdentity(identity);
6512 }
6513 }
6514
6515 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006516 * Set the allowed network types of the device and
6517 * provide the reason triggering the allowed network change.
6518 *
6519 * @param subId the id of the subscription.
6520 * @param reason the reason the allowed network type change is taking place
6521 * @param allowedNetworkTypes the allowed network types.
6522 * @return true on success; false on any failure.
6523 */
6524 @Override
6525 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006526 @TelephonyManager.AllowedNetworkTypesReason int reason,
6527 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6529 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006530 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006531 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6532 return false;
6533 }
6534 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6535 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006536 return false;
6537 }
6538
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006539 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6540 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6541
6542
6543 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6544 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6545 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006546 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006547
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006548 final long identity = Binder.clearCallingIdentity();
6549 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006550 Boolean success = (Boolean) sendRequest(
6551 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6552 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6553
6554 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6555 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006556 } finally {
6557 Binder.restoreCallingIdentity(identity);
6558 }
6559 }
6560
6561 /**
Miaoa84611c2019-03-15 09:21:10 +08006562 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006563 *
Miaoa84611c2019-03-15 09:21:10 +08006564 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006565 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006566 * @hide
6567 */
6568 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006569 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006570 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006571 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006572 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573 try {
Miaoa84611c2019-03-15 09:21:10 +08006574 if (phone != null) {
6575 return phone.hasMatchedTetherApnSetting();
6576 } else {
6577 return false;
6578 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006579 } finally {
6580 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006581 }
Junda Liu475951f2014-11-07 16:45:03 -08006582 }
6583
6584 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006585 * Enable or disable always reporting signal strength changes from radio.
6586 *
6587 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6588 */
6589 @Override
6590 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6591 enforceModifyPermission();
6592 enforceSystemCaller();
6593
6594 final long identity = Binder.clearCallingIdentity();
6595 final Phone phone = getPhone(subId);
6596 try {
6597 if (phone != null) {
6598 if (DBG) {
6599 log("setAlwaysReportSignalStrength: subId=" + subId
6600 + " isEnable=" + isEnable);
6601 }
6602 phone.setAlwaysReportSignalStrength(isEnable);
6603 } else {
6604 loge("setAlwaysReportSignalStrength: no phone found for subId="
6605 + subId);
6606 }
6607 } finally {
6608 Binder.restoreCallingIdentity(identity);
6609 }
6610 }
6611
6612 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006613 * Get the user enabled state of Mobile Data.
6614 *
6615 * TODO: remove and use isUserDataEnabled.
6616 * This can't be removed now because some vendor codes
6617 * calls through ITelephony directly while they should
6618 * use TelephonyManager.
6619 *
6620 * @return true on enabled
6621 */
6622 @Override
6623 public boolean getDataEnabled(int subId) {
6624 return isUserDataEnabled(subId);
6625 }
6626
6627 /**
6628 * Get whether mobile data is enabled per user setting.
6629 *
6630 * There are other factors deciding whether mobile data is actually enabled, but they are
6631 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006632 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006633 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006634 *
6635 * @return {@code true} if data is enabled else {@code false}
6636 */
6637 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006638 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006639 try {
6640 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6641 null);
6642 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6644 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006645 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006646
6647 final long identity = Binder.clearCallingIdentity();
6648 try {
6649 int phoneId = mSubscriptionController.getPhoneId(subId);
6650 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6651 Phone phone = PhoneFactory.getPhone(phoneId);
6652 if (phone != null) {
6653 boolean retVal = phone.isUserDataEnabled();
6654 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6655 return retVal;
6656 } else {
6657 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6658 return false;
6659 }
6660 } finally {
6661 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006662 }
6663 }
6664
6665 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006666 * Checks if the device is capable of mobile data by considering whether whether the
6667 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6668 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006669 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006670 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006671 */
6672 @Override
6673 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006674 try {
6675 try {
6676 mApp.enforceCallingOrSelfPermission(
6677 android.Manifest.permission.ACCESS_NETWORK_STATE,
6678 null);
6679 } catch (Exception e) {
6680 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6681 "isDataEnabled");
6682 }
6683 } catch (Exception e) {
6684 enforceReadPrivilegedPermission("isDataEnabled");
6685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006686
6687 final long identity = Binder.clearCallingIdentity();
6688 try {
6689 int phoneId = mSubscriptionController.getPhoneId(subId);
6690 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6691 Phone phone = PhoneFactory.getPhone(phoneId);
6692 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006693 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6695 return retVal;
6696 } else {
6697 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6698 return false;
6699 }
6700 } finally {
6701 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006702 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006703 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006704
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006705 /**
6706 * Check if data is enabled for a specific reason
6707 * @param subId Subscription index
6708 * @param reason the reason the data enable change is taking place
6709 * @return {@code true} if the overall data is enabled; {@code false} if not.
6710 */
6711 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006712 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006713 @TelephonyManager.DataEnabledReason int reason) {
6714 try {
6715 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6716 null);
6717 } catch (Exception e) {
6718 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006719 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006720 }
6721
6722
6723 final long identity = Binder.clearCallingIdentity();
6724 try {
6725 int phoneId = mSubscriptionController.getPhoneId(subId);
6726 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006727 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006728 + " reason=" + reason);
6729 }
6730 Phone phone = PhoneFactory.getPhone(phoneId);
6731 if (phone != null) {
6732 boolean retVal;
6733 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6734 retVal = phone.isUserDataEnabled();
6735 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006736 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006737 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006738 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006739 return retVal;
6740 } else {
6741 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006742 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006743 + subId + " retVal=false");
6744 }
6745 return false;
6746 }
6747 } finally {
6748 Binder.restoreCallingIdentity(identity);
6749 }
6750 }
6751
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006752 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006753 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006754 if (uid == Process.PHONE_UID) {
6755 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6756 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006757 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6758 }
6759
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006760 //load access rules from carrier configs, and check those as well: b/139133814
6761 SubscriptionController subController = SubscriptionController.getInstance();
6762 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6763 || subController == null) return privilegeFromSim;
6764
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006765 PackageManager pkgMgr = phone.getContext().getPackageManager();
6766 String[] packages = pkgMgr.getPackagesForUid(uid);
6767
6768 final long identity = Binder.clearCallingIdentity();
6769 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006770 int subId = phone.getSubId();
6771 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6772 // A test override is in place for the privileges for this subId, so don't try to
6773 // read the subscription privileges.
6774 return privilegeFromSim;
6775 }
6776 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006777 SubscriptionManager subManager = (SubscriptionManager)
6778 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6779 for (String pkg : packages) {
6780 if (subManager.canManageSubscription(subInfo, pkg)) {
6781 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6782 }
6783 }
6784 return privilegeFromSim;
6785 } finally {
6786 Binder.restoreCallingIdentity(identity);
6787 }
6788 }
6789
6790 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6791 String pkgName) {
6792 //load access rules from carrier configs, and check those as well: b/139133814
6793 SubscriptionController subController = SubscriptionController.getInstance();
6794 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6795 || subController == null) return privilegeFromSim;
6796
6797 final long identity = Binder.clearCallingIdentity();
6798 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006799 int subId = phone.getSubId();
6800 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6801 // A test override is in place for the privileges for this subId, so don't try to
6802 // read the subscription privileges.
6803 return privilegeFromSim;
6804 }
6805 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006806 SubscriptionManager subManager = (SubscriptionManager)
6807 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6808 return subManager.canManageSubscription(subInfo, pkgName)
6809 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6810 } finally {
6811 Binder.restoreCallingIdentity(identity);
6812 }
6813 }
6814
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006815 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006816 public int getCarrierPrivilegeStatus(int subId) {
6817 final Phone phone = getPhone(subId);
6818 if (phone == null) {
6819 loge("getCarrierPrivilegeStatus: Invalid subId");
6820 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6821 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006822 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6823 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006824 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006825 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6826 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006827
6828 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006829 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006830 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006831 }
Junda Liu29340342014-07-10 15:23:27 -07006832
6833 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006834 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006835 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006836 final Phone phone = getPhone(subId);
6837 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006838 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006839 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6840 }
6841 UiccProfile profile =
6842 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6843 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006844 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006845 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6846 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006847 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006848 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006849 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006850 }
6851
6852 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006853 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006854 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006855 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006856 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006857 }
6858
6859 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006860 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6861 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006862 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006863 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6864 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006865 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006866 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006867 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006868 }
6869
6870 @Override
6871 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006872 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006873 if (TextUtils.isEmpty(pkgName))
6874 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006875 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6876 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006877 UiccPort port = UiccController.getInstance().getUiccPort(i);
6878 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006879 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006880 continue;
6881 }
6882
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006883 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006884 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006885 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006886 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6887 break;
6888 }
6889 }
6890
6891 return result;
Junda Liu29340342014-07-10 15:23:27 -07006892 }
Derek Tan89e89d42014-07-08 17:00:10 -07006893
6894 @Override
Junda Liue64de782015-04-16 17:19:16 -07006895 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006896 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006897 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6898 loge("phoneId " + phoneId + " is not valid.");
6899 return null;
6900 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006901 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6902 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006903 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006904 return null ;
6905 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006906 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006907 }
6908
Amith Yamasani6e118872016-02-19 12:53:51 -08006909 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006910 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006911 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006912 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006913 List<String> privilegedPackages = new ArrayList<>();
6914 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006915 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006916 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006917 if (port != null) {
6918 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006919 if (packages == null) {
6920 // Only check packages in user 0 for now
6921 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006922 PackageManager.MATCH_DISABLED_COMPONENTS
6923 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006924 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006925 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006926 }
6927 for (int p = packages.size() - 1; p >= 0; p--) {
6928 PackageInfo pkgInfo = packages.get(p);
6929 if (pkgInfo != null && pkgInfo.packageName != null
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006930 && port.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006931 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006932 privilegedPackages.add(pkgInfo.packageName);
6933 }
6934 }
6935 }
6936 }
6937 return privilegedPackages;
6938 }
6939
chen xuf7e9fe82019-05-09 19:31:02 -07006940 @Override
6941 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006942 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6943
6944 final long identity = Binder.clearCallingIdentity();
6945
chen xuf7e9fe82019-05-09 19:31:02 -07006946 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006947 try {
6948 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6949 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6950 }
6951 } finally {
6952 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006953 }
6954 return privilegedPackages;
6955 }
6956
Wink Savilleb564aae2014-10-23 10:18:09 -07006957 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006958 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006959 UiccPort port = phone == null ? null : phone.getUiccPort();
6960 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006961 return null;
6962 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006963 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006964 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006965 return null;
6966 }
6967 return iccId;
6968 }
6969
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006970 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006971 public void setCallComposerStatus(int subId, int status) {
6972 enforceModifyPermission();
6973
6974 final long identity = Binder.clearCallingIdentity();
6975 try {
6976 Phone phone = getPhone(subId);
6977 if (phone != null) {
6978 Phone defaultPhone = phone.getImsPhone();
6979 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6980 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6981 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006982 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6983 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006984 }
6985 }
Shuo Qian284ae752020-12-22 19:10:14 -08006986 } catch (ImsException e) {
6987 throw new ServiceSpecificException(e.getCode());
6988 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006989 Binder.restoreCallingIdentity(identity);
6990 }
6991 }
6992
6993 @Override
6994 public int getCallComposerStatus(int subId) {
6995 enforceReadPrivilegedPermission("getCallComposerStatus");
6996
6997 final long identity = Binder.clearCallingIdentity();
6998 try {
6999 Phone phone = getPhone(subId);
7000 if (phone != null) {
7001 Phone defaultPhone = phone.getImsPhone();
7002 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7003 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7004 return imsPhone.getCallComposerStatus();
7005 }
7006 }
7007 } finally {
7008 Binder.restoreCallingIdentity(identity);
7009 }
7010 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7011 }
7012
7013 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007014 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7015 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007016 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007017 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019 final long identity = Binder.clearCallingIdentity();
7020 try {
7021 final String iccId = getIccId(subId);
7022 final Phone phone = getPhone(subId);
7023 if (phone == null) {
7024 return false;
7025 }
7026 final String subscriberId = phone.getSubscriberId();
7027
7028 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007029 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007030 + subscriberId + " to " + number);
7031 }
7032
7033 if (TextUtils.isEmpty(iccId)) {
7034 return false;
7035 }
7036
7037 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7038
7039 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7040 if (alphaTag == null) {
7041 editor.remove(alphaTagPrefKey);
7042 } else {
7043 editor.putString(alphaTagPrefKey, alphaTag);
7044 }
7045
7046 // Record both the line number and IMSI for this ICCID, since we need to
7047 // track all merged IMSIs based on line number
7048 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7049 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7050 if (number == null) {
7051 editor.remove(numberPrefKey);
7052 editor.remove(subscriberPrefKey);
7053 } else {
7054 editor.putString(numberPrefKey, number);
7055 editor.putString(subscriberPrefKey, subscriberId);
7056 }
7057
7058 editor.commit();
7059 return true;
7060 } finally {
7061 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007062 }
Derek Tan7226c842014-07-02 17:42:23 -07007063 }
7064
7065 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007066 public String getLine1NumberForDisplay(int subId, String callingPackage,
7067 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007068 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007070 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007071 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007072 return null;
7073 }
Derek Tan97ebb422014-09-05 16:55:38 -07007074
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075 final long identity = Binder.clearCallingIdentity();
7076 try {
7077 String iccId = getIccId(subId);
7078 if (iccId != null) {
7079 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7080 if (DBG_MERGE) {
7081 log("getLine1NumberForDisplay returning "
7082 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7083 }
7084 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007086 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7087 return null;
7088 } finally {
7089 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007090 }
Derek Tan7226c842014-07-02 17:42:23 -07007091 }
7092
7093 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007094 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7095 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007096 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007097 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007098 return null;
7099 }
Derek Tan97ebb422014-09-05 16:55:38 -07007100
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007101 final long identity = Binder.clearCallingIdentity();
7102 try {
7103 String iccId = getIccId(subId);
7104 if (iccId != null) {
7105 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7106 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7107 }
7108 return null;
7109 } finally {
7110 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007111 }
Derek Tan7226c842014-07-02 17:42:23 -07007112 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007113
7114 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007115 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7116 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007117 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7118 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007120 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007121 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007122 return null;
7123 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007124
Jordan Liub49b04b2019-05-06 14:45:15 -07007125 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7126 // the process, where TelephonyManager was instantiated.
7127 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007128 final long identity = Binder.clearCallingIdentity();
7129 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007130 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131 final TelephonyManager tele = TelephonyManager.from(context);
7132 final SubscriptionManager sub = SubscriptionManager.from(context);
7133
7134 // Figure out what subscribers are currently active
7135 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136
Jordan Liub49b04b2019-05-06 14:45:15 -07007137 // Only consider subs which match the current subId
7138 // This logic can be simplified. See b/131189269 for progress.
7139 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007140 activeSubscriberIds.add(tele.getSubscriberId(subId));
7141 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007142
7143 // First pass, find a number override for an active subscriber
7144 String mergeNumber = null;
7145 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7146 for (String key : prefs.keySet()) {
7147 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7148 final String subscriberId = (String) prefs.get(key);
7149 if (activeSubscriberIds.contains(subscriberId)) {
7150 final String iccId = key.substring(
7151 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7152 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7153 mergeNumber = (String) prefs.get(numberKey);
7154 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007155 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007156 + " for active subscriber " + subscriberId);
7157 }
7158 if (!TextUtils.isEmpty(mergeNumber)) {
7159 break;
7160 }
7161 }
7162 }
7163 }
7164
7165 // Shortcut when no active merged subscribers
7166 if (TextUtils.isEmpty(mergeNumber)) {
7167 return null;
7168 }
7169
7170 // Second pass, find all subscribers under that line override
7171 final ArraySet<String> result = new ArraySet<>();
7172 for (String key : prefs.keySet()) {
7173 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7174 final String number = (String) prefs.get(key);
7175 if (mergeNumber.equals(number)) {
7176 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7177 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7178 final String subscriberId = (String) prefs.get(subscriberKey);
7179 if (!TextUtils.isEmpty(subscriberId)) {
7180 result.add(subscriberId);
7181 }
7182 }
7183 }
7184 }
7185
7186 final String[] resultArray = result.toArray(new String[result.size()]);
7187 Arrays.sort(resultArray);
7188 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007189 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007190 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7191 }
7192 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007193 } finally {
7194 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007195 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007196 }
7197
7198 @Override
zoey chen38003472019-12-13 17:16:31 +08007199 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7200 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007201
7202 final long identity = Binder.clearCallingIdentity();
7203 try {
7204 final TelephonyManager telephonyManager = mApp.getSystemService(
7205 TelephonyManager.class);
7206 String subscriberId = telephonyManager.getSubscriberId(subId);
7207 if (subscriberId == null) {
7208 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007209 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007210 + subId);
7211 }
7212 return null;
7213 }
7214
7215 final SubscriptionInfo info = SubscriptionController.getInstance()
7216 .getSubscriptionInfo(subId);
7217 final ParcelUuid groupUuid = info.getGroupUuid();
7218 // If it doesn't belong to any group, return just subscriberId of itself.
7219 if (groupUuid == null) {
7220 return new String[]{subscriberId};
7221 }
7222
7223 // Get all subscriberIds from the group.
7224 final List<String> mergedSubscriberIds = new ArrayList<>();
7225 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007226 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007227 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007228 for (SubscriptionInfo subInfo : groupInfos) {
7229 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7230 if (subscriberId != null) {
7231 mergedSubscriberIds.add(subscriberId);
7232 }
7233 }
7234
7235 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238
7239 }
7240 }
7241
7242 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007243 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007244 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007245 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007246
7247 final long identity = Binder.clearCallingIdentity();
7248 try {
7249 final Phone phone = getPhone(subId);
7250 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7251 } finally {
7252 Binder.restoreCallingIdentity(identity);
7253 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007254 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007255
7256 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007257 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007258 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7259 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007260 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7261 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007262
7263 final long identity = Binder.clearCallingIdentity();
7264 try {
7265 final Phone phone = getPhone(subId);
7266 if (phone == null) {
7267 return false;
7268 }
7269 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7270 cdmaNonRoamingList);
7271 } finally {
7272 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007273 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007274 }
7275
7276 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007277 @Deprecated
7278 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7279 enforceModifyPermission();
7280
7281 int returnValue = 0;
7282 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007283 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007284 if(result.exception == null) {
7285 if (result.result != null) {
7286 byte[] responseData = (byte[])(result.result);
7287 if(responseData.length > oemResp.length) {
7288 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7289 responseData.length + "bytes. Buffer Size is " +
7290 oemResp.length + "bytes.");
7291 }
7292 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7293 returnValue = responseData.length;
7294 }
7295 } else {
7296 CommandException ex = (CommandException) result.exception;
7297 returnValue = ex.getCommandError().ordinal();
7298 if(returnValue > 0) returnValue *= -1;
7299 }
7300 } catch (RuntimeException e) {
7301 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7302 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7303 if(returnValue > 0) returnValue *= -1;
7304 }
7305
7306 return returnValue;
7307 }
7308
7309 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007310 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007311 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007312 try {
7313 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007314 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007315 mApp, phone.getSubId(), "getRadioAccessFamily");
7316 } catch (SecurityException e) {
7317 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7318 throw e;
7319 }
chen xub97461a2018-10-26 14:17:57 -07007320 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007321 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007322 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007323 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007324 final long identity = Binder.clearCallingIdentity();
7325 try {
chen xub97461a2018-10-26 14:17:57 -07007326 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007327 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007328 mApp, phone.getSubId(), "getRadioAccessFamily");
7329 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007330 } finally {
7331 Binder.restoreCallingIdentity(identity);
7332 }
chen xub97461a2018-10-26 14:17:57 -07007333 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007334 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007335
7336 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007337 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007338 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007339 try {
7340 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7341 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007342 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007343 }
7344 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007345 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007346 }
7347 RoleManager rm = mApp.getSystemService(RoleManager.class);
7348 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7349 if (!dialerRoleHolders.contains(callingPackage)) {
7350 throw new SecurityException("App must be the dialer role holder to"
7351 + " upload a call composer pic");
7352 }
7353
7354 Executors.newSingleThreadExecutor().execute(() -> {
7355 ByteArrayOutputStream output = new ByteArrayOutputStream(
7356 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7357 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7358 boolean readUntilEnd = false;
7359 int totalBytesRead = 0;
7360 byte[] buffer = new byte[16 * 1024];
7361 while (true) {
7362 int numRead;
7363 try {
7364 numRead = input.read(buffer);
7365 } catch (IOException e) {
7366 try {
7367 fd.checkError();
7368 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7369 null);
7370 } catch (IOException e1) {
7371 // This means that the other side closed explicitly with an error. If this
7372 // happens, log and ignore.
7373 loge("Remote end of call composer picture pipe closed: " + e1);
7374 }
7375 break;
7376 }
7377 if (numRead == -1) {
7378 readUntilEnd = true;
7379 break;
7380 }
7381 totalBytesRead += numRead;
7382 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7383 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7384 try {
7385 input.close();
7386 } catch (IOException e) {
7387 // ignore
7388 }
7389 break;
7390 }
7391 output.write(buffer, 0, numRead);
7392 }
7393 // Generally, the remote end will close the file descriptors. The only case where we
7394 // close is above, where the picture size is too big.
7395
7396 try {
7397 fd.checkError();
7398 } catch (IOException e) {
7399 loge("Remote end for call composer closed with an error: " + e);
7400 return;
7401 }
7402
Hall Liuaa4211e2021-01-20 15:43:39 -08007403 if (!readUntilEnd) {
7404 loge("Did not finish reading entire image; aborting");
7405 return;
7406 }
Hall Liu82694d52020-12-11 18:22:04 -08007407
Hall Liuaa4211e2021-01-20 15:43:39 -08007408 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7409 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7410 new CallComposerPictureTransfer.Factory() {},
7411 imageData,
7412 (result) -> {
7413 if (result.first != null) {
7414 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7415 Bundle outputResult = new Bundle();
7416 outputResult.putParcelable(
7417 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7418 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7419 outputResult);
7420 } else {
7421 callback.send(result.second, null);
7422 }
7423 }
7424 );
Hall Liu82694d52020-12-11 18:22:04 -08007425 });
7426 }
7427
7428 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007429 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007430 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007431 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432
7433 final long identity = Binder.clearCallingIdentity();
7434 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007435 ImsManager.getInstance(defaultPhone.getContext(),
7436 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 } finally {
7438 Binder.restoreCallingIdentity(identity);
7439 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007440 }
7441
7442 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007443 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007444 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7446 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007447 return false;
7448 }
Svet Ganovb320e182015-04-16 12:30:10 -07007449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007450 final long identity = Binder.clearCallingIdentity();
7451 try {
7452 // Check the user preference and the system-level IMS setting. Even if the user has
7453 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7454 // In the long run, we may instead need to check if there exists a connection service
7455 // which can support video calling.
7456 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007457 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007458 return imsManager.isVtEnabledByPlatform()
7459 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7460 && imsManager.isVtEnabledByUser();
7461 } finally {
7462 Binder.restoreCallingIdentity(identity);
7463 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007464 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007465
Andrew Leea1239f22015-03-02 17:44:07 -08007466 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007467 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7468 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007470 mApp, subId, callingPackage, callingFeatureId,
7471 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472 return false;
7473 }
7474
7475 final long identity = Binder.clearCallingIdentity();
7476 try {
7477 CarrierConfigManager configManager =
7478 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007479 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7481 } finally {
7482 Binder.restoreCallingIdentity(identity);
7483 }
Andrew Leea1239f22015-03-02 17:44:07 -08007484 }
7485
7486 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007487 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007489 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 return false;
7491 }
7492
7493 final long identity = Binder.clearCallingIdentity();
7494 try {
7495 CarrierConfigManager configManager =
7496 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007497 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007498 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7499 } finally {
7500 Binder.restoreCallingIdentity(identity);
7501 }
Andrew Leea1239f22015-03-02 17:44:07 -08007502 }
7503
Andrew Lee9431b832015-03-09 18:46:45 -07007504 @Override
7505 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007506 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007507 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007508 }
7509
7510 @Override
7511 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 final long identity = Binder.clearCallingIdentity();
7513 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007514 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 } finally {
7516 Binder.restoreCallingIdentity(identity);
7517 }
Andrew Lee9431b832015-03-09 18:46:45 -07007518 }
7519
Hall Liuf6668912018-10-31 17:05:23 -07007520 /**
7521 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7522 * support for the feature and device firmware support.
7523 *
7524 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7525 */
7526 @Override
7527 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007529 final Phone phone = getPhone(subscriptionId);
7530 if (phone == null) {
7531 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7532 return false;
7533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007535 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7537 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007538 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 return isCarrierSupported && isDeviceSupported;
7540 } finally {
7541 Binder.restoreCallingIdentity(identity);
7542 }
Hall Liu98187582018-01-22 19:15:32 -08007543 }
7544
Hall Liuf6668912018-10-31 17:05:23 -07007545 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007546 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7547 * RTT setting, will return true if the device and carrier both support RTT.
7548 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007549 */
7550 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 final long identity = Binder.clearCallingIdentity();
7552 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007553 boolean isRttSupported = isRttSupported(subscriptionId);
7554 boolean isUserRttSettingOn = Settings.Secure.getInt(
7555 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7556 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7557 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7558 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007559 } finally {
7560 Binder.restoreCallingIdentity(identity);
7561 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007562 }
7563
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007564 @Deprecated
7565 @Override
7566 public String getDeviceId(String callingPackage) {
7567 return getDeviceIdWithFeature(callingPackage, null);
7568 }
7569
Sanket Padawe7310cc72015-01-14 09:53:20 -08007570 /**
7571 * Returns the unique device ID of phone, for example, the IMEI for
7572 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7573 *
7574 * <p>Requires Permission:
7575 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7576 */
7577 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007578 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007579 try {
7580 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7581 } catch (SecurityException se) {
7582 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7583 throw new SecurityException("Package " + callingPackage + " does not belong to "
7584 + Binder.getCallingUid());
7585 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007586 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007587 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007588 return null;
7589 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007590 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007591 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007592 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007593 return null;
7594 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595
7596 final long identity = Binder.clearCallingIdentity();
7597 try {
7598 return phone.getDeviceId();
7599 } finally {
7600 Binder.restoreCallingIdentity(identity);
7601 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007602 }
7603
Ping Sunc67b7c22016-03-02 19:16:45 +08007604 /**
7605 * {@hide}
7606 * Returns the IMS Registration Status on a particular subid
7607 *
7608 * @param subId
7609 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007610 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007611 Phone phone = getPhone(subId);
7612 if (phone != null) {
7613 return phone.isImsRegistered();
7614 } else {
7615 return false;
7616 }
7617 }
7618
Santos Cordon7a1885b2015-02-03 11:15:19 -08007619 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007620 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007621 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007623 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007624 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7625 }
7626 final long identity = Binder.clearCallingIdentity();
7627 try {
7628 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7629 } finally {
7630 Binder.restoreCallingIdentity(identity);
7631 }
7632 }
7633
7634 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007635 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007636 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007637 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007638 mApp,
7639 subscriptionId,
7640 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007641 final long identity = Binder.clearCallingIdentity();
7642 try {
7643 Phone phone = getPhone(subscriptionId);
7644 if (phone == null) {
7645 return null;
7646 }
7647 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7648 } finally {
7649 Binder.restoreCallingIdentity(identity);
7650 }
7651 }
7652
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007653 /**
7654 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007655 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007656 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007657 final long identity = Binder.clearCallingIdentity();
7658 try {
7659 Phone phone = getPhone(subId);
7660 if (phone != null) {
7661 return phone.isWifiCallingEnabled();
7662 } else {
7663 return false;
7664 }
7665 } finally {
7666 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007667 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007668 }
7669
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007670 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007671 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007672 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007673 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674 final long identity = Binder.clearCallingIdentity();
7675 try {
7676 Phone phone = getPhone(subId);
7677 if (phone != null) {
7678 return phone.isVideoEnabled();
7679 } else {
7680 return false;
7681 }
7682 } finally {
7683 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007684 }
7685 }
7686
7687 /**
7688 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7689 * defined in {@link ImsRegistrationImplBase}.
7690 */
7691 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007692 final long identity = Binder.clearCallingIdentity();
7693 try {
7694 Phone phone = getPhone(subId);
7695 if (phone != null) {
7696 return phone.getImsRegistrationTech();
7697 } else {
7698 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7699 }
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007702 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007703 }
7704
Stuart Scott8eef64f2015-04-08 15:13:54 -07007705 @Override
7706 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007707 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007708 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7709 return;
7710 }
Kai Shif70f46f2021-03-03 13:59:46 -08007711 Phone defaultPhone = getDefaultPhone();
7712 if (defaultPhone != null) {
7713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7714 mApp, getDefaultPhone().getSubId(), "factoryReset");
7715 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007716 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007717
Svet Ganovcc087f82015-05-12 20:35:54 -07007718 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007719 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7720 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007721 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007722 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007723 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007724 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007725 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007726 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007727 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007728 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007729 // There has been issues when Sms raw table somehow stores orphan
7730 // fragments. They lead to garbled message when new fragments come
7731 // in and combined with those stale ones. In case this happens again,
7732 // user can reset all network settings which will clean up this table.
7733 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007734 // Clean up IMS settings as well here.
7735 int slotId = getSlotIndex(subId);
7736 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7737 ImsManager.getInstance(mApp, slotId).factoryReset();
7738 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007739
Kai Shif70f46f2021-03-03 13:59:46 -08007740 if (defaultPhone == null) {
7741 return;
7742 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007743 // Erase modem config if erase modem on network setting is enabled.
7744 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7745 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7746 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007747 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007748 }
Kai Shif70f46f2021-03-03 13:59:46 -08007749
7750 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007751 } finally {
7752 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007753 }
7754 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007755
SongFerngWangfd89b102021-05-27 22:44:54 +08007756 @VisibleForTesting
7757 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7758 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7759 return;
7760 }
7761 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7762 RILConstants.PREFERRED_NETWORK_MODE);
7763 SubscriptionManager.setSubscriptionProperty(subId,
7764 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7765 "user=" + defaultNetworkType);
7766 phone.loadAllowedNetworksFromSubscriptionDatabase();
7767 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7768 defaultNetworkType, null);
7769 }
7770
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007771 private void cleanUpSmsRawTable(Context context) {
7772 ContentResolver resolver = context.getContentResolver();
7773 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7774 resolver.delete(uri, null, null);
7775 }
7776
Narayan Kamath1c496c22015-04-16 14:40:19 +01007777 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007778 public String getSimLocaleForSubscriber(int subId) {
7779 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7780 final Phone phone = getPhone(subId);
7781 if (phone == null) {
7782 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007783 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007784 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007785 final long identity = Binder.clearCallingIdentity();
7786 try {
chen xu5d3637b2019-01-21 23:31:38 -08007787 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007788 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007789 if (info == null) {
7790 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7791 return null;
7792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007793 // Try and fetch the locale from the carrier properties or from the SIM language
7794 // preferences (EF-PL and EF-LI)...
7795 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007796 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007797 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7798 if (localeFromDefaultSim != null) {
7799 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7800 if (DBG) log("Using locale from subId: " + subId + " locale: "
7801 + localeFromDefaultSim);
7802 return localeFromDefaultSim.toLanguageTag();
7803 } else {
7804 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007805 }
7806 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007807
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808 // The SIM language preferences only store a language (e.g. fr = French), not an
7809 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7810 // the SIM and carrier preferences does not include a country we add the country
7811 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007812 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007813 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007814 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007815 return mccLocale.toLanguageTag();
7816 }
7817
7818 if (DBG) log("No locale found - returning null");
7819 return null;
7820 } finally {
7821 Binder.restoreCallingIdentity(identity);
7822 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007823 }
7824
7825 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007826 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007827 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007828 }
7829
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007830 /**
7831 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7832 */
7833 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007834 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007835 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007836 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007837
Chenjie Yu1ba97252018-01-11 18:16:20 -08007838 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007839 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007840
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007841 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007842 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7843 * representing the state of the modem.
7844 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007845 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7846 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007847 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007848 */
7849 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007850 public void requestModemActivityInfo(ResultReceiver result) {
7851 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007852 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853
7854 final long identity = Binder.clearCallingIdentity();
7855 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007856 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857 } finally {
7858 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007859 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007860 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007861
Siddharth Rayb8114062018-06-17 15:02:38 -07007862 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7863 // less than total activity duration.
7864 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7865 if (info == null) {
7866 return false;
7867 }
7868 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007869 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7870 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7871
Siddharth Rayb8114062018-06-17 15:02:38 -07007872 return (info.isValid()
7873 && (info.getSleepTimeMillis() <= activityDurationMs)
7874 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007875 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007876 && (totalTxTimeMs <= activityDurationMs));
7877 }
7878
Jack Yu85bd38a2015-11-09 11:34:32 -08007879 /**
7880 * {@hide}
7881 * Returns the service state information on specified subscription.
7882 */
7883 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007884 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7885 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007887 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007888 return null;
7889 }
7890
Hall Liuf19c44f2018-11-27 14:38:17 -08007891 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7892 LocationAccessPolicy.checkLocationPermission(mApp,
7893 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7894 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007895 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007896 .setCallingPid(Binder.getCallingPid())
7897 .setCallingUid(Binder.getCallingUid())
7898 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007899 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007900 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007901 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7902 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007903 .build());
7904
7905 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7906 LocationAccessPolicy.checkLocationPermission(mApp,
7907 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7908 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007909 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007910 .setCallingPid(Binder.getCallingPid())
7911 .setCallingUid(Binder.getCallingUid())
7912 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007913 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007914 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007915 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7916 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007917 .build());
7918 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7919 boolean hasFinePermission =
7920 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7921 boolean hasCoarsePermission =
7922 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7923
Jack Yu479f40e2020-10-27 21:29:25 -07007924 final Phone phone = getPhone(subId);
7925 if (phone == null) {
7926 return null;
7927 }
7928
Jordan Liu0f2bc442020-11-18 16:47:37 -08007929 final long identity = Binder.clearCallingIdentity();
7930
Jack Yu479f40e2020-10-27 21:29:25 -07007931 boolean isCallingPackageDataService = phone.getDataServicePackages()
7932 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007933 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007934 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7935 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7936 Rlog.d(LOG_TAG,
7937 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7938 return null;
7939 }
7940
Hall Liuf19c44f2018-11-27 14:38:17 -08007941 ServiceState ss = phone.getServiceState();
7942
7943 // Scrub out the location info in ServiceState depending on what level of access
7944 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007945 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007946 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7947 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948 } finally {
7949 Binder.restoreCallingIdentity(identity);
7950 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007951 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007952
7953 /**
7954 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7955 *
7956 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7957 * voicemail ringtone.
7958 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7959 * PhoneAccount.
7960 */
7961 @Override
7962 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963 final long identity = Binder.clearCallingIdentity();
7964 try {
7965 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7966 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007967 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007968 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007970 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7971 } finally {
7972 Binder.restoreCallingIdentity(identity);
7973 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007974 }
7975
7976 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007977 * Sets the per-account voicemail ringtone.
7978 *
7979 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7980 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7981 *
7982 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7983 * voicemail ringtone.
7984 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7985 * PhoneAccount.
7986 */
7987 @Override
7988 public void setVoicemailRingtoneUri(String callingPackage,
7989 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007990 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007991 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007992 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7993 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7995 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7996 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007998
7999 final long identity = Binder.clearCallingIdentity();
8000 try {
8001 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8002 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008003 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008004 }
8005 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8006 } finally {
8007 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008008 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008009 }
8010
8011 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008012 * Returns whether vibration is set for voicemail notification in Phone settings.
8013 *
8014 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8015 * voicemail vibration setting.
8016 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8017 */
8018 @Override
8019 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008020 final long identity = Binder.clearCallingIdentity();
8021 try {
8022 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8023 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008024 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008025 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008027 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8028 } finally {
8029 Binder.restoreCallingIdentity(identity);
8030 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008031 }
8032
Youhan Wange64578a2016-05-02 15:32:42 -07008033 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008034 * Sets the per-account voicemail vibration.
8035 *
8036 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8037 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8038 *
8039 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8040 * voicemail vibration setting.
8041 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8042 * specific PhoneAccount.
8043 */
8044 @Override
8045 public void setVoicemailVibrationEnabled(String callingPackage,
8046 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008047 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008048 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008049 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8050 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8052 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8053 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008054 }
8055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008056 final long identity = Binder.clearCallingIdentity();
8057 try {
8058 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8059 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008060 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008061 }
8062 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8063 } finally {
8064 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008065 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008066 }
8067
8068 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008069 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8070 *
8071 * @throws SecurityException if the caller does not have the required permission
8072 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008073 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008074 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008075 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008076 }
8077
8078 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008079 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8080 * permission.
8081 *
8082 * @throws SecurityException if the caller does not have the required permission
8083 */
8084 private void enforceSendSmsPermission() {
8085 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8086 }
8087
8088 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008089 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008090 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008091 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008092 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008093 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008094 final long identity = Binder.clearCallingIdentity();
8095 try {
8096 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008097 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008098 if (componentName == null) {
8099 throw new SecurityException(
8100 "Caller not current active visual voicemail package[null]");
8101 }
8102 String vvmPackage = componentName.getPackageName();
8103 if (!callingPackage.equals(vvmPackage)) {
8104 throw new SecurityException("Caller not current active visual voicemail package["
8105 + vvmPackage + "]");
8106 }
8107 } finally {
8108 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008109 }
8110 }
8111
8112 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008113 * Return the application ID for the app type.
8114 *
8115 * @param subId the subscription ID that this request applies to.
8116 * @param appType the uicc app type.
8117 * @return Application ID for specificied app type, or null if no uicc.
8118 */
8119 @Override
8120 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008121 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008122 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008123
8124 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008125 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008126 if (phone == null) {
8127 return null;
8128 }
8129 String aid = null;
8130 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008131 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008132 .getApplicationByType(appType).getAid();
8133 } catch (Exception e) {
8134 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8135 }
8136 return aid;
8137 } finally {
8138 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008139 }
Youhan Wange64578a2016-05-02 15:32:42 -07008140 }
8141
Youhan Wang4001d252016-05-11 10:29:41 -07008142 /**
8143 * Return the Electronic Serial Number.
8144 *
8145 * @param subId the subscription ID that this request applies to.
8146 * @return ESN or null if error.
8147 */
8148 @Override
8149 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008150 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008151 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008152
8153 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008154 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008155 if (phone == null) {
8156 return null;
8157 }
8158 String esn = null;
8159 try {
8160 esn = phone.getEsn();
8161 } catch (Exception e) {
8162 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8163 }
8164 return esn;
8165 } finally {
8166 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008167 }
Youhan Wang4001d252016-05-11 10:29:41 -07008168 }
8169
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008170 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008171 * Return the Preferred Roaming List Version.
8172 *
8173 * @param subId the subscription ID that this request applies to.
8174 * @return PRLVersion or null if error.
8175 */
8176 @Override
8177 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008178 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008179 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008180
8181 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008182 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008183 if (phone == null) {
8184 return null;
8185 }
8186 String cdmaPrlVersion = null;
8187 try {
8188 cdmaPrlVersion = phone.getCdmaPrlVersion();
8189 } catch (Exception e) {
8190 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8191 }
8192 return cdmaPrlVersion;
8193 } finally {
8194 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008195 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008196 }
8197
8198 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008199 * Get snapshot of Telephony histograms
8200 * @return List of Telephony histograms
8201 * @hide
8202 */
8203 @Override
8204 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8206 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008207
8208 final long identity = Binder.clearCallingIdentity();
8209 try {
8210 return RIL.getTelephonyRILTimingHistograms();
8211 } finally {
8212 Binder.restoreCallingIdentity(identity);
8213 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008214 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008215
8216 /**
8217 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008218 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8219 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008220 * Require system privileges. In the future we may add this to carrier APIs.
8221 *
Michele Berionne482f8202018-11-27 18:57:59 -08008222 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008223 */
8224 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008225 @TelephonyManager.SetCarrierRestrictionResult
8226 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008227 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008228 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008229
Michele Berionne482f8202018-11-27 18:57:59 -08008230 if (carrierRestrictionRules == null) {
8231 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008232 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008234 final long identity = Binder.clearCallingIdentity();
8235 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008236 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008237 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238 } finally {
8239 Binder.restoreCallingIdentity(identity);
8240 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008241 }
8242
8243 /**
8244 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008245 * Get the allowed carrier list and the excluded carrier list, including the priority between
8246 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008247 * Require system privileges. In the future we may add this to carrier APIs.
8248 *
Michele Berionne482f8202018-11-27 18:57:59 -08008249 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008250 */
8251 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008252 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008253 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008254 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008255
8256 final long identity = Binder.clearCallingIdentity();
8257 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008258 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8259 if (response instanceof CarrierRestrictionRules) {
8260 return (CarrierRestrictionRules) response;
8261 }
8262 // Response is an Exception of some kind,
8263 // which is signalled to the user as a NULL retval
8264 return null;
8265 } catch (Exception e) {
8266 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8267 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008268 } finally {
8269 Binder.restoreCallingIdentity(identity);
8270 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008271 }
8272
fionaxu59545b42016-05-25 15:53:37 -07008273 /**
fionaxu59545b42016-05-25 15:53:37 -07008274 * Action set from carrier signalling broadcast receivers to enable/disable radio
8275 * @param subId the subscription ID that this action applies to.
8276 * @param enabled control enable or disable radio.
8277 * {@hide}
8278 */
8279 @Override
8280 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8281 enforceModifyPermission();
8282 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283
8284 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008285 if (phone == null) {
8286 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8287 return;
8288 }
8289 try {
8290 phone.carrierActionSetRadioEnabled(enabled);
8291 } catch (Exception e) {
8292 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 } finally {
8294 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008295 }
8296 }
8297
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008298 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008299 * Enable or disable Voice over NR (VoNR)
8300 * @param subId the subscription ID that this action applies to.
8301 * @param enabled enable or disable VoNR.
8302 * @return operation result.
8303 */
8304 @Override
8305 public int setVoNrEnabled(int subId, boolean enabled) {
8306 enforceModifyPermission();
8307 final Phone phone = getPhone(subId);
8308
8309 final long identity = Binder.clearCallingIdentity();
8310 if (phone == null) {
8311 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8312 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8313 }
8314
8315 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8316 try {
8317 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8318 workSource);
8319 if (DBG) log("setVoNrEnabled result: " + result);
8320 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
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008423 * @param reason the reason the data enable change is taking place
8424 * @param enabled True if enabling the data, otherwise disabling.
8425 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008426 */
8427 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008428 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008429 boolean enabled) {
8430 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8431 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8432 try {
8433 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008434 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008435 } catch (SecurityException se) {
8436 enforceModifyPermission();
8437 }
8438 } else {
8439 enforceModifyPermission();
8440 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008441
8442 final long identity = Binder.clearCallingIdentity();
8443 try {
8444 Phone phone = getPhone(subId);
8445 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008446 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8447 phone.carrierActionSetMeteredApnsEnabled(enabled);
8448 } else {
8449 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8450 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008451 }
8452 } finally {
8453 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008454 }
8455 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008456
8457 /**
8458 * Get Client request stats
8459 * @return List of Client Request Stats
8460 * @hide
8461 */
8462 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008463 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8464 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008466 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008467 return null;
8468 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008469 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008471 final long identity = Binder.clearCallingIdentity();
8472 try {
8473 if (phone != null) {
8474 return phone.getClientRequestStats();
8475 }
8476
8477 return null;
8478 } finally {
8479 Binder.restoreCallingIdentity(identity);
8480 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008481 }
8482
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008483 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008484 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008485 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008486 }
Jack Yueb4124c2017-02-16 15:32:43 -08008487
8488 /**
Grace Chen70990072017-03-24 17:21:30 -07008489 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008490 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008491 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008492 * @param state State of SIM (power down, power up, pass through)
8493 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8494 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8495 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008496 *
8497 **/
8498 @Override
Grace Chen70990072017-03-24 17:21:30 -07008499 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008500 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008501 Phone phone = PhoneFactory.getPhone(slotIndex);
8502
vagdeviaf9a5b92018-08-15 16:01:53 -07008503 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008505 final long identity = Binder.clearCallingIdentity();
8506 try {
8507 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008508 phone.setSimPowerState(state, null, workSource);
8509 }
8510 } finally {
8511 Binder.restoreCallingIdentity(identity);
8512 }
8513 }
8514
8515 /**
8516 * Set SIM card power state.
8517 *
8518 * @param slotIndex SIM slot id.
8519 * @param state State of SIM (power down, power up, pass through)
8520 * @param callback callback to trigger after success or failure
8521 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8522 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8523 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8524 *
8525 **/
8526 @Override
8527 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8528 IIntegerConsumer callback) {
8529 enforceModifyPermission();
8530 Phone phone = PhoneFactory.getPhone(slotIndex);
8531
8532 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8533
8534 final long identity = Binder.clearCallingIdentity();
8535 try {
8536 if (phone != null) {
8537 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8538 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008539 }
8540 } finally {
8541 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008542 }
8543 }
Shuo Qiandd210312017-04-12 22:11:33 +00008544
Tyler Gunn65d45c22017-06-05 11:22:26 -07008545 private boolean isUssdApiAllowed(int subId) {
8546 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008547 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008548 if (configManager == null) {
8549 return false;
8550 }
8551 PersistableBundle pb = configManager.getConfigForSubId(subId);
8552 if (pb == null) {
8553 return false;
8554 }
8555 return pb.getBoolean(
8556 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8557 }
8558
Shuo Qiandd210312017-04-12 22:11:33 +00008559 /**
8560 * Check if phone is in emergency callback mode
8561 * @return true if phone is in emergency callback mode
8562 * @param subId sub id
8563 */
goneil9c5f4872017-12-05 14:07:56 -08008564 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008565 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008566 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008567 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008568
8569 final long identity = Binder.clearCallingIdentity();
8570 try {
8571 if (phone != null) {
8572 return phone.isInEcm();
8573 } else {
8574 return false;
8575 }
8576 } finally {
8577 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008578 }
8579 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008580
8581 /**
8582 * Get the current signal strength information for the given subscription.
8583 * Because this information is not updated when the device is in a low power state
8584 * it should not be relied-upon to be current.
8585 * @param subId Subscription index
8586 * @return the most recent cached signal strength info from the modem
8587 */
8588 @Override
8589 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008590 final long identity = Binder.clearCallingIdentity();
8591 try {
8592 Phone p = getPhone(subId);
8593 if (p == null) {
8594 return null;
8595 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008597 return p.getSignalStrength();
8598 } finally {
8599 Binder.restoreCallingIdentity(identity);
8600 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008601 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008602
Pengquan Meng77b7f132018-08-22 14:49:57 -07008603 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008604 * Get the current modem radio state for the given slot.
8605 * @param slotIndex slot index.
8606 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008607 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008608 * @return the current radio power state from the modem
8609 */
8610 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008611 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008612 Phone phone = PhoneFactory.getPhone(slotIndex);
8613 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008614 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8615 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008616 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8617 }
8618
8619 final long identity = Binder.clearCallingIdentity();
8620 try {
8621 return phone.getRadioPowerState();
8622 } finally {
8623 Binder.restoreCallingIdentity(identity);
8624 }
8625 }
8626 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8627 }
8628
8629 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008630 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8631 *
8632 * <p>Requires one of the following permissions:
8633 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8634 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8635 * privileges.
8636 *
8637 * @param subId subscription id
8638 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8639 * {@code false}.
8640 */
8641 @Override
8642 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008643 try {
8644 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8645 null);
8646 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008647 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008648 mApp, subId, "isDataRoamingEnabled");
8649 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008650
Pengquan Menga1bb6272018-09-06 09:59:22 -07008651 boolean isEnabled = false;
8652 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008653 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008654 Phone phone = getPhone(subId);
8655 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008656 } finally {
8657 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008658 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008659 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008660 }
8661
8662
8663 /**
8664 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8665 *
8666 * <p> Requires permission:
8667 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8668 * privileges.
8669 *
8670 * @param subId subscription id
8671 * @param isEnabled {@code true} means enable, {@code false} means disable.
8672 */
8673 @Override
8674 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8676 mApp, subId, "setDataRoamingEnabled");
8677
Pengquan Menga1bb6272018-09-06 09:59:22 -07008678 final long identity = Binder.clearCallingIdentity();
8679 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008680 Phone phone = getPhone(subId);
8681 if (phone != null) {
8682 phone.setDataRoamingEnabled(isEnabled);
8683 }
8684 } finally {
8685 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008686 }
8687 }
8688
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008689 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008690 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008691 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008692 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008693 mApp, subId, "isManualNetworkSelectionAllowed");
8694
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008695 boolean isAllowed = true;
8696 final long identity = Binder.clearCallingIdentity();
8697 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008698 Phone phone = getPhone(subId);
8699 if (phone != null) {
8700 isAllowed = phone.isCspPlmnEnabled();
8701 }
8702 } finally {
8703 Binder.restoreCallingIdentity(identity);
8704 }
8705 return isAllowed;
8706 }
8707
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008708 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8709 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8710 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8711 // Update each UiccPort object based on privilege access
8712 UiccPort[] uiccPorts = card.getUiccPortList();
8713 for (UiccPort port : uiccPorts) {
8714 UiccProfile profile = port.getUiccProfile();
8715 if (profile == null ||
8716 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8717 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8718 return false;
8719 }
8720 }
8721 return true;
8722 }
8723
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008724 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008725 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008726 // Verify that tha callingPackage belongs to the calling UID
8727 mApp.getSystemService(AppOpsManager.class)
8728 .checkPackage(Binder.getCallingUid(), callingPackage);
8729
Jordan Liu1e142fc2019-04-22 15:10:43 -07008730 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008731 try {
8732 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008733 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008734 } catch (SecurityException e) {
8735 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8736 // has carrier privileges on an active UICC
8737 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8738 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008739 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008740 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008741 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008742
8743 final long identity = Binder.clearCallingIdentity();
8744 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008745 UiccController uiccController = UiccController.getInstance();
8746 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008747 if (hasReadPermission) {
8748 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008749 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008750
8751 // Remove private info if the caller doesn't have access
8752 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8753 for (UiccCardInfo cardInfo : cardInfos) {
8754 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8755 // is available
8756 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008757 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8758 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8759 if (card == null || card.getUiccPortList().length == 0) {
8760 // assume no access if the card or ports are unavailable
Jordan Liu1e142fc2019-04-22 15:10:43 -07008761 filteredInfos.add(cardInfo.getUnprivileged());
8762 continue;
8763 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008764
8765 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008766 filteredInfos.add(cardInfo);
8767 } else {
8768 filteredInfos.add(cardInfo.getUnprivileged());
8769 }
8770 }
8771 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008772 } finally {
8773 Binder.restoreCallingIdentity(identity);
8774 }
8775 }
8776
8777 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008778 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008779 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008781 final long identity = Binder.clearCallingIdentity();
8782 try {
8783 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8784 if (slots == null) {
8785 Rlog.i(LOG_TAG, "slots is null.");
8786 return null;
8787 }
8788
8789 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8790 for (int i = 0; i < slots.length; i++) {
8791 UiccSlot slot = slots[i];
8792 if (slot == null) {
8793 continue;
8794 }
8795
Jordan Liu7be7e652019-05-06 18:55:02 +00008796 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008797 UiccCard card = slot.getUiccCard();
8798 if (card != null) {
8799 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008800 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008801 cardId = slot.getEid();
8802 if (TextUtils.isEmpty(cardId)) {
8803 cardId = slot.getIccId();
8804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008805 }
8806
Jordan Liu857451f2019-05-09 16:35:35 -07008807 if (cardId != null) {
8808 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8809 // if cardId is an EID, it's all digits so this is fine
8810 cardId = IccUtils.stripTrailingFs(cardId);
8811 }
8812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008813 int cardState = 0;
8814 switch (slot.getCardState()) {
8815 case CARDSTATE_ABSENT:
8816 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8817 break;
8818 case CARDSTATE_PRESENT:
8819 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8820 break;
8821 case CARDSTATE_ERROR:
8822 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8823 break;
8824 case CARDSTATE_RESTRICTED:
8825 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8826 break;
8827 default:
8828 break;
8829
8830 }
8831
8832 infos[i] = new UiccSlotInfo(
8833 slot.isActive(),
8834 slot.isEuicc(),
8835 cardId,
8836 cardState,
8837 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008838 slot.isExtendedApduSupported(),
8839 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008840 }
8841 return infos;
8842 } finally {
8843 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008844 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008845 }
8846
8847 @Override
8848 public boolean switchSlots(int[] physicalSlots) {
8849 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008850
8851 final long identity = Binder.clearCallingIdentity();
8852 try {
8853 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8854 } finally {
8855 Binder.restoreCallingIdentity(identity);
8856 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008857 }
Jack Yu4c988042018-02-27 15:30:01 -08008858
8859 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008860 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008861 final long identity = Binder.clearCallingIdentity();
8862 try {
8863 return UiccController.getInstance().getCardIdForDefaultEuicc();
8864 } finally {
8865 Binder.restoreCallingIdentity(identity);
8866 }
8867 }
8868
Pengquan Meng85728fb2018-03-12 16:31:21 -07008869 /**
goneil47ffb6e2018-04-06 15:40:58 -07008870 * A test API to reload the UICC profile.
8871 *
8872 * <p>Requires that the calling app has permission
8873 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8874 * @hide
8875 */
8876 @Override
8877 public void refreshUiccProfile(int subId) {
8878 enforceModifyPermission();
8879
8880 final long identity = Binder.clearCallingIdentity();
8881 try {
8882 Phone phone = getPhone(subId);
8883 if (phone == null) {
8884 return;
8885 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008886 UiccPort uiccPort = phone.getUiccPort();
8887 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008888 return;
8889 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008890 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008891 if (uiccProfile == null) {
8892 return;
8893 }
8894 uiccProfile.refresh();
8895 } finally {
8896 Binder.restoreCallingIdentity(identity);
8897 }
8898 }
8899
8900 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008901 * Returns false if the mobile data is disabled by default, otherwise return true.
8902 */
8903 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008904 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008905 }
8906
8907 /**
8908 * Returns true if the data roaming is enabled by default, i.e the system property
8909 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8910 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8911 */
8912 private boolean getDefaultDataRoamingEnabled(int subId) {
8913 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008914 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008915 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008916 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8917 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8918 return isDataRoamingEnabled;
8919 }
8920
8921 /**
8922 * Returns the default network type for the given {@code subId}, if the default network type is
8923 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8924 */
8925 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008926 List<Integer> list = TelephonyProperties.default_network();
8927 int phoneId = mSubscriptionController.getPhoneId(subId);
8928 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8929 return list.get(phoneId);
8930 }
8931 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008932 }
fionaxua13278b2018-03-21 00:08:13 -07008933
8934 @Override
8935 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008936 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008937 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008938
8939 final long identity = Binder.clearCallingIdentity();
8940 try {
8941 final Phone phone = getPhone(subId);
8942 if (phone == null) {
8943 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8944 return;
8945 }
chen xueaba88a2019-03-15 13:15:10 -07008946 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8947 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008948 if (carrierPrivilegeRules == null) {
8949 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8950 } else {
8951 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008953 } finally {
8954 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008955 }
fionaxua13278b2018-03-21 00:08:13 -07008956 }
8957
8958 @Override
8959 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008960 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008961
8962 final long identity = Binder.clearCallingIdentity();
8963 try {
8964 final Phone phone = getPhone(subId);
8965 if (phone == null) {
8966 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8967 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8968 }
8969 return phone.getCarrierIdListVersion();
8970 } finally {
8971 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008972 }
fionaxua13278b2018-03-21 00:08:13 -07008973 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008974
8975 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008976 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8977 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008979 mApp, subId, callingPackage, callingFeatureId,
8980 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008981 return -1;
8982 }
8983
8984 final long identity = Binder.clearCallingIdentity();
8985 try {
8986 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8987 } finally {
8988 Binder.restoreCallingIdentity(identity);
8989 }
8990 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008991
8992 @Override
8993 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008994 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008995 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008996 mApp, subId, "getCdmaRoamingMode");
8997
8998 final long identity = Binder.clearCallingIdentity();
8999 try {
9000 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9001 } finally {
9002 Binder.restoreCallingIdentity(identity);
9003 }
9004 }
9005
9006 @Override
9007 public boolean setCdmaRoamingMode(int subId, int mode) {
9008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9009 mApp, subId, "setCdmaRoamingMode");
9010
9011 final long identity = Binder.clearCallingIdentity();
9012 try {
9013 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9014 } finally {
9015 Binder.restoreCallingIdentity(identity);
9016 }
9017 }
9018
9019 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009020 public int getCdmaSubscriptionMode(int subId) {
9021 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009022 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009023 mApp, subId, "getCdmaSubscriptionMode");
9024
9025 final long identity = Binder.clearCallingIdentity();
9026 try {
9027 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9028 } finally {
9029 Binder.restoreCallingIdentity(identity);
9030 }
9031 }
9032
9033 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009034 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9036 mApp, subId, "setCdmaSubscriptionMode");
9037
9038 final long identity = Binder.clearCallingIdentity();
9039 try {
9040 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9041 } finally {
9042 Binder.restoreCallingIdentity(identity);
9043 }
9044 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009045
sqianc5eccab2018-10-19 18:46:41 -07009046 @Override
sqian8c685422019-02-22 15:55:18 -08009047 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009048 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009050 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9051 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009052 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9053 }
9054 final long identity = Binder.clearCallingIdentity();
9055 try {
sqian854d44b2018-12-12 16:48:18 -08009056 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9057 for (Phone phone: PhoneFactory.getPhones()) {
9058 if (phone.getEmergencyNumberTracker() != null
9059 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9060 emergencyNumberListInternal.put(
9061 phone.getSubId(),
9062 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9063 }
sqian11b7a0e2018-12-05 18:48:28 -08009064 }
sqian854d44b2018-12-12 16:48:18 -08009065 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009066 } finally {
9067 Binder.restoreCallingIdentity(identity);
9068 }
sqianc5eccab2018-10-19 18:46:41 -07009069 }
9070
9071 @Override
sqian8c685422019-02-22 15:55:18 -08009072 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009073 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009074 if (!exactMatch) {
9075 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009076 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009077 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009078 }
9079 final long identity = Binder.clearCallingIdentity();
9080 try {
sqian854d44b2018-12-12 16:48:18 -08009081 for (Phone phone: PhoneFactory.getPhones()) {
9082 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009083 && phone.getEmergencyNumberTracker()
9084 .isEmergencyNumber(number, exactMatch)) {
9085 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009086 }
sqian11b7a0e2018-12-05 18:48:28 -08009087 }
9088 return false;
9089 } finally {
9090 Binder.restoreCallingIdentity(identity);
9091 }
9092 }
9093
sqianf4ca7ed2019-01-15 18:32:07 -08009094 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009095 * Start emergency callback mode for GsmCdmaPhone for testing.
9096 */
9097 @Override
9098 public void startEmergencyCallbackMode() {
9099 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9100 "startEmergencyCallbackMode");
9101 enforceModifyPermission();
9102 final long identity = Binder.clearCallingIdentity();
9103 try {
9104 for (Phone phone : PhoneFactory.getPhones()) {
9105 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9106 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9107 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9108 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9109 gsmCdmaPhone.obtainMessage(
9110 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9111 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9112 }
9113 }
9114 } finally {
9115 Binder.restoreCallingIdentity(identity);
9116 }
9117 }
9118
9119 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009120 * Update emergency number list for test mode.
9121 */
9122 @Override
9123 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9124 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9125 "updateEmergencyNumberListTestMode");
9126
9127 final long identity = Binder.clearCallingIdentity();
9128 try {
9129 for (Phone phone: PhoneFactory.getPhones()) {
9130 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9131 if (tracker != null) {
9132 tracker.executeEmergencyNumberTestModeCommand(action, num);
9133 }
9134 }
9135 } finally {
9136 Binder.restoreCallingIdentity(identity);
9137 }
9138 }
9139
9140 /**
9141 * Get the full emergency number list for test mode.
9142 */
9143 @Override
9144 public List<String> getEmergencyNumberListTestMode() {
9145 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9146 "getEmergencyNumberListTestMode");
9147
9148 final long identity = Binder.clearCallingIdentity();
9149 try {
9150 Set<String> emergencyNumbers = new HashSet<>();
9151 for (Phone phone: PhoneFactory.getPhones()) {
9152 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9153 if (tracker != null) {
9154 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9155 emergencyNumbers.add(num.getNumber());
9156 }
9157 }
9158 }
9159 return new ArrayList<>(emergencyNumbers);
9160 } finally {
9161 Binder.restoreCallingIdentity(identity);
9162 }
9163 }
9164
chen xud6b45bd2018-10-30 22:27:10 -07009165 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009166 public int getEmergencyNumberDbVersion(int subId) {
9167 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9168
9169 final long identity = Binder.clearCallingIdentity();
9170 try {
9171 final Phone phone = getPhone(subId);
9172 if (phone == null) {
9173 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9174 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9175 }
9176 return phone.getEmergencyNumberDbVersion();
9177 } finally {
9178 Binder.restoreCallingIdentity(identity);
9179 }
9180 }
9181
9182 @Override
9183 public void notifyOtaEmergencyNumberDbInstalled() {
9184 enforceModifyPermission();
9185
9186 final long identity = Binder.clearCallingIdentity();
9187 try {
9188 for (Phone phone: PhoneFactory.getPhones()) {
9189 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9190 if (tracker != null) {
9191 tracker.updateOtaEmergencyNumberDatabase();
9192 }
9193 }
9194 } finally {
9195 Binder.restoreCallingIdentity(identity);
9196 }
9197 }
9198
9199 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009200 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009201 enforceActiveEmergencySessionPermission();
9202
9203 final long identity = Binder.clearCallingIdentity();
9204 try {
9205 for (Phone phone: PhoneFactory.getPhones()) {
9206 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9207 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009208 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9209 }
9210 }
9211 } finally {
9212 Binder.restoreCallingIdentity(identity);
9213 }
9214 }
9215
9216 @Override
9217 public void resetOtaEmergencyNumberDbFilePath() {
9218 enforceActiveEmergencySessionPermission();
9219
9220 final long identity = Binder.clearCallingIdentity();
9221 try {
9222 for (Phone phone: PhoneFactory.getPhones()) {
9223 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9224 if (tracker != null) {
9225 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009226 }
9227 }
9228 } finally {
9229 Binder.restoreCallingIdentity(identity);
9230 }
9231 }
9232
9233 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009234 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9235 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9236 Phone phone = getPhone(subId);
9237 if (phone == null) {
9238 return null;
9239 }
9240 final long identity = Binder.clearCallingIdentity();
9241 try {
9242 UiccProfile profile = UiccController.getInstance()
9243 .getUiccProfileForPhone(phone.getPhoneId());
9244 if (profile != null) {
9245 return profile.getCertsFromCarrierPrivilegeAccessRules();
9246 }
9247 } finally {
9248 Binder.restoreCallingIdentity(identity);
9249 }
9250 return null;
9251 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009252
9253 /**
9254 * Enable or disable a modem stack.
9255 */
9256 @Override
9257 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9258 enforceModifyPermission();
9259
9260 final long identity = Binder.clearCallingIdentity();
9261 try {
9262 Phone phone = PhoneFactory.getPhone(slotIndex);
9263 if (phone == null) {
9264 return false;
9265 } else {
9266 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9267 }
9268 } finally {
9269 Binder.restoreCallingIdentity(identity);
9270 }
9271 }
Michelecea4cf22018-12-21 15:00:11 -08009272
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009273 /**
9274 * Whether a modem stack is enabled or not.
9275 */
9276 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009277 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9278 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009279 Phone phone = PhoneFactory.getPhone(slotIndex);
9280 if (phone == null) return false;
9281
9282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009283 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9284 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009285 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9286 }
9287
9288 final long identity = Binder.clearCallingIdentity();
9289 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009290 try {
9291 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9292 } catch (NoSuchElementException ex) {
9293 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9294 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009295 } finally {
9296 Binder.restoreCallingIdentity(identity);
9297 }
9298 }
9299
Michelecea4cf22018-12-21 15:00:11 -08009300 @Override
Michele0ea7d782019-03-19 14:58:42 -07009301 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009302 enforceModifyPermission();
9303
9304 final long identity = Binder.clearCallingIdentity();
9305 try {
9306 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009307 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009308 .commit();
9309 } finally {
9310 Binder.restoreCallingIdentity(identity);
9311 }
9312 }
9313
9314 @Override
Michele0ea7d782019-03-19 14:58:42 -07009315 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009316 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009318 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9319 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009320 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009321 }
Michelecea4cf22018-12-21 15:00:11 -08009322
9323 final long identity = Binder.clearCallingIdentity();
9324 try {
Michele0ea7d782019-03-19 14:58:42 -07009325 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009326 } finally {
9327 Binder.restoreCallingIdentity(identity);
9328 }
9329 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009330
Michele0ea7d782019-03-19 14:58:42 -07009331 @TelephonyManager.IsMultiSimSupportedResult
9332 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009333 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9334 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9335 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009336 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9337 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009338 }
9339 // Check if the hardware supports multisim functionality. If usage of multisim is not
9340 // supported by the modem, indicate that it is restricted.
9341 PhoneCapability staticCapability =
9342 mPhoneConfigurationManager.getStaticPhoneCapability();
9343 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009344 loge("isMultiSimSupportedInternal: no static configuration available");
9345 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009346 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009347 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009348 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9349 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009350 }
9351 // Check if support of multiple SIMs is restricted by carrier
9352 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009353 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009354 }
9355
Michele0ea7d782019-03-19 14:58:42 -07009356 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009357 }
9358
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009359 /**
9360 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009361 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9362 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9363 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009364 * @param numOfSims number of active sims we want to switch to
9365 */
9366 @Override
9367 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009368 if (numOfSims == 1) {
9369 enforceModifyPermission();
9370 } else {
9371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9372 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9373 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009374 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009375
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009376 try {
Michele30b57b22019-03-01 12:01:14 -08009377 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009378 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009379 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9380 return;
9381 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009382 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9383 } finally {
9384 Binder.restoreCallingIdentity(identity);
9385 }
9386 }
9387
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009388 @Override
9389 public boolean isApplicationOnUicc(int subId, int appType) {
9390 enforceReadPrivilegedPermission("isApplicationOnUicc");
9391 Phone phone = getPhone(subId);
9392 if (phone == null) {
9393 return false;
9394 }
9395 final long identity = Binder.clearCallingIdentity();
9396 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009397 UiccPort uiccPort = phone.getUiccPort();
9398 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009399 return false;
9400 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009401 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009402 if (uiccProfile == null) {
9403 return false;
9404 }
9405 if (TelephonyManager.APPTYPE_SIM <= appType
9406 && appType <= TelephonyManager.APPTYPE_ISIM) {
9407 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9408 }
9409 return false;
9410 } finally {
9411 Binder.restoreCallingIdentity(identity);
9412 }
9413 }
9414
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009415 /**
chen xub4baa772019-04-03 10:23:41 -07009416 * Get whether making changes to modem configurations will trigger reboot.
9417 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009418 */
9419 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009420 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9421 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009422 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009423 mApp, subId, callingPackage, callingFeatureId,
9424 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009425 return false;
9426 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009427 final long identity = Binder.clearCallingIdentity();
9428 try {
9429 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9430 } finally {
9431 Binder.restoreCallingIdentity(identity);
9432 }
9433 }
9434
Nathan Harold29f5f052019-02-15 13:41:57 -08009435 private void updateModemStateMetrics() {
9436 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9437 // TODO: check the state for each modem if the api is ready.
9438 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9439 }
9440
Pengquan Meng3889a572019-01-23 11:16:29 -08009441 @Override
9442 public int[] getSlotsMapping() {
9443 enforceReadPrivilegedPermission("getSlotsMapping");
9444
9445 final long identity = Binder.clearCallingIdentity();
9446 try {
9447 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9448 // All logical slots should have a mapping to a physical slot.
9449 int[] logicalSlotsMapping = new int[phoneCount];
9450 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9451 for (int i = 0; i < slotInfos.length; i++) {
9452 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9453 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9454 }
9455 }
9456 return logicalSlotsMapping;
9457 } finally {
9458 Binder.restoreCallingIdentity(identity);
9459 }
9460 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009461
9462 /**
9463 * Get the IRadio HAL Version
9464 */
9465 @Override
9466 public int getRadioHalVersion() {
9467 Phone phone = getDefaultPhone();
9468 if (phone == null) return -1;
9469 HalVersion hv = phone.getHalVersion();
9470 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9471 return hv.major * 100 + hv.minor;
9472 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009473
9474 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009475 * Get the current calling package name.
9476 * @return the current calling package name
9477 */
9478 @Override
9479 public String getCurrentPackageName() {
9480 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9481 }
9482
9483 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009484 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9485 * corresponding network requests on a subId.
9486 *
9487 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009488 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009489 * 2) APN is un-metered for this subscription, or
9490 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009491 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009492 *
9493 * @return whether data is allowed for a apn type.
9494 *
9495 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009496 */
9497 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009498 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009499 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9500 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009501
9502 // Now that all security checks passes, perform the operation as ourselves.
9503 final long identity = Binder.clearCallingIdentity();
9504 try {
9505 Phone phone = getPhone(subId);
9506 if (phone == null) return false;
9507
Jack Yu41407ee2019-05-13 16:54:09 -07009508 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009509 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9510 } finally {
9511 Binder.restoreCallingIdentity(identity);
9512 }
9513 }
9514
9515 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009516 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009517 enforceReadPrivilegedPermission("isApnMetered");
9518
9519 // Now that all security checks passes, perform the operation as ourselves.
9520 final long identity = Binder.clearCallingIdentity();
9521 try {
9522 Phone phone = getPhone(subId);
9523 if (phone == null) return true; // By default return true.
9524
Jack Yu41407ee2019-05-13 16:54:09 -07009525 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009526 } finally {
9527 Binder.restoreCallingIdentity(identity);
9528 }
9529 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009530
9531 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009532 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9533 int subscriptionId, IBooleanConsumer resultCallback) {
9534 enforceModifyPermission();
9535 long token = Binder.clearCallingIdentity();
9536 try {
9537 Phone phone = getPhone(subscriptionId);
9538 if (phone == null) {
9539 try {
9540 if (resultCallback != null) {
9541 resultCallback.accept(false);
9542 }
9543 } catch (RemoteException e) {
9544 // ignore
9545 }
9546 return;
9547 }
9548 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9549 Pair.create(specifiers, (x) -> {
9550 try {
9551 if (resultCallback != null) {
9552 resultCallback.accept(x);
9553 }
9554 } catch (RemoteException e) {
9555 // ignore
9556 }
9557 });
9558 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9559 } finally {
9560 Binder.restoreCallingIdentity(token);
9561 }
9562 }
9563
9564 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009565 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9566 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009567 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009568 mApp, subId, "getSystemSelectionChannels");
9569 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9570 final long identity = Binder.clearCallingIdentity();
9571 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009572 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9573 if (result instanceof IllegalStateException) {
9574 throw (IllegalStateException) result;
9575 }
9576 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009577 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9578 return specifiers;
9579 } finally {
9580 Binder.restoreCallingIdentity(identity);
9581 }
9582 }
9583
9584 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009585 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009586 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009587 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9588 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9589 if (iccRecords == null) {
9590 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9591 return false;
9592 }
9593 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9594 }
9595
9596 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009597 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9598 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009599 if (callingPackage == null) {
9600 callingPackage = getCurrentPackageName();
9601 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009602 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9603 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009604 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9605 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009606 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9607 }
9608 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9609 Intent intent = new Intent();
9610 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9611 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9612 // Bring up choose default SMS subscription dialog right now
9613 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9614 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9615 mApp.startActivity(intent);
9616 }
chen xud5ca2d52019-05-28 15:20:57 -07009617
9618 @Override
9619 public String getMmsUAProfUrl(int subId) {
9620 //TODO investigate if this API should require proper permission check in R b/133791609
9621 final long identity = Binder.clearCallingIdentity();
9622 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009623 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9624 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9625 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9626 return carrierUAProfUrl;
9627 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009628 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9629 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009630 } finally {
9631 Binder.restoreCallingIdentity(identity);
9632 }
9633 }
9634
9635 @Override
9636 public String getMmsUserAgent(int subId) {
9637 //TODO investigate if this API should require proper permission check in R b/133791609
9638 final long identity = Binder.clearCallingIdentity();
9639 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009640 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9641 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9642 if (!TextUtils.isEmpty(carrierUserAgent)) {
9643 return carrierUserAgent;
9644 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009645 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9646 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009647 } finally {
9648 Binder.restoreCallingIdentity(identity);
9649 }
9650 }
Jack Yub07d4972019-05-28 16:12:25 -07009651
9652 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009653 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9654 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009655
Jack Yub07d4972019-05-28 16:12:25 -07009656 final long identity = Binder.clearCallingIdentity();
9657 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009658 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009659 if (phone == null) return false;
9660
Hall Liua62f5da2020-09-25 10:42:19 -07009661 switch (policy) {
9662 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9663 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9664 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9665 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9666 default:
9667 throw new IllegalArgumentException(policy + " is not a valid policy");
9668 }
Jack Yub07d4972019-05-28 16:12:25 -07009669 } finally {
9670 Binder.restoreCallingIdentity(identity);
9671 }
9672 }
9673
9674 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009675 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009676 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009677 enforceModifyPermission();
9678
changbettyd5c246e2019-12-24 15:40:37 +08009679 final long identity = Binder.clearCallingIdentity();
9680 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009681 Phone phone = getPhone(subscriptionId);
9682 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009683
Hall Liua62f5da2020-09-25 10:42:19 -07009684 switch (policy) {
9685 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9686 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9687 break;
9688 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9689 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9690 break;
9691 default:
9692 throw new IllegalArgumentException(policy + " is not a valid policy");
9693 }
changbettyd5c246e2019-12-24 15:40:37 +08009694 } finally {
9695 Binder.restoreCallingIdentity(identity);
9696 }
9697 }
9698
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009699 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009700 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009701 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9702 * otherwise.
9703 */
9704 @Override
9705 public void setCepEnabled(boolean isCepEnabled) {
9706 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9707
9708 final long identity = Binder.clearCallingIdentity();
9709 try {
9710 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9711 for (Phone phone : PhoneFactory.getPhones()) {
9712 Phone defaultPhone = phone.getImsPhone();
9713 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9714 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9715 ImsPhoneCallTracker imsPhoneCallTracker =
9716 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9717 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9718 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9719 + imsPhone.getMsisdn());
9720 }
9721 }
9722 } finally {
9723 Binder.restoreCallingIdentity(identity);
9724 }
9725 }
allenwtsu46dcc572020-01-08 18:24:03 +08009726
9727 /**
9728 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9729 *
9730 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9731 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9732 * before being read.
9733 */
9734 @Override
9735 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9736 isCompressed) {
9737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9738 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009739 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9740 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9741 }
9742 if (!isImsAvailableOnDevice()) {
9743 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9744 "IMS not available on device.");
9745 }
9746
9747 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009748 try {
Hui Wang761a6682020-10-31 05:12:53 +00009749 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9750 } finally {
9751 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009752 }
9753 }
zoey chene02881a2019-12-30 16:11:23 +08009754
9755 @Override
9756 public boolean isIccLockEnabled(int subId) {
9757 enforceReadPrivilegedPermission("isIccLockEnabled");
9758
9759 // Now that all security checks passes, perform the operation as ourselves.
9760 final long identity = Binder.clearCallingIdentity();
9761 try {
9762 Phone phone = getPhone(subId);
9763 if (phone != null && phone.getIccCard() != null) {
9764 return phone.getIccCard().getIccLockEnabled();
9765 } else {
9766 return false;
9767 }
9768 } finally {
9769 Binder.restoreCallingIdentity(identity);
9770 }
9771 }
9772
9773 /**
9774 * Set the ICC pin lock enabled or disabled.
9775 *
9776 * @return an integer representing the status of IccLock enabled or disabled in the following
9777 * three cases:
9778 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9779 * successfully.
9780 * - Positive number and zero for remaining password attempts.
9781 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9782 *
9783 */
9784 @Override
9785 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9786 enforceModifyPermission();
9787
9788 Phone phone = getPhone(subId);
9789 if (phone == null) {
9790 return 0;
9791 }
9792 // Now that all security checks passes, perform the operation as ourselves.
9793 final long identity = Binder.clearCallingIdentity();
9794 try {
9795 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9796 new Pair<Boolean, String>(enabled, password), phone, null);
9797 return attemptsRemaining;
9798
9799 } catch (Exception e) {
9800 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9801 } finally {
9802 Binder.restoreCallingIdentity(identity);
9803 }
9804 return 0;
9805 }
9806
9807 /**
9808 * Change the ICC password used in ICC pin lock.
9809 *
9810 * @return an integer representing the status of IccLock changed in the following three cases:
9811 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9812 * - Positive number and zero for remaining password attempts.
9813 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9814 *
9815 */
9816 @Override
9817 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9818 enforceModifyPermission();
9819
9820 Phone phone = getPhone(subId);
9821 if (phone == null) {
9822 return 0;
9823 }
9824 // Now that all security checks passes, perform the operation as ourselves.
9825 final long identity = Binder.clearCallingIdentity();
9826 try {
9827 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9828 new Pair<String, String>(oldPassword, newPassword), phone, null);
9829 return attemptsRemaining;
9830
9831 } catch (Exception e) {
9832 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9833 } finally {
9834 Binder.restoreCallingIdentity(identity);
9835 }
9836 return 0;
9837 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009838
9839 /**
9840 * Request for receiving user activity notification
9841 */
9842 @Override
9843 public void requestUserActivityNotification() {
9844 if (!mNotifyUserActivity.get()
9845 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9846 mNotifyUserActivity.set(true);
9847 }
9848 }
9849
9850 /**
9851 * Called when userActivity is signalled in the power manager.
9852 * This is safe to call from any thread, with any window manager locks held or not.
9853 */
9854 @Override
9855 public void userActivity() {
9856 // ***************************************
9857 // * Inherited from PhoneWindowManager *
9858 // ***************************************
9859 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9860 // WITH ITS LOCKS HELD.
9861 //
9862 // This code must be VERY careful about the locks
9863 // it acquires.
9864 // In fact, the current code acquires way too many,
9865 // and probably has lurking deadlocks.
9866
9867 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9868 throw new SecurityException("Only the OS may call notifyUserActivity()");
9869 }
9870
9871 if (mNotifyUserActivity.getAndSet(false)) {
9872 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9873 USER_ACTIVITY_NOTIFICATION_DELAY);
9874 }
9875 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009876
9877 @Override
9878 public boolean canConnectTo5GInDsdsMode() {
9879 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9880 }
Jack Yud10cdd42020-09-28 20:28:01 -07009881
9882 @Override
9883 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9884 String callingFeatureId) {
9885 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9886 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9887 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9888 }
9889
9890 Phone phone = getPhone(subId);
9891 if (phone == null) {
9892 throw new RuntimeException("phone is not available");
9893 }
9894 // Now that all security checks passes, perform the operation as ourselves.
9895 final long identity = Binder.clearCallingIdentity();
9896 try {
9897 return phone.getEquivalentHomePlmns();
9898 } finally {
9899 Binder.restoreCallingIdentity(identity);
9900 }
9901 }
Daniel Bright59e67312020-11-13 11:49:37 -08009902
9903 @Override
9904 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009905 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9906 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009907 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009908 if (radioInterfaceCapabilities == null) {
9909 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009910 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009911 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009912 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009913
Hui Wang641e81c2020-10-12 12:14:23 -07009914 @Override
9915 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9916 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009917 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9918 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9919 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9920 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9921 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009922 if (DBG) {
9923 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9924 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9925 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9926 }
9927
9928 if (!SubscriptionManager.isValidSubscriptionId(subId)
9929 || appType < TelephonyManager.APPTYPE_UNKNOWN
9930 || appType > TelephonyManager.APPTYPE_ISIM
9931 || nafUrl == null || securityProtocol == null || callback == null) {
9932 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9933 if (callback != null) {
9934 try {
9935 callback.onAuthenticationFailure(
9936 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9937 } catch (RemoteException exception) {
9938 log("Fail to notify onAuthenticationFailure due to " + exception);
9939 }
9940 return;
9941 }
9942 }
9943
9944 final long token = Binder.clearCallingIdentity();
9945 try {
9946 getGbaManager(subId).bootstrapAuthenticationRequest(
9947 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9948 forceBootStrapping, callback));
9949 } finally {
9950 Binder.restoreCallingIdentity(token);
9951 }
9952 }
9953
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009954 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009955 * Attempts to set the radio power state for all phones for thermal reason.
9956 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009957 * requested radio power state will actually be set. See {@link
9958 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9959 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009960 * @param enable {@code true} if trying to turn radio on.
9961 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9962 * false}.
9963 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009964 private boolean setRadioPowerForThermal(boolean enable) {
9965 boolean isPhoneAvailable = false;
9966 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9967 Phone phone = PhoneFactory.getPhone(i);
9968 if (phone != null) {
9969 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9970 isPhoneAvailable = true;
9971 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009972 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009973
9974 // return true if successfully informed the phone object about the thermal radio power
9975 // request.
9976 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009977 }
9978
9979 private int handleDataThrottlingRequest(int subId,
9980 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009981 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9982 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9983 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9984 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9985 throw new IllegalArgumentException("modem does not support data throttling");
9986 }
9987
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009988 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9989 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009990 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009991 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9992 }
9993
9994 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9995
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009996 if (isDataThrottlingSupported) {
9997 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009998 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009999 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10000 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10001 } else if (thermalMitigationResult
10002 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010003 log("Modem likely does not support data throttling on secondary carrier. Data " +
10004 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10005 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010006 }
10007 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010008 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010009
10010 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010011 }
10012
Jack Nudelman644b91a2021-03-12 14:09:48 -080010013 private static List<String> getThermalMitigationAllowlist(Context context) {
10014 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10015 for (String pckg : context.getResources()
10016 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10017 sThermalMitigationAllowlistedPackages.add(pckg);
10018 }
10019 }
10020
10021 return sThermalMitigationAllowlistedPackages;
10022 }
10023
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010024 private boolean isAnyPhoneInEmergencyState() {
10025 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10026 if (tm.isInEmergencyCall()) {
10027 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10028 return true;
10029 }
10030 for (Phone phone : PhoneFactory.getPhones()) {
10031 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10032 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10033 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10034 + phone.isInEcm());
10035 return true;
10036 }
10037 }
10038
10039 return false;
10040 }
10041
Jack Nudelman644b91a2021-03-12 14:09:48 -080010042 /**
10043 * Used by shell commands to add an authorized package name for thermal mitigation.
10044 * @param packageName name of package to be allowlisted
10045 * @param context
10046 */
10047 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10048 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10049 sThermalMitigationAllowlistedPackages.add(packageName);
10050 }
10051
10052 /**
10053 * Used by shell commands to remove an authorized package name for thermal mitigation.
10054 * @param packageName name of package to remove from allowlist
10055 * @param context
10056 */
10057 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10058 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10059 sThermalMitigationAllowlistedPackages.remove(packageName);
10060 }
10061
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010062 /**
10063 * Thermal mitigation request to control functionalities at modem.
10064 *
10065 * @param subId the id of the subscription.
10066 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010067 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010068 *
10069 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10070 */
10071 @Override
10072 @ThermalMitigationResult
10073 public int sendThermalMitigationRequest(
10074 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010075 ThermalMitigationRequest thermalMitigationRequest,
10076 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010077 enforceModifyPermission();
10078
Jack Nudelman644b91a2021-03-12 14:09:48 -080010079 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10080 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10081 .contains(callingPackage)) {
10082 throw new SecurityException("Calling package must be configured in the device config. "
10083 + "calling package: " + callingPackage);
10084 }
10085
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010086 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10087 final long identity = Binder.clearCallingIdentity();
10088
10089 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10090 try {
10091 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10092 switch (thermalMitigationAction) {
10093 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10094 thermalMitigationResult =
10095 handleDataThrottlingRequest(subId,
10096 thermalMitigationRequest.getDataThrottlingRequest());
10097 break;
10098 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10099 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10100 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10101 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10102 }
10103
10104 // Ensure that radio is on. If not able to power on due to phone being
10105 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010106 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010107 thermalMitigationResult =
10108 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10109 break;
10110 }
10111
10112 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10113 false);
10114 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10115 break;
10116 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10117 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10118 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10119 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10120 }
10121
10122 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10123 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010124 Phone phone = getPhone(subId);
10125 if (phone == null) {
10126 thermalMitigationResult =
10127 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10128 break;
10129 }
10130
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010131 TelephonyConnectionService service =
10132 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010133 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010134 Log.e(LOG_TAG, "An emergency call is pending");
10135 thermalMitigationResult =
10136 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10137 break;
10138 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010139 thermalMitigationResult =
10140 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10141 break;
10142 }
10143 } else {
10144 thermalMitigationResult =
10145 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10146 break;
10147 }
10148
10149 // Turn radio off. If not able to power off due to phone being unavailable,
10150 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010151 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010152 thermalMitigationResult =
10153 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10154 break;
10155 }
10156 thermalMitigationResult =
10157 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10158 break;
10159 default:
10160 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10161 + "not exist. Requested action: " + thermalMitigationAction);
10162 }
10163 } catch (IllegalArgumentException e) {
10164 throw e;
10165 } catch (Exception e) {
10166 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10167 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10168 } finally {
10169 Binder.restoreCallingIdentity(identity);
10170 }
10171
10172 if (DBG) {
10173 log("thermalMitigationRequest returning with thermalMitigationResult: "
10174 + thermalMitigationResult);
10175 }
10176
10177 return thermalMitigationResult;
10178 }
Hui Wang641e81c2020-10-12 12:14:23 -070010179
10180 /**
10181 * Set the GbaService Package Name that Telephony will bind to.
10182 *
10183 * @param subId The sim that the GbaService is associated with.
10184 * @param packageName The name of the package to be replaced with.
10185 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10186 */
10187 @Override
10188 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10189 enforceModifyPermission();
10190
10191 final long identity = Binder.clearCallingIdentity();
10192 try {
10193 return getGbaManager(subId).overrideServicePackage(packageName);
10194 } finally {
10195 Binder.restoreCallingIdentity(identity);
10196 }
10197 }
10198
10199 /**
10200 * Return the package name of the currently bound GbaService.
10201 *
10202 * @param subId The sim that the GbaService is associated with.
10203 * @return the package name of the GbaService configuration, null if GBA is not supported.
10204 */
10205 @Override
10206 public String getBoundGbaService(int subId) {
10207 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10208
10209 final long identity = Binder.clearCallingIdentity();
10210 try {
10211 return getGbaManager(subId).getServicePackage();
10212 } finally {
10213 Binder.restoreCallingIdentity(identity);
10214 }
10215 }
10216
10217 /**
10218 * Set the release time for telephony to unbind GbaService.
10219 *
10220 * @param subId The sim that the GbaService is associated with.
10221 * @param interval The release time to unbind GbaService by millisecond.
10222 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10223 */
10224 @Override
10225 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10226 enforceModifyPermission();
10227
10228 final long identity = Binder.clearCallingIdentity();
10229 try {
10230 return getGbaManager(subId).overrideReleaseTime(interval);
10231 } finally {
10232 Binder.restoreCallingIdentity(identity);
10233 }
10234 }
10235
10236 /**
10237 * Return the release time for telephony to unbind GbaService.
10238 *
10239 * @param subId The sim that the GbaService is associated with.
10240 * @return The release time to unbind GbaService by millisecond.
10241 */
10242 @Override
10243 public int getGbaReleaseTime(int subId) {
10244 enforceReadPrivilegedPermission("getGbaReleaseTime");
10245
10246 final long identity = Binder.clearCallingIdentity();
10247 try {
10248 return getGbaManager(subId).getReleaseTime();
10249 } finally {
10250 Binder.restoreCallingIdentity(identity);
10251 }
10252 }
10253
10254 private GbaManager getGbaManager(int subId) {
10255 GbaManager instance = GbaManager.getInstance(subId);
10256 if (instance == null) {
10257 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10258 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10259 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10260 }
10261 return instance;
10262 }
Hui Wang761a6682020-10-31 05:12:53 +000010263
10264 /**
10265 * indicate whether the device and the carrier can support
10266 * RCS VoLTE single registration.
10267 */
10268 @Override
10269 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010270 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10271 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10272 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10273 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010274
10275 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10276 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10277 }
10278
10279 final long identity = Binder.clearCallingIdentity();
10280 try {
10281 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10282 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010283 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10284 if (isCapable != null) {
10285 return isCapable;
10286 }
Hui Wang761a6682020-10-31 05:12:53 +000010287 }
Hui Wang67af90e2021-06-04 16:57:15 -070010288 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10289 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010290 } finally {
10291 Binder.restoreCallingIdentity(identity);
10292 }
10293 }
10294
10295 /**
10296 * Register RCS provisioning callback.
10297 */
10298 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010299 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010300 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010301 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010302 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010303 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10304 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010305
10306 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10307 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10308 }
10309 if (!isImsAvailableOnDevice()) {
10310 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10311 "IMS not available on device.");
10312 }
10313
10314 final long identity = Binder.clearCallingIdentity();
10315 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010316 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010317 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010318 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10319 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010320 }
Hui Wang761a6682020-10-31 05:12:53 +000010321 } finally {
10322 Binder.restoreCallingIdentity(identity);
10323 }
10324 }
10325
10326 /**
10327 * Unregister RCS provisioning callback.
10328 */
10329 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010330 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010331 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010332 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010333 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010334 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10335 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010336
10337 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10338 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10339 }
10340 if (!isImsAvailableOnDevice()) {
10341 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10342 "IMS not available on device.");
10343 }
10344
10345 final long identity = Binder.clearCallingIdentity();
10346 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010347 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010348 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010349 } finally {
10350 Binder.restoreCallingIdentity(identity);
10351 }
10352 }
10353
10354 /**
10355 * trigger RCS reconfiguration.
10356 */
10357 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010358 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10359 "triggerRcsReconfiguration",
10360 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010361
10362 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10363 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10364 }
10365 if (!isImsAvailableOnDevice()) {
10366 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10367 "IMS not available on device.");
10368 }
10369
10370 final long identity = Binder.clearCallingIdentity();
10371 try {
10372 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10373 } finally {
10374 Binder.restoreCallingIdentity(identity);
10375 }
10376 }
10377
10378 /**
10379 * Provide the client configuration parameters of the RCS application.
10380 */
10381 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010382 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10383 "setRcsClientConfiguration",
10384 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010385
10386 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10387 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10388 }
10389 if (!isImsAvailableOnDevice()) {
10390 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10391 "IMS not available on device.");
10392 }
10393
10394 final long identity = Binder.clearCallingIdentity();
10395
10396 try {
10397 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10398 if (configBinder == null) {
10399 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010400 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10401 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010402 } else {
10403 configBinder.setRcsClientConfiguration(rcc);
10404 }
10405 } catch (RemoteException e) {
10406 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010407 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10408 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010409 } finally {
10410 Binder.restoreCallingIdentity(identity);
10411 }
10412 }
10413
10414 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010415 * Enables or disables the test mode for RCS VoLTE single registration.
10416 */
10417 @Override
10418 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10419 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10420 "setRcsSingleRegistrationTestModeEnabled");
10421
10422 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10423 }
10424
10425 /**
10426 * Gets the test mode for RCS VoLTE single registration.
10427 */
10428 @Override
10429 public boolean getRcsSingleRegistrationTestModeEnabled() {
10430 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10431 "getRcsSingleRegistrationTestModeEnabled");
10432
10433 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10434 }
10435
10436 /**
Hui Wang761a6682020-10-31 05:12:53 +000010437 * Overrides the config of RCS VoLTE single registration enabled for the device.
10438 */
10439 @Override
10440 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10441 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10442 "setDeviceSingleRegistrationEnabledOverride");
10443 enforceModifyPermission();
10444
10445 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10446 : Boolean.parseBoolean(enabledStr);
10447 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010448 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010449 }
10450
10451 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010452 * Sends a device to device communication message. Only usable via shell.
10453 * @param message message to send.
10454 * @param value message value.
10455 */
10456 @Override
10457 public void sendDeviceToDeviceMessage(int message, int value) {
10458 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010459 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010460 enforceModifyPermission();
10461
10462 final long identity = Binder.clearCallingIdentity();
10463 try {
10464 TelephonyConnectionService service =
10465 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10466 if (service == null) {
10467 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10468 return;
10469 }
10470 service.sendTestDeviceToDeviceMessage(message, value);
10471 } finally {
10472 Binder.restoreCallingIdentity(identity);
10473 }
10474 }
10475
Tyler Gunnbabbda02021-02-10 11:05:02 -080010476 /**
10477 * Sets the specified device to device transport active.
10478 * @param transport The transport to set active.
10479 */
10480 @Override
10481 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10482 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10483 "setActiveDeviceToDeviceTransport");
10484 enforceModifyPermission();
10485
10486 final long identity = Binder.clearCallingIdentity();
10487 try {
10488 TelephonyConnectionService service =
10489 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10490 if (service == null) {
10491 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10492 return;
10493 }
10494 service.setActiveDeviceToDeviceTransport(transport);
10495 } finally {
10496 Binder.restoreCallingIdentity(identity);
10497 }
10498 }
Tyler Gunn92479152021-01-20 16:30:10 -080010499
Tyler Gunnd4339262021-05-03 14:46:49 -070010500 @Override
10501 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10502 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10503 "setDeviceToDeviceForceEnabled");
10504
10505 final long identity = Binder.clearCallingIdentity();
10506 try {
10507 Arrays.stream(PhoneFactory.getPhones()).forEach(
10508 p -> {
10509 Phone thePhone = p.getImsPhone();
10510 if (thePhone != null && thePhone instanceof ImsPhone) {
10511 ImsPhone imsPhone = (ImsPhone) thePhone;
10512 CallTracker tracker = imsPhone.getCallTracker();
10513 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10514 ImsPhoneCallTracker imsPhoneCallTracker =
10515 (ImsPhoneCallTracker) tracker;
10516 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10517 }
10518 }
10519 }
10520 );
10521 } finally {
10522 Binder.restoreCallingIdentity(identity);
10523 }
10524 }
10525
Tyler Gunn92479152021-01-20 16:30:10 -080010526 /**
Hui Wang761a6682020-10-31 05:12:53 +000010527 * Gets the config of RCS VoLTE single registration enabled for the device.
10528 */
10529 @Override
10530 public boolean getDeviceSingleRegistrationEnabled() {
10531 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10532 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10533 }
10534
10535 /**
10536 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10537 */
10538 @Override
10539 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10540 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10541 "setCarrierSingleRegistrationEnabledOverride");
10542 enforceModifyPermission();
10543
10544 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10545 : Boolean.parseBoolean(enabledStr);
10546 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10547 subId, enabled);
10548 }
10549
10550 /**
10551 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10552 */
10553 @Override
10554 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10555 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10556 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10557 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010558
10559 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010560 * Overrides the ims feature validation result
10561 */
10562 @Override
10563 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10564 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10565 "setImsFeatureValidationOverride");
10566
10567 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10568 : Boolean.parseBoolean(enabledStr);
10569 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10570 subId, enabled);
10571 }
10572
10573 /**
10574 * Gets the ims feature validation override value
10575 */
10576 @Override
10577 public boolean getImsFeatureValidationOverride(int subId) {
10578 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10579 "getImsFeatureValidationOverride");
10580 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10581 }
10582
10583 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010584 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10585 * their mobile plan.
10586 */
10587 @Override
10588 public String getMobileProvisioningUrl() {
10589 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10590 final long identity = Binder.clearCallingIdentity();
10591 try {
10592 return getDefaultPhone().getMobileProvisioningUrl();
10593 } finally {
10594 Binder.restoreCallingIdentity(identity);
10595 }
10596 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010597
James.cf Linbcdf8b32021-01-14 16:44:13 +080010598 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010599 * Get the EAB contact from the EAB database.
10600 */
10601 @Override
10602 public String getContactFromEab(String contact) {
10603 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10604 enforceModifyPermission();
10605 final long identity = Binder.clearCallingIdentity();
10606 try {
10607 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10608 } finally {
10609 Binder.restoreCallingIdentity(identity);
10610 }
10611 }
10612
10613 /**
Calvin Pana1434322021-07-01 19:27:01 +080010614 * Get the EAB capability from the EAB database.
10615 */
10616 @Override
10617 public String getCapabilityFromEab(String contact) {
10618 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10619 enforceModifyPermission();
10620 final long identity = Binder.clearCallingIdentity();
10621 try {
10622 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10623 } finally {
10624 Binder.restoreCallingIdentity(identity);
10625 }
10626 }
10627
10628 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010629 * Remove the EAB contacts from the EAB database.
10630 */
10631 @Override
10632 public int removeContactFromEab(int subId, String contacts) {
10633 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10634 enforceModifyPermission();
10635 final long identity = Binder.clearCallingIdentity();
10636 try {
10637 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10638 } finally {
10639 Binder.restoreCallingIdentity(identity);
10640 }
10641 }
10642
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010643 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010644 public boolean getDeviceUceEnabled() {
10645 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10646 final long identity = Binder.clearCallingIdentity();
10647 try {
10648 return mApp.getDeviceUceEnabled();
10649 } finally {
10650 Binder.restoreCallingIdentity(identity);
10651 }
10652 }
10653
10654 @Override
10655 public void setDeviceUceEnabled(boolean isEnabled) {
10656 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10657 final long identity = Binder.clearCallingIdentity();
10658 try {
10659 mApp.setDeviceUceEnabled(isEnabled);
10660 } finally {
10661 Binder.restoreCallingIdentity(identity);
10662 }
10663 }
10664
Brad Ebinger14d467f2021-02-12 06:18:28 +000010665 /**
10666 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10667 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10668 */
10669 // Used for SHELL command only right now.
10670 @Override
10671 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10672 List<String> featureTags) {
10673 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10674 "addUceRegistrationOverrideShell");
10675 final long identity = Binder.clearCallingIdentity();
10676 try {
10677 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10678 new ArraySet<>(featureTags));
10679 } catch (ImsException e) {
10680 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10681 } finally {
10682 Binder.restoreCallingIdentity(identity);
10683 }
10684 }
10685
10686 /**
10687 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10688 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10689 */
10690 // Used for SHELL command only right now.
10691 @Override
10692 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10693 List<String> featureTags) {
10694 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10695 "removeUceRegistrationOverrideShell");
10696 final long identity = Binder.clearCallingIdentity();
10697 try {
10698 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10699 new ArraySet<>(featureTags));
10700 } catch (ImsException e) {
10701 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10702 } finally {
10703 Binder.restoreCallingIdentity(identity);
10704 }
10705 }
10706
10707 /**
10708 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10709 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10710 */
10711 // Used for SHELL command only right now.
10712 @Override
10713 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10714 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10715 "clearUceRegistrationOverrideShell");
10716 final long identity = Binder.clearCallingIdentity();
10717 try {
10718 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10719 } catch (ImsException e) {
10720 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10721 } finally {
10722 Binder.restoreCallingIdentity(identity);
10723 }
10724 }
10725
10726 /**
10727 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10728 */
10729 // Used for SHELL command only right now.
10730 @Override
10731 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10732 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10733 "getLatestRcsContactUceCapabilityShell");
10734 final long identity = Binder.clearCallingIdentity();
10735 try {
10736 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10737 } catch (ImsException e) {
10738 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10739 } finally {
10740 Binder.restoreCallingIdentity(identity);
10741 }
10742 }
10743
10744 /**
10745 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10746 * device does not have an active PUBLISH.
10747 */
10748 // Used for SHELL command only right now.
10749 @Override
10750 public String getLastUcePidfXmlShell(int subId) {
10751 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10752 final long identity = Binder.clearCallingIdentity();
10753 try {
10754 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10755 } catch (ImsException e) {
10756 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10757 } finally {
10758 Binder.restoreCallingIdentity(identity);
10759 }
10760 }
10761
James.cf Line8713a42021-04-29 16:04:26 +080010762 /**
10763 * Remove UCE requests cannot be sent to the network status.
10764 */
10765 // Used for SHELL command only right now.
10766 @Override
10767 public boolean removeUceRequestDisallowedStatus(int subId) {
10768 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10769 final long identity = Binder.clearCallingIdentity();
10770 try {
10771 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10772 } catch (ImsException e) {
10773 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10774 } finally {
10775 Binder.restoreCallingIdentity(identity);
10776 }
10777 }
10778
James.cf Lin18bb9002021-05-25 01:37:38 +080010779 /**
10780 * Remove UCE requests cannot be sent to the network status.
10781 */
10782 // Used for SHELL command only.
10783 @Override
10784 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10785 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10786 final long identity = Binder.clearCallingIdentity();
10787 try {
10788 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10789 } catch (ImsException e) {
10790 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10791 } finally {
10792 Binder.restoreCallingIdentity(identity);
10793 }
10794 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010795
James.cf Lin4b784aa2021-01-31 03:25:15 +080010796 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010797 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10798 String callingPackage) {
10799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10800 mApp, subId, "setSignalStrengthUpdateRequest");
10801
10802 final int callingUid = Binder.getCallingUid();
10803 // Verify that tha callingPackage belongs to the calling UID
10804 mApp.getSystemService(AppOpsManager.class)
10805 .checkPackage(callingUid, callingPackage);
10806
10807 validateSignalStrengthUpdateRequest(request, callingUid);
10808
10809 final long identity = Binder.clearCallingIdentity();
10810 try {
10811 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10812 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10813
10814 if (result instanceof IllegalStateException) {
10815 throw (IllegalStateException) result;
10816 }
10817 } finally {
10818 Binder.restoreCallingIdentity(identity);
10819 }
10820 }
10821
10822 @Override
10823 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10824 String callingPackage) {
10825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10826 mApp, subId, "clearSignalStrengthUpdateRequest");
10827
10828 final int callingUid = Binder.getCallingUid();
10829 // Verify that tha callingPackage belongs to the calling UID
10830 mApp.getSystemService(AppOpsManager.class)
10831 .checkPackage(callingUid, callingPackage);
10832
10833 final long identity = Binder.clearCallingIdentity();
10834 try {
10835 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10836 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10837
10838 if (result instanceof IllegalStateException) {
10839 throw (IllegalStateException) result;
10840 }
10841 } finally {
10842 Binder.restoreCallingIdentity(identity);
10843 }
10844 }
10845
10846 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10847 int callingUid) {
10848 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10849 // phone/system process do not have further restriction on request
10850 return;
10851 }
10852
10853 // Applications has restrictions on how to use the request:
10854 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10855 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10856 // This is not system caller which has been checked above
10857 throw new IllegalArgumentException(
10858 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10859 }
10860
10861 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10862 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10863 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10864 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10865 || info.isEnabled()) {
10866 throw new IllegalArgumentException(
10867 "Only system can set hide fields in SignalThresholdInfo");
10868 }
10869
10870 // Thresholds length for each RAN need in range. This has been validated in
10871 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10872 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10873 final int[] thresholds = info.getThresholds();
10874 Objects.requireNonNull(thresholds);
10875 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10876 || thresholds.length
10877 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10878 throw new IllegalArgumentException(
10879 "thresholds length is out of range: " + thresholds.length);
10880 }
10881 }
10882 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010883
10884 /**
10885 * Gets the current phone capability.
10886 *
10887 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10888 * @return the PhoneCapability which describes the data connection capability of modem.
10889 * It's used to evaluate possible phone config change, for example from single
10890 * SIM device to multi-SIM device.
10891 */
10892 @Override
10893 public PhoneCapability getPhoneCapability() {
10894 enforceReadPrivilegedPermission("getPhoneCapability");
10895 final long identity = Binder.clearCallingIdentity();
10896 try {
10897 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10898 } finally {
10899 Binder.restoreCallingIdentity(identity);
10900 }
10901 }
Michele Berionne5e411512020-11-13 02:36:59 +000010902
10903 /**
10904 * Prepare TelephonyManager for an unattended reboot. The reboot is
10905 * required to be done shortly after the API is invoked.
10906 */
10907 @Override
10908 @TelephonyManager.PrepareUnattendedRebootResult
10909 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010910 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000010911 enforceRebootPermission();
10912
10913 final long identity = Binder.clearCallingIdentity();
10914 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010915 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000010916 } finally {
10917 Binder.restoreCallingIdentity(identity);
10918 }
10919 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010920
10921 /**
10922 * Request to get the current slicing configuration including URSP rules and
10923 * NSSAIs (configured, allowed and rejected).
10924 *
10925 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10926 */
10927 @Override
10928 public void getSlicingConfig(ResultReceiver callback) {
10929 enforceReadPrivilegedPermission("getSlicingConfig");
10930
10931 final long identity = Binder.clearCallingIdentity();
10932 try {
10933 Phone phone = getDefaultPhone();
10934 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10935 } finally {
10936 Binder.restoreCallingIdentity(identity);
10937 }
10938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010939}