blob: 274b3011a3658594a804f23d527a3463e9523761 [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;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700189import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800190import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000192import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800193import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000194import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800195import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700196import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700197import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800198import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800199import com.android.phone.callcomposer.CallComposerPictureManager;
200import com.android.phone.callcomposer.CallComposerPictureTransfer;
201import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700202import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700203import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800204import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700205import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700206import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800207import com.android.services.telephony.TelecomAccountRegistry;
208import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800209import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800210
Hall Liu82694d52020-12-11 18:22:04 -0800211import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700212import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800213import java.io.IOException;
214import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700215import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800217import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800218import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800219import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800220import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100221import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800222import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700223import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800225import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800226import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800227import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800228import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229
230/**
231 * Implementation of the ITelephony interface.
232 */
Santos Cordon117fee72014-05-16 17:56:12 -0700233public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234 private static final String LOG_TAG = "PhoneInterfaceManager";
235 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
236 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800237 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238
239 // Message codes used with mMainThreadHandler
240 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700241 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
242 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700243 private static final int CMD_OPEN_CHANNEL = 9;
244 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
245 private static final int CMD_CLOSE_CHANNEL = 11;
246 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800247 private static final int CMD_NV_READ_ITEM = 13;
248 private static final int EVENT_NV_READ_ITEM_DONE = 14;
249 private static final int CMD_NV_WRITE_ITEM = 15;
250 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
251 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
252 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700253 private static final int CMD_RESET_MODEM_CONFIG = 19;
254 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800255 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
256 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800257 private static final int CMD_SEND_ENVELOPE = 25;
258 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000259 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
260 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700261 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
262 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
263 private static final int CMD_EXCHANGE_SIM_IO = 31;
264 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800265 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
266 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700267 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
268 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700269 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
270 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700271 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
272 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
273 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
274 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700275 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
276 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
277 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
278 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700279 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800280 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
281 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000282 private static final int CMD_SWITCH_SLOTS = 50;
283 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700284 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
285 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
286 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
287 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
288 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
289 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
290 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
291 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700292 private static final int CMD_GET_ALL_CELL_INFO = 60;
293 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
294 private static final int CMD_GET_CELL_LOCATION = 62;
295 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700296 private static final int CMD_MODEM_REBOOT = 64;
297 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700298 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
299 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800300 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
301 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700302 private static final int CMD_GET_MODEM_STATUS = 70;
303 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700304 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
305 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700306 private static final int CMD_ERASE_MODEM_CONFIG = 74;
307 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800308 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
309 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
310 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
311 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800312 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
313 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800314 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800315 private static final int CMD_GET_CALL_FORWARDING = 83;
316 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
317 private static final int CMD_SET_CALL_FORWARDING = 85;
318 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
319 private static final int CMD_GET_CALL_WAITING = 87;
320 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
321 private static final int CMD_SET_CALL_WAITING = 89;
322 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700323 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
324 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
325 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
326 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700327 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
328 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800329 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
330 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800331 private static final int CMD_SET_DATA_THROTTLING = 99;
332 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800333 private static final int CMD_SET_SIM_POWER = 101;
334 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800335 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
336 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
337 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
338 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800339 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
340 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000341 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800342 private static final int CMD_GET_SLICING_CONFIG = 110;
343 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800344 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700345 private static final int CMD_ENABLE_VONR = 113;
346 private static final int EVENT_ENABLE_VONR_DONE = 114;
347 private static final int CMD_IS_VONR_ENABLED = 115;
348 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800350 // Parameters of select command.
351 private static final int SELECT_COMMAND = 0xA4;
352 private static final int SELECT_P1 = 0x04;
353 private static final int SELECT_P2 = 0;
354 private static final int SELECT_P3 = 0x10;
355
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 /** The singleton instance. */
357 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800358 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359
Wink Saville3ab207e2014-11-20 13:07:20 -0800360 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800361 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800362 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700363 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800364 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700365 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800366 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800367 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800368 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700369 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800370 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
Peter Wangdafb9ac2020-01-15 14:13:38 -0800372 /** User Activity */
373 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800374 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
375
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700376 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
377
Derek Tan97ebb422014-09-05 16:55:38 -0700378 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
379 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800380 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800381 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700382
Michelecea4cf22018-12-21 15:00:11 -0800383 // String to store multi SIM allowed
384 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
385
Derek Tan740e1672017-06-27 14:56:27 -0700386 // The AID of ISD-R.
387 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
388
yinxub1bed742017-04-17 11:45:04 -0700389 private NetworkScanRequestTracker mNetworkScanRequestTracker;
390
David Kelly5e06a7f2018-03-12 14:10:59 +0000391 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
392 private static final int MANUFACTURER_CODE_LENGTH = 8;
393
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800394 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800395 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800396
Derek Tan89e89d42014-07-08 17:00:10 -0700397 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700398 * Experiment flag to enable erase modem config on reset network, default value is false
399 */
400 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
401 "reset_network_erase_modem_config_enabled";
402
Rambo Wang0f050d82021-02-12 11:43:36 -0800403 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
404
Naina Nallurid63128d2019-09-17 14:10:30 -0700405 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700406 * A request object to use for transmitting data to an ICC.
407 */
408 private static final class IccAPDUArgument {
409 public int channel, cla, command, p1, p2, p3;
410 public String data;
411
412 public IccAPDUArgument(int channel, int cla, int command,
413 int p1, int p2, int p3, String data) {
414 this.channel = channel;
415 this.cla = cla;
416 this.command = command;
417 this.p1 = p1;
418 this.p2 = p2;
419 this.p3 = p3;
420 this.data = data;
421 }
422 }
423
424 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700425 * A request object to use for transmitting data to an ICC.
426 */
427 private static final class ManualNetworkSelectionArgument {
428 public OperatorInfo operatorInfo;
429 public boolean persistSelection;
430
431 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
432 this.operatorInfo = operatorInfo;
433 this.persistSelection = persistSelection;
434 }
435 }
436
437 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
439 * request after sending. The main thread will notify the request when it is complete.
440 */
441 private static final class MainThreadRequest {
442 /** The argument to use for the request */
443 public Object argument;
444 /** The result of the request that is run on the main thread */
445 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800446 // The subscriber id that this request applies to. Defaults to
447 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
448 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449
Nathan Harold92bed182018-10-12 18:16:49 -0700450 // In cases where subId is unavailable, the caller needs to specify the phone.
451 public Phone phone;
452
vagdeviaf9a5b92018-08-15 16:01:53 -0700453 public WorkSource workSource;
454
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 public MainThreadRequest(Object argument) {
456 this.argument = argument;
457 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800458
Nathan Harold92bed182018-10-12 18:16:49 -0700459 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
460 this.argument = argument;
461 if (phone != null) {
462 this.phone = phone;
463 }
464 this.workSource = workSource;
465 }
466
vagdeviaf9a5b92018-08-15 16:01:53 -0700467 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800468 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800469 if (subId != null) {
470 this.subId = subId;
471 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700472 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 }
475
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800476 private static final class IncomingThirdPartyCallArgs {
477 public final ComponentName component;
478 public final String callId;
479 public final String callerDisplayName;
480
481 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
482 String callerDisplayName) {
483 this.component = component;
484 this.callId = callId;
485 this.callerDisplayName = callerDisplayName;
486 }
487 }
488
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700489 /**
490 * A handler that processes messages on the main thread in the phone process. Since many
491 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
492 * inbound binder threads to the main thread in the phone process. The Binder thread
493 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
494 * on, which will be notified when the operation completes and will contain the result of the
495 * request.
496 *
497 * <p>If a MainThreadRequest object is provided in the msg.obj field,
498 * note that request.result must be set to something non-null for the calling thread to
499 * unblock.
500 */
501 private final class MainThreadHandler extends Handler {
502 @Override
503 public void handleMessage(Message msg) {
504 MainThreadRequest request;
505 Message onCompleted;
506 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000507 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800509 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510
511 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 case CMD_HANDLE_USSD_REQUEST: {
513 request = (MainThreadRequest) msg.obj;
514 final Phone phone = getPhoneFromRequest(request);
515 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
516 String ussdRequest = ussdObject.first;
517 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700518
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 if (!isUssdApiAllowed(request.subId)) {
520 // Carrier does not support use of this API, return failure.
521 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
522 UssdResponse response = new UssdResponse(ussdRequest, null);
523 Bundle returnData = new Bundle();
524 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
525 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700526
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 request.result = true;
528 notifyRequester(request);
529 return;
530 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700531
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 try {
533 request.result = phone != null
534 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
535 } catch (CallStateException cse) {
536 request.result = false;
537 }
538 // Wake up the requesting thread
539 notifyRequester(request);
540 break;
pkanwar32d516d2016-10-14 19:37:38 -0700541 }
542
Yorke Lee716f67e2015-06-17 15:39:16 -0700543 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700545 final Phone phone = getPhoneFromRequest(request);
546 request.result = phone != null ?
547 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
548 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700549 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700553
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700554 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000557 uiccPort = getUiccPortFromRequest(request);
558 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700559 loge("iccTransmitApduLogicalChannel: No UICC");
560 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700561 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
564 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000565 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 iccArgument.channel, iccArgument.cla, iccArgument.command,
567 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 break;
571
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 ar = (AsyncResult) msg.obj;
574 request = (MainThreadRequest) ar.userObj;
575 if (ar.exception == null && ar.result != null) {
576 request.result = ar.result;
577 } else {
578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
579 if (ar.result == null) {
580 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800581 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800583 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 } else {
585 loge("iccTransmitApduLogicalChannel: Unknown exception");
586 }
587 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 break;
590
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
592 request = (MainThreadRequest) msg.obj;
593 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000594 uiccPort = getUiccPortFromRequest(request);
595 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 loge("iccTransmitApduBasicChannel: No UICC");
597 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 } else {
600 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
601 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000602 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
604 iccArgument.p3, iccArgument.data, onCompleted);
605 }
606 break;
607
608 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
609 ar = (AsyncResult) msg.obj;
610 request = (MainThreadRequest) ar.userObj;
611 if (ar.exception == null && ar.result != null) {
612 request.result = ar.result;
613 } else {
614 request.result = new IccIoResult(0x6F, 0, (byte[])null);
615 if (ar.result == null) {
616 loge("iccTransmitApduBasicChannel: Empty response");
617 } else if (ar.exception instanceof CommandException) {
618 loge("iccTransmitApduBasicChannel: CommandException: " +
619 ar.exception);
620 } else {
621 loge("iccTransmitApduBasicChannel: Unknown exception");
622 }
623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 break;
626
627 case CMD_EXCHANGE_SIM_IO:
628 request = (MainThreadRequest) msg.obj;
629 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000630 uiccPort = getUiccPortFromRequest(request);
631 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 loge("iccExchangeSimIO: No UICC");
633 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 } else {
636 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
637 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000638 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
640 iccArgument.data, onCompleted);
641 }
642 break;
643
644 case EVENT_EXCHANGE_SIM_IO_DONE:
645 ar = (AsyncResult) msg.obj;
646 request = (MainThreadRequest) ar.userObj;
647 if (ar.exception == null && ar.result != null) {
648 request.result = ar.result;
649 } else {
650 request.result = new IccIoResult(0x6f, 0, (byte[])null);
651 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 break;
654
Derek Tan4d5e5c12014-02-04 11:54:58 -0800655 case CMD_SEND_ENVELOPE:
656 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000657 uiccPort = getUiccPortFromRequest(request);
658 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 loge("sendEnvelopeWithStatus: No UICC");
660 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700661 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700662 } else {
663 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000664 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700665 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800666 break;
667
668 case EVENT_SEND_ENVELOPE_DONE:
669 ar = (AsyncResult) msg.obj;
670 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700671 if (ar.exception == null && ar.result != null) {
672 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800673 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700674 request.result = new IccIoResult(0x6F, 0, (byte[])null);
675 if (ar.result == null) {
676 loge("sendEnvelopeWithStatus: Empty response");
677 } else if (ar.exception instanceof CommandException) {
678 loge("sendEnvelopeWithStatus: CommandException: " +
679 ar.exception);
680 } else {
681 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
682 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800685 break;
686
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 case CMD_OPEN_CHANNEL:
688 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000689 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800690 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000691 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800693 request.result = new IccOpenLogicalChannelResponse(-1,
694 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700695 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700696 } else {
697 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000698 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800699 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700700 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 break;
702
703 case EVENT_OPEN_CHANNEL_DONE:
704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 int[] result = (int[]) ar.result;
709 int channelId = result[0];
710 byte[] selectResponse = null;
711 if (result.length > 1) {
712 selectResponse = new byte[result.length - 1];
713 for (int i = 1; i < result.length; ++i) {
714 selectResponse[i - 1] = (byte) result[i];
715 }
716 }
717 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700718 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 if (ar.result == null) {
721 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700723 if (ar.exception != null) {
724 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
725 }
726
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700727 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700728 if (ar.exception instanceof CommandException) {
729 CommandException.Error error =
730 ((CommandException) (ar.exception)).getCommandError();
731 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700732 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700733 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700734 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700735 }
736 }
737 openChannelResp = new IccOpenLogicalChannelResponse(
738 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700740 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700741 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 break;
743
744 case CMD_CLOSE_CHANNEL:
745 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000746 uiccPort = getUiccPortFromRequest(request);
747 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700748 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900749 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700750 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700751 } else {
752 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000753 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700754 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 break;
756
757 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800758 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
759 break;
760
761 case CMD_NV_READ_ITEM:
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800764 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
765 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800766 break;
767
768 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700769 ar = (AsyncResult) msg.obj;
770 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800771 if (ar.exception == null && ar.result != null) {
772 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800774 request.result = "";
775 if (ar.result == null) {
776 loge("nvReadItem: Empty response");
777 } else if (ar.exception instanceof CommandException) {
778 loge("nvReadItem: CommandException: " +
779 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700780 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800781 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700782 }
783 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700784 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 break;
786
Jake Hambye994d462014-02-03 13:10:13 -0800787 case CMD_NV_WRITE_ITEM:
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
790 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800791 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700792 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800793 break;
794
795 case EVENT_NV_WRITE_ITEM_DONE:
796 handleNullReturnEvent(msg, "nvWriteItem");
797 break;
798
799 case CMD_NV_WRITE_CDMA_PRL:
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800802 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800803 break;
804
805 case EVENT_NV_WRITE_CDMA_PRL_DONE:
806 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
807 break;
808
chen xu6dac5ab2018-10-26 17:39:23 -0700809 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800810 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700811 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800812 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800813 break;
814
chen xu6dac5ab2018-10-26 17:39:23 -0700815 case EVENT_RESET_MODEM_CONFIG_DONE:
816 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800817 break;
818
Sooraj Sasindran37444802020-08-11 10:40:43 -0700819 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
820 request = (MainThreadRequest) msg.obj;
821 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
822 request);
823 Phone phone = getPhoneFromRequest(request);
824 if (phone != null) {
825 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
826 } else {
827 loge("isNRDualConnectivityEnabled: No phone object");
828 request.result = false;
829 notifyRequester(request);
830 }
831 break;
832 }
833
834 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
837 if (ar.exception == null && ar.result != null) {
838 request.result = ar.result;
839 } else {
840 // request.result must be set to something non-null
841 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700842 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700843 request.result = ar.result;
844 } else {
845 request.result = false;
846 }
847 if (ar.result == null) {
848 loge("isNRDualConnectivityEnabled: Empty response");
849 } else if (ar.exception instanceof CommandException) {
850 loge("isNRDualConnectivityEnabled: CommandException: "
851 + ar.exception);
852 } else {
853 loge("isNRDualConnectivityEnabled: Unknown exception");
854 }
855 }
856 notifyRequester(request);
857 break;
858
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700859 case CMD_IS_VONR_ENABLED: {
860 request = (MainThreadRequest) msg.obj;
861 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
862 request);
863 Phone phone = getPhoneFromRequest(request);
864 if (phone != null) {
865 phone.isVoNrEnabled(onCompleted, request.workSource);
866 } else {
867 loge("isVoNrEnabled: No phone object");
868 request.result = false;
869 notifyRequester(request);
870 }
871 break;
872 }
873
874 case EVENT_IS_VONR_ENABLED_DONE:
875 ar = (AsyncResult) msg.obj;
876 request = (MainThreadRequest) ar.userObj;
877 if (ar.exception == null && ar.result != null) {
878 request.result = ar.result;
879 } else {
880 // request.result must be set to something non-null
881 // for the calling thread to unblock
882 if (ar.result != null) {
883 request.result = ar.result;
884 } else {
885 request.result = false;
886 }
887 if (ar.result == null) {
888 loge("isVoNrEnabled: Empty response");
889 } else if (ar.exception instanceof CommandException) {
890 loge("isVoNrEnabled: CommandException: "
891 + ar.exception);
892 } else {
893 loge("isVoNrEnabled: Unknown exception");
894 }
895 }
896 notifyRequester(request);
897 break;
898
Sooraj Sasindran37444802020-08-11 10:40:43 -0700899 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
900 request = (MainThreadRequest) msg.obj;
901 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
902 Phone phone = getPhoneFromRequest(request);
903 if (phone != null) {
904 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
905 request.workSource);
906 } else {
907 loge("enableNrDualConnectivity: No phone object");
908 request.result =
909 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
910 notifyRequester(request);
911 }
912 break;
913 }
914
915 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 if (ar.exception == null) {
919 request.result =
920 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
921 } else {
922 request.result =
923 TelephonyManager
924 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
925 if (ar.exception instanceof CommandException) {
926 CommandException.Error error =
927 ((CommandException) (ar.exception)).getCommandError();
928 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
929 request.result =
930 TelephonyManager
931 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000932 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
933 request.result =
934 TelephonyManager
935 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700936 }
937 loge("enableNrDualConnectivity" + ": CommandException: "
938 + ar.exception);
939 } else {
940 loge("enableNrDualConnectivity" + ": Unknown exception");
941 }
942 }
943 notifyRequester(request);
944 break;
945 }
946
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700947 case CMD_ENABLE_VONR: {
948 request = (MainThreadRequest) msg.obj;
949 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
950 Phone phone = getPhoneFromRequest(request);
951 if (phone != null) {
952 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
953 request.workSource);
954 } else {
955 loge("setVoNrEnabled: No phone object");
956 request.result =
957 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
958 notifyRequester(request);
959 }
960 break;
961 }
962
963 case EVENT_ENABLE_VONR_DONE: {
964 ar = (AsyncResult) msg.obj;
965 request = (MainThreadRequest) ar.userObj;
966 if (ar.exception == null) {
967 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
968 } else {
969 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
970 if (ar.exception instanceof CommandException) {
971 CommandException.Error error =
972 ((CommandException) (ar.exception)).getCommandError();
973 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
974 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
975 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
976 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
977 } else {
978 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
979 }
980 loge("setVoNrEnabled" + ": CommandException: "
981 + ar.exception);
982 } else {
983 loge("setVoNrEnabled" + ": Unknown exception");
984 }
985 }
986 notifyRequester(request);
987 break;
988 }
989
SongFerngWang3ef3e072020-12-21 16:41:52 +0800990 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800991 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800992 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
993 request);
994 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800995 break;
996
SongFerngWang3ef3e072020-12-21 16:41:52 +0800997 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
1000 if (ar.exception == null && ar.result != null) {
1001 request.result = ar.result; // Integer
1002 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301003 // request.result must be set to something non-null
1004 // for the calling thread to unblock
1005 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001006 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001007 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001008 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001009 loge("getAllowedNetworkTypesBitmask: CommandException: "
1010 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001011 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001012 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001013 }
1014 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001015 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001016 break;
1017
SongFerngWang3ef3e072020-12-21 16:41:52 +08001018 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001019 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001020 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1021 request);
1022 Pair<Integer, Long> reasonWithNetworkTypes =
1023 (Pair<Integer, Long>) request.argument;
1024 getPhoneFromRequest(request).setAllowedNetworkTypes(
1025 reasonWithNetworkTypes.first,
1026 reasonWithNetworkTypes.second,
1027 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001028 break;
1029
SongFerngWang3ef3e072020-12-21 16:41:52 +08001030 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1031 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001032 break;
1033
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001034 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1035 request = (MainThreadRequest)msg.obj;
1036 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001037 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001038 break;
1039
1040 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1041 ar = (AsyncResult)msg.obj;
1042 request = (MainThreadRequest)ar.userObj;
1043 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001044 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001045 break;
1046
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001047 case CMD_SET_VOICEMAIL_NUMBER:
1048 request = (MainThreadRequest) msg.obj;
1049 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1050 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001051 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1052 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001053 break;
1054
1055 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1056 handleNullReturnEvent(msg, "setVoicemailNumber");
1057 break;
1058
Stuart Scott54788802015-03-30 13:18:01 -07001059 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1060 request = (MainThreadRequest) msg.obj;
1061 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1062 request);
1063 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1064 break;
1065
1066 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1067 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1068 break;
1069
Shishir Agrawal302c8692015-06-19 13:49:39 -07001070 case CMD_PERFORM_NETWORK_SCAN:
1071 request = (MainThreadRequest) msg.obj;
1072 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1073 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1074 break;
1075
Hall Liu27d24262020-09-18 19:04:59 -07001076 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001077 request = (MainThreadRequest) msg.obj;
1078 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001079 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1080 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1081 request.argument;
1082 int callForwardingReason = args.first;
1083 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001084 break;
Hall Liu27d24262020-09-18 19:04:59 -07001085 }
1086 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001087 ar = (AsyncResult) msg.obj;
1088 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001089 TelephonyManager.CallForwardingInfoCallback callback =
1090 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1091 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001092 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001093 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001094 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1095 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1096 // Service Class is a bit mask per 3gpp 27.007. Search for
1097 // any service for voice call.
1098 if ((callForwardInfo.serviceClass
1099 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001100 callForwardingInfo = new CallForwardingInfo(true,
1101 callForwardInfo.reason,
1102 callForwardInfo.number,
1103 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001104 break;
1105 }
1106 }
1107 // Didn't find a call forward info for voice call.
1108 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001109 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1110 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001111 }
Hall Liu27d24262020-09-18 19:04:59 -07001112 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001113 } else {
1114 if (ar.result == null) {
1115 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1116 }
1117 if (ar.exception != null) {
1118 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1119 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001120 int errorCode = TelephonyManager
1121 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001122 if (ar.exception instanceof CommandException) {
1123 CommandException.Error error =
1124 ((CommandException) (ar.exception)).getCommandError();
1125 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001126 errorCode = TelephonyManager
1127 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001128 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001129 errorCode = TelephonyManager
1130 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001131 }
1132 }
Hall Liu27d24262020-09-18 19:04:59 -07001133 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001134 }
Shuo Qian4a594052020-01-23 11:59:30 -08001135 break;
Hall Liu27d24262020-09-18 19:04:59 -07001136 }
Shuo Qian4a594052020-01-23 11:59:30 -08001137
Hall Liu27d24262020-09-18 19:04:59 -07001138 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001141 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001142 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001143 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1144 request.argument).first;
1145 request.phone.setCallForwardingOption(
1146 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001147 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001148 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001149 callForwardingInfoToSet.getReason(),
1150 callForwardingInfoToSet.getNumber(),
1151 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1152 break;
Hall Liu27d24262020-09-18 19:04:59 -07001153 }
Shuo Qian4a594052020-01-23 11:59:30 -08001154
Hall Liu27d24262020-09-18 19:04:59 -07001155 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001156 ar = (AsyncResult) msg.obj;
1157 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001158 Consumer<Integer> callback =
1159 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1160 request.argument).second;
1161 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001162 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001163 int errorCode = TelephonyManager.CallForwardingInfoCallback
1164 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001165 if (ar.exception instanceof CommandException) {
1166 CommandException.Error error =
1167 ((CommandException) (ar.exception)).getCommandError();
1168 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001169 errorCode = TelephonyManager.CallForwardingInfoCallback
1170 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001171 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001172 errorCode = TelephonyManager.CallForwardingInfoCallback
1173 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001174 }
1175 }
1176 callback.accept(errorCode);
1177 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001178 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001179 }
Shuo Qian4a594052020-01-23 11:59:30 -08001180 break;
Hall Liu27d24262020-09-18 19:04:59 -07001181 }
Shuo Qian4a594052020-01-23 11:59:30 -08001182
Hall Liu27d24262020-09-18 19:04:59 -07001183 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001184 request = (MainThreadRequest) msg.obj;
1185 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1186 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1187 break;
Hall Liu27d24262020-09-18 19:04:59 -07001188 }
Shuo Qian4a594052020-01-23 11:59:30 -08001189
Hall Liu27d24262020-09-18 19:04:59 -07001190 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001191 ar = (AsyncResult) msg.obj;
1192 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001193 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001194 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1195 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001196 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001197 // Service Class is a bit mask per 3gpp 27.007.
1198 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001199 if (callForwardResults.length > 1
1200 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001201 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001202 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001203 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1204 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001205 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001206 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001207 }
1208 } else {
1209 if (ar.result == null) {
1210 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1211 }
1212 if (ar.exception != null) {
1213 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1214 }
1215 if (ar.exception instanceof CommandException) {
1216 CommandException.Error error =
1217 ((CommandException) (ar.exception)).getCommandError();
1218 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1219 callForwardingStatus =
1220 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1221 }
1222 }
1223 }
Hall Liu27d24262020-09-18 19:04:59 -07001224 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001225 break;
Hall Liu27d24262020-09-18 19:04:59 -07001226 }
Shuo Qian4a594052020-01-23 11:59:30 -08001227
Hall Liu27d24262020-09-18 19:04:59 -07001228 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001229 request = (MainThreadRequest) msg.obj;
1230 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001231 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1232 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001233 break;
Hall Liu27d24262020-09-18 19:04:59 -07001234 }
Shuo Qian4a594052020-01-23 11:59:30 -08001235
Hall Liu27d24262020-09-18 19:04:59 -07001236 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001237 ar = (AsyncResult) msg.obj;
1238 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001239 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1240 Consumer<Integer> callback =
1241 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1242 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001243 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001244 if (ar.exception instanceof CommandException) {
1245 CommandException.Error error =
1246 ((CommandException) (ar.exception)).getCommandError();
1247 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1248 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1249 } else {
1250 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1251 }
1252 } else {
1253 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1254 }
1255 } else {
1256 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1257 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001258 }
Shuo Qian4a594052020-01-23 11:59:30 -08001259 break;
Hall Liu27d24262020-09-18 19:04:59 -07001260 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001261 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1262 ar = (AsyncResult) msg.obj;
1263 request = (MainThreadRequest) ar.userObj;
1264 CellNetworkScanResult cellScanResult;
1265 if (ar.exception == null && ar.result != null) {
1266 cellScanResult = new CellNetworkScanResult(
1267 CellNetworkScanResult.STATUS_SUCCESS,
1268 (List<OperatorInfo>) ar.result);
1269 } else {
1270 if (ar.result == null) {
1271 loge("getCellNetworkScanResults: Empty response");
1272 }
1273 if (ar.exception != null) {
1274 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1275 }
1276 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1277 if (ar.exception instanceof CommandException) {
1278 CommandException.Error error =
1279 ((CommandException) (ar.exception)).getCommandError();
1280 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1281 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1282 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1283 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1284 }
1285 }
1286 cellScanResult = new CellNetworkScanResult(errorCode, null);
1287 }
1288 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001289 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001290 break;
1291
1292 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1293 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001294 ManualNetworkSelectionArgument selArg =
1295 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001296 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1297 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001298 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1299 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001300 break;
1301
1302 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001303 ar = (AsyncResult) msg.obj;
1304 request = (MainThreadRequest) ar.userObj;
1305 if (ar.exception == null) {
1306 request.result = true;
1307 } else {
1308 request.result = false;
1309 loge("setNetworkSelectionModeManual " + ar.exception);
1310 }
1311 notifyRequester(request);
1312 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001313 break;
1314
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001315 case CMD_GET_MODEM_ACTIVITY_INFO:
1316 request = (MainThreadRequest) msg.obj;
1317 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001318 if (defaultPhone != null) {
1319 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001320 } else {
1321 ResultReceiver result = (ResultReceiver) request.argument;
1322 Bundle bundle = new Bundle();
1323 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001324 new ModemActivityInfo(0, 0, 0,
1325 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001326 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001327 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001328 break;
1329
Hall Liud0f208c2020-10-14 16:54:44 -07001330 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001331 ar = (AsyncResult) msg.obj;
1332 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001333 ResultReceiver result = (ResultReceiver) request.argument;
1334
Hall Liud0f208c2020-10-14 16:54:44 -07001335 ModemActivityInfo ret = null;
1336 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001337 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001338 // Update the last modem activity info and the result of the request.
1339 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1340 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001341 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001342 int[] txTimeMs = info.getTransmitTimeMillis();
1343 int[] lastModemTxTimeMs = mLastModemActivityInfo
1344 .getTransmitTimeMillis();
1345 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1346 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1347 }
Hall Liu49656c02020-10-09 19:00:11 -07001348 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001349 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1350 + mLastModemActivityInfo.getSleepTimeMillis());
1351 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1352 + mLastModemActivityInfo.getIdleTimeMillis());
1353 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1354 mLastModemActivityInfo.setReceiveTimeMillis(
1355 info.getReceiveTimeMillis()
1356 + mLastModemActivityInfo.getReceiveTimeMillis());
1357 }
Hall Liu49656c02020-10-09 19:00:11 -07001358 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001359 mLastModemActivityInfo.getSleepTimeMillis(),
1360 mLastModemActivityInfo.getIdleTimeMillis(),
1361 mLastModemActivityInfo.getTransmitTimeMillis(),
1362 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001363 } else {
1364 if (ar.result == null) {
1365 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001366 error = TelephonyManager.ModemActivityInfoException
1367 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001368 } else if (ar.exception instanceof CommandException) {
1369 loge("queryModemActivityInfo: CommandException: " +
1370 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001371 error = TelephonyManager.ModemActivityInfoException
1372 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001373 } else {
1374 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001375 error = TelephonyManager.ModemActivityInfoException
1376 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001377 }
1378 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001379 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001380 if (ret != null) {
1381 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1382 } else {
1383 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1384 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001385 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001386 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001387 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001388 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001389
Meng Wang1a7c35a2016-05-05 20:56:15 -07001390 case CMD_SET_ALLOWED_CARRIERS:
1391 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001392 CarrierRestrictionRules argument =
1393 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001394 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001395 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001396 break;
1397
1398 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1399 ar = (AsyncResult) msg.obj;
1400 request = (MainThreadRequest) ar.userObj;
1401 if (ar.exception == null && ar.result != null) {
1402 request.result = ar.result;
1403 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001404 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1405 if (ar.exception instanceof CommandException) {
1406 loge("setAllowedCarriers: CommandException: " + ar.exception);
1407 CommandException.Error error =
1408 ((CommandException) (ar.exception)).getCommandError();
1409 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1410 request.result =
1411 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1412 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001413 } else {
1414 loge("setAllowedCarriers: Unknown exception");
1415 }
1416 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001417 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001418 break;
1419
1420 case CMD_GET_ALLOWED_CARRIERS:
1421 request = (MainThreadRequest) msg.obj;
1422 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001423 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001424 break;
1425
1426 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1427 ar = (AsyncResult) msg.obj;
1428 request = (MainThreadRequest) ar.userObj;
1429 if (ar.exception == null && ar.result != null) {
1430 request.result = ar.result;
1431 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001432 request.result = new IllegalStateException(
1433 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001434 if (ar.result == null) {
1435 loge("getAllowedCarriers: Empty response");
1436 } else if (ar.exception instanceof CommandException) {
1437 loge("getAllowedCarriers: CommandException: " +
1438 ar.exception);
1439 } else {
1440 loge("getAllowedCarriers: Unknown exception");
1441 }
1442 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001443 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001444 break;
1445
Nathan Haroldb3014052017-01-25 15:57:32 -08001446 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1447 ar = (AsyncResult) msg.obj;
1448 request = (MainThreadRequest) ar.userObj;
1449 if (ar.exception == null && ar.result != null) {
1450 request.result = ar.result;
1451 } else {
1452 request.result = new IllegalArgumentException(
1453 "Failed to retrieve Forbidden Plmns");
1454 if (ar.result == null) {
1455 loge("getForbiddenPlmns: Empty response");
1456 } else {
1457 loge("getForbiddenPlmns: Unknown exception");
1458 }
1459 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001460 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001461 break;
1462
1463 case CMD_GET_FORBIDDEN_PLMNS:
1464 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001465 uiccPort = getUiccPortFromRequest(request);
1466 if (uiccPort == null) {
1467 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001468 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001469 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001470 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001471 break;
1472 }
1473 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001474 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001475 if (uiccApp == null) {
1476 loge("getForbiddenPlmns() no app with specified type -- "
1477 + appType);
1478 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001479 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001480 break;
1481 } else {
1482 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1483 + " specified type -- " + appType);
1484 }
1485 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1486 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1487 onCompleted);
1488 break;
1489
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001490 case CMD_SWITCH_SLOTS:
1491 request = (MainThreadRequest) msg.obj;
1492 int[] physicalSlots = (int[]) request.argument;
1493 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1494 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1495 break;
1496
1497 case EVENT_SWITCH_SLOTS_DONE:
1498 ar = (AsyncResult) msg.obj;
1499 request = (MainThreadRequest) ar.userObj;
1500 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001501 notifyRequester(request);
1502 break;
1503 case CMD_GET_NETWORK_SELECTION_MODE:
1504 request = (MainThreadRequest) msg.obj;
1505 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1506 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1507 break;
1508
1509 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1510 ar = (AsyncResult) msg.obj;
1511 request = (MainThreadRequest) ar.userObj;
1512 if (ar.exception != null) {
1513 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1514 } else {
1515 int mode = ((int[]) ar.result)[0];
1516 if (mode == 0) {
1517 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1518 } else {
1519 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1520 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001521 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001522 notifyRequester(request);
1523 break;
1524 case CMD_GET_CDMA_ROAMING_MODE:
1525 request = (MainThreadRequest) msg.obj;
1526 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1527 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1528 break;
1529 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1530 ar = (AsyncResult) msg.obj;
1531 request = (MainThreadRequest) ar.userObj;
1532 if (ar.exception != null) {
1533 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1534 } else {
1535 request.result = ((int[]) ar.result)[0];
1536 }
1537 notifyRequester(request);
1538 break;
1539 case CMD_SET_CDMA_ROAMING_MODE:
1540 request = (MainThreadRequest) msg.obj;
1541 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1542 int mode = (int) request.argument;
1543 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1544 break;
1545 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1546 ar = (AsyncResult) msg.obj;
1547 request = (MainThreadRequest) ar.userObj;
1548 request.result = ar.exception == null;
1549 notifyRequester(request);
1550 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001551 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1552 request = (MainThreadRequest) msg.obj;
1553 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1554 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1555 break;
1556 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1557 ar = (AsyncResult) msg.obj;
1558 request = (MainThreadRequest) ar.userObj;
1559 if (ar.exception != null) {
1560 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1561 } else {
1562 request.result = ((int[]) ar.result)[0];
1563 }
1564 notifyRequester(request);
1565 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001566 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1567 request = (MainThreadRequest) msg.obj;
1568 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1569 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001570 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1571 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001572 break;
1573 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1574 ar = (AsyncResult) msg.obj;
1575 request = (MainThreadRequest) ar.userObj;
1576 request.result = ar.exception == null;
1577 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001578 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001579 case CMD_GET_ALL_CELL_INFO:
1580 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001581 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001582 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001583 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001584 case EVENT_GET_ALL_CELL_INFO_DONE:
1585 ar = (AsyncResult) msg.obj;
1586 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001587 // If a timeout occurs, the response will be null
1588 request.result = (ar.exception == null && ar.result != null)
1589 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001590 synchronized (request) {
1591 request.notifyAll();
1592 }
1593 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001594 case CMD_REQUEST_CELL_INFO_UPDATE:
1595 request = (MainThreadRequest) msg.obj;
1596 request.phone.requestCellInfoUpdate(request.workSource,
1597 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1598 break;
1599 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1600 ar = (AsyncResult) msg.obj;
1601 request = (MainThreadRequest) ar.userObj;
1602 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1603 try {
1604 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001605 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001606 cb.onError(
1607 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1608 ar.exception.getClass().getName(),
1609 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001610 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001611 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001612 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001613 } else {
1614 // use the result as returned
1615 cb.onCellInfo((List<CellInfo>) ar.result);
1616 }
1617 } catch (RemoteException re) {
1618 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1619 }
1620 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001621 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001622 request = (MainThreadRequest) msg.obj;
1623 WorkSource ws = (WorkSource) request.argument;
1624 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001625 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001626 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001627 }
1628 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001629 ar = (AsyncResult) msg.obj;
1630 request = (MainThreadRequest) ar.userObj;
1631 if (ar.exception == null) {
1632 request.result = ar.result;
1633 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001634 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001635 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001636 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001637 }
1638
1639 synchronized (request) {
1640 request.notifyAll();
1641 }
1642 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001643 }
chen xu6dac5ab2018-10-26 17:39:23 -07001644 case CMD_MODEM_REBOOT:
1645 request = (MainThreadRequest) msg.obj;
1646 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001647 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001648 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001649 case EVENT_CMD_MODEM_REBOOT_DONE:
1650 handleNullReturnEvent(msg, "rebootModem");
1651 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001652 case CMD_REQUEST_ENABLE_MODEM:
1653 request = (MainThreadRequest) msg.obj;
1654 boolean enable = (boolean) request.argument;
1655 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001656 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001657 PhoneConfigurationManager.getInstance()
1658 .enablePhone(request.phone, enable, onCompleted);
1659 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001660 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001661 ar = (AsyncResult) msg.obj;
1662 request = (MainThreadRequest) ar.userObj;
1663 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001664 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001665 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001666 if ((boolean) request.result) {
1667 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1668 updateModemStateMetrics();
1669 } else {
1670 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1671 + ar.exception);
1672 }
1673 notifyRequester(request);
1674 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001675 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001676 case CMD_GET_MODEM_STATUS:
1677 request = (MainThreadRequest) msg.obj;
1678 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1679 PhoneConfigurationManager.getInstance()
1680 .getPhoneStatusFromModem(request.phone, onCompleted);
1681 break;
1682 case EVENT_GET_MODEM_STATUS_DONE:
1683 ar = (AsyncResult) msg.obj;
1684 request = (MainThreadRequest) ar.userObj;
1685 int id = request.phone.getPhoneId();
1686 if (ar.exception == null && ar.result != null) {
1687 request.result = ar.result;
1688 //update the cache as modem status has changed
1689 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1690 (boolean) request.result);
1691 } else {
1692 // Return true if modem status cannot be retrieved. For most cases,
1693 // modem status is on. And for older version modems, GET_MODEM_STATUS
1694 // and disable modem are not supported. Modem is always on.
1695 // TODO: this should be fixed in R to support a third
1696 // status UNKNOWN b/131631629
1697 request.result = true;
1698 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1699 + ar.exception);
1700 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001701 notifyRequester(request);
1702 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001703 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1704 request = (MainThreadRequest) msg.obj;
1705 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1706 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1707 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1708 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1709 break;
1710 }
1711 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1712 ar = (AsyncResult) msg.obj;
1713 request = (MainThreadRequest) ar.userObj;
1714 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1715 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1716 args.second.accept(ar.exception == null);
1717 notifyRequester(request);
1718 break;
1719 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001720 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1721 request = (MainThreadRequest) msg.obj;
1722 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1723 Phone phone = getPhoneFromRequest(request);
1724 if (phone != null) {
1725 phone.getSystemSelectionChannels(onCompleted);
1726 } else {
1727 loge("getSystemSelectionChannels: No phone object");
1728 request.result = new ArrayList<RadioAccessSpecifier>();
1729 notifyRequester(request);
1730 }
1731 break;
1732 }
1733 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1734 ar = (AsyncResult) msg.obj;
1735 request = (MainThreadRequest) ar.userObj;
1736 if (ar.exception == null && ar.result != null) {
1737 request.result = ar.result;
1738 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001739 request.result = new IllegalStateException(
1740 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001741 if (ar.result == null) {
1742 loge("getSystemSelectionChannels: Empty response");
1743 } else {
1744 loge("getSystemSelectionChannels: Unknown exception");
1745 }
1746 }
1747 notifyRequester(request);
1748 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001749 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1750 ar = (AsyncResult) msg.obj;
1751 request = (MainThreadRequest) ar.userObj;
1752 if (ar.exception == null && ar.result != null) {
1753 request.result = ar.result;
1754 } else {
1755 request.result = -1;
1756 loge("Failed to set Forbidden Plmns");
1757 if (ar.result == null) {
1758 loge("setForbidenPlmns: Empty response");
1759 } else if (ar.exception != null) {
1760 loge("setForbiddenPlmns: Exception: " + ar.exception);
1761 request.result = -1;
1762 } else {
1763 loge("setForbiddenPlmns: Unknown exception");
1764 }
1765 }
1766 notifyRequester(request);
1767 break;
1768 case CMD_SET_FORBIDDEN_PLMNS:
1769 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001770 uiccPort = getUiccPortFromRequest(request);
1771 if (uiccPort == null) {
1772 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001773 request.result = -1;
1774 notifyRequester(request);
1775 break;
1776 }
1777 Pair<Integer, List<String>> setFplmnsArgs =
1778 (Pair<Integer, List<String>>) request.argument;
1779 appType = setFplmnsArgs.first;
1780 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001781 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001782 if (uiccApp == null) {
1783 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1784 request.result = -1;
1785 loge("Failed to get UICC App");
1786 notifyRequester(request);
1787 } else {
1788 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1789 ((SIMRecords) uiccApp.getIccRecords())
1790 .setForbiddenPlmns(onCompleted, fplmns);
1791 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001792 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001793 case CMD_ERASE_MODEM_CONFIG:
1794 request = (MainThreadRequest) msg.obj;
1795 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1796 defaultPhone.eraseModemConfig(onCompleted);
1797 break;
1798 case EVENT_ERASE_MODEM_CONFIG_DONE:
1799 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001800 break;
zoey chene02881a2019-12-30 16:11:23 +08001801
Kai Shif70f46f2021-03-03 13:59:46 -08001802 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1803 request = (MainThreadRequest) msg.obj;
1804 request.result = defaultPhone.eraseDataInSharedPreferences();
1805 notifyRequester(request);
1806 break;
1807
zoey chene02881a2019-12-30 16:11:23 +08001808 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1809 request = (MainThreadRequest) msg.obj;
1810 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1811 Pair<String, String> changed = (Pair<String, String>) request.argument;
1812 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1813 changed.first, changed.second, onCompleted);
1814 break;
1815 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1816 ar = (AsyncResult) msg.obj;
1817 request = (MainThreadRequest) ar.userObj;
1818 if (ar.exception == null) {
1819 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001820 // If the operation is successful, update the PIN storage
1821 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1822 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001823 UiccController.getInstance().getPinStorage()
1824 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001825 } else {
1826 request.result = msg.arg1;
1827 }
1828 notifyRequester(request);
1829 break;
1830
Michele Berionne5e411512020-11-13 02:36:59 +00001831 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001832 request = (MainThreadRequest) msg.obj;
1833 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1834 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1835 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1836 enabled.first, enabled.second, onCompleted);
1837 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001838 }
zoey chene02881a2019-12-30 16:11:23 +08001839 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1840 ar = (AsyncResult) msg.obj;
1841 request = (MainThreadRequest) ar.userObj;
1842 if (ar.exception == null) {
1843 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001844 // If the operation is successful, update the PIN storage
1845 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1846 int phoneId = getPhoneFromRequest(request).getPhoneId();
1847 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001848 UiccController.getInstance().getPinStorage()
1849 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001850 } else {
1851 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1852 }
zoey chene02881a2019-12-30 16:11:23 +08001853 } else {
1854 request.result = msg.arg1;
1855 }
Michele Berionne5e411512020-11-13 02:36:59 +00001856
1857
zoey chene02881a2019-12-30 16:11:23 +08001858 notifyRequester(request);
1859 break;
1860
Peter Wangdafb9ac2020-01-15 14:13:38 -08001861 case MSG_NOTIFY_USER_ACTIVITY:
1862 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001863 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001864 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1865 getDefaultPhone().getContext().sendBroadcastAsUser(
1866 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1867 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001868
1869 case CMD_SET_DATA_THROTTLING: {
1870 request = (MainThreadRequest) msg.obj;
1871 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1872 DataThrottlingRequest dataThrottlingRequest =
1873 (DataThrottlingRequest) request.argument;
1874 Phone phone = getPhoneFromRequest(request);
1875 if (phone != null) {
1876 phone.setDataThrottling(onCompleted,
1877 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1878 dataThrottlingRequest.getCompletionDurationMillis());
1879 } else {
1880 loge("setDataThrottling: No phone object");
1881 request.result =
1882 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1883 notifyRequester(request);
1884 }
1885
1886 break;
1887 }
1888 case EVENT_SET_DATA_THROTTLING_DONE:
1889 ar = (AsyncResult) msg.obj;
1890 request = (MainThreadRequest) ar.userObj;
1891
1892 if (ar.exception == null) {
1893 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1894 } else if (ar.exception instanceof CommandException) {
1895 loge("setDataThrottling: CommandException: " + ar.exception);
1896 CommandException.Error error =
1897 ((CommandException) (ar.exception)).getCommandError();
1898
1899 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1900 request.result = TelephonyManager
1901 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1902 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1903 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001904 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1905 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001906 } else {
1907 request.result =
1908 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1909 }
1910 } else {
1911 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1912 }
1913 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1914 notifyRequester(request);
1915 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001916
1917 case CMD_SET_SIM_POWER: {
1918 request = (MainThreadRequest) msg.obj;
1919 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1920 request = (MainThreadRequest) msg.obj;
1921 int stateToSet =
1922 ((Pair<Integer, IIntegerConsumer>)
1923 request.argument).first;
1924 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1925 break;
1926 }
1927 case EVENT_SET_SIM_POWER_DONE: {
1928 ar = (AsyncResult) msg.obj;
1929 request = (MainThreadRequest) ar.userObj;
1930 IIntegerConsumer callback =
1931 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1932 if (ar.exception != null) {
1933 loge("setSimPower exception: " + ar.exception);
1934 int errorCode = TelephonyManager.CallForwardingInfoCallback
1935 .RESULT_ERROR_UNKNOWN;
1936 if (ar.exception instanceof CommandException) {
1937 CommandException.Error error =
1938 ((CommandException) (ar.exception)).getCommandError();
1939 if (error == CommandException.Error.SIM_ERR) {
1940 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1941 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1942 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1943 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1944 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1945 } else {
1946 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1947 }
1948 }
1949 try {
1950 callback.accept(errorCode);
1951 } catch (RemoteException e) {
1952 // Ignore if the remote process is no longer available to call back.
1953 Log.w(LOG_TAG, "setSimPower: callback not available.");
1954 }
1955 } else {
1956 try {
1957 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1958 } catch (RemoteException e) {
1959 // Ignore if the remote process is no longer available to call back.
1960 Log.w(LOG_TAG, "setSimPower: callback not available.");
1961 }
1962 }
1963 break;
1964 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001965 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1966 request = (MainThreadRequest) msg.obj;
1967
1968 final Phone phone = getPhoneFromRequest(request);
1969 if (phone == null || phone.getServiceStateTracker() == null) {
1970 request.result = new IllegalStateException("Phone or SST is null");
1971 notifyRequester(request);
1972 break;
1973 }
1974
1975 Pair<Integer, SignalStrengthUpdateRequest> pair =
1976 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1977 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1978 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001979 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001980 request.subId, pair.first /*callingUid*/,
1981 pair.second /*request*/, onCompleted);
1982 break;
1983 }
1984 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1985 ar = (AsyncResult) msg.obj;
1986 request = (MainThreadRequest) ar.userObj;
1987 // request.result will be the exception of ar if present, true otherwise.
1988 // Be cautious not to leave result null which will wait() forever
1989 request.result = ar.exception != null ? ar.exception : true;
1990 notifyRequester(request);
1991 break;
1992 }
1993 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1994 request = (MainThreadRequest) msg.obj;
1995
1996 Phone phone = getPhoneFromRequest(request);
1997 if (phone == null || phone.getServiceStateTracker() == null) {
1998 request.result = new IllegalStateException("Phone or SST is null");
1999 notifyRequester(request);
2000 break;
2001 }
2002
2003 Pair<Integer, SignalStrengthUpdateRequest> pair =
2004 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2005 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2006 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002007 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002008 request.subId, pair.first /*callingUid*/,
2009 pair.second /*request*/, onCompleted);
2010 break;
2011 }
2012 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2013 ar = (AsyncResult) msg.obj;
2014 request = (MainThreadRequest) ar.userObj;
2015 request.result = ar.exception != null ? ar.exception : true;
2016 notifyRequester(request);
2017 break;
2018 }
Jordan Liu109698e2020-11-24 14:50:34 -08002019
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002020 case CMD_GET_SLICING_CONFIG: {
2021 request = (MainThreadRequest) msg.obj;
2022 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2023 request.phone.getSlicingConfig(onCompleted);
2024 break;
2025 }
2026 case EVENT_GET_SLICING_CONFIG_DONE: {
2027 ar = (AsyncResult) msg.obj;
2028 request = (MainThreadRequest) ar.userObj;
2029 ResultReceiver result = (ResultReceiver) request.argument;
2030
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002031 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002032 Bundle bundle = new Bundle();
2033 int resultCode = 0;
2034 if (ar.exception != null) {
2035 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2036 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002037 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002038 } else if (ar.result == null) {
2039 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002040 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002041 } else {
2042 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002043 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2044 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002045 }
2046
2047 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002048 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002049 }
2050 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2051 result.send(resultCode, bundle);
2052 notifyRequester(request);
2053 break;
2054 }
2055
Michele Berionne5e411512020-11-13 02:36:59 +00002056 case CMD_PREPARE_UNATTENDED_REBOOT:
2057 request = (MainThreadRequest) msg.obj;
2058 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002059 UiccController.getInstance().getPinStorage()
2060 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002061 notifyRequester(request);
2062 break;
2063
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064 default:
2065 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2066 break;
2067 }
2068 }
Jake Hambye994d462014-02-03 13:10:13 -08002069
Pengquan Menga1bb6272018-09-06 09:59:22 -07002070 private void notifyRequester(MainThreadRequest request) {
2071 synchronized (request) {
2072 request.notifyAll();
2073 }
2074 }
2075
Jake Hambye994d462014-02-03 13:10:13 -08002076 private void handleNullReturnEvent(Message msg, String command) {
2077 AsyncResult ar = (AsyncResult) msg.obj;
2078 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2079 if (ar.exception == null) {
2080 request.result = true;
2081 } else {
2082 request.result = false;
2083 if (ar.exception instanceof CommandException) {
2084 loge(command + ": CommandException: " + ar.exception);
2085 } else {
2086 loge(command + ": Unknown exception");
2087 }
2088 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002089 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 }
2092
2093 /**
2094 * Posts the specified command to be executed on the main thread,
2095 * waits for the request to complete, and returns the result.
2096 * @see #sendRequestAsync
2097 */
2098 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002099 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2100 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002101 }
2102
2103 /**
2104 * Posts the specified command to be executed on the main thread,
2105 * waits for the request to complete, and returns the result.
2106 * @see #sendRequestAsync
2107 */
2108 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2109 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002110 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002111 }
2112
2113 /**
2114 * Posts the specified command to be executed on the main thread,
2115 * waits for the request to complete, and returns the result.
2116 * @see #sendRequestAsync
2117 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002118 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002119 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2120 }
2121
2122 /**
2123 * Posts the specified command to be executed on the main thread,
2124 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2125 * if not timeout or null otherwise.
2126 * @see #sendRequestAsync
2127 */
2128 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2129 long timeoutInMs) {
2130 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002131 }
2132
2133 /**
2134 * Posts the specified command to be executed on the main thread,
2135 * waits for the request to complete, and returns the result.
2136 * @see #sendRequestAsync
2137 */
Nathan Harold92bed182018-10-12 18:16:49 -07002138 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002139 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002140 }
2141
2142 /**
2143 * Posts the specified command to be executed on the main thread,
2144 * waits for the request to complete, and returns the result.
2145 * @see #sendRequestAsync
2146 */
2147 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002148 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2149 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002150 }
2151
2152 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002153 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2154 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2155 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002156 * @see #sendRequestAsync
2157 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002158 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2159 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2161 throw new RuntimeException("This method will deadlock if called from the main thread.");
2162 }
2163
Nathan Harold92bed182018-10-12 18:16:49 -07002164 MainThreadRequest request = null;
2165 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2166 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2167 } else if (phone != null) {
2168 request = new MainThreadRequest(argument, phone, workSource);
2169 } else {
2170 request = new MainThreadRequest(argument, subId, workSource);
2171 }
2172
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 Message msg = mMainThreadHandler.obtainMessage(command, request);
2174 msg.sendToTarget();
2175
Rambo Wang0f050d82021-02-12 11:43:36 -08002176
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002178 if (timeoutInMs >= 0) {
2179 // Wait for at least timeoutInMs before returning null request result
2180 long now = SystemClock.elapsedRealtime();
2181 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002182 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002183 try {
2184 request.wait(deadline - now);
2185 } catch (InterruptedException e) {
2186 // Do nothing, go back and check if request is completed or timeout
2187 } finally {
2188 now = SystemClock.elapsedRealtime();
2189 }
2190 }
2191 } else {
2192 // Wait for the request to complete
2193 while (request.result == null) {
2194 try {
2195 request.wait();
2196 } catch (InterruptedException e) {
2197 // Do nothing, go back and wait until the request is complete
2198 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 }
2200 }
2201 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002202 if (request.result == null) {
2203 Log.wtf(LOG_TAG,
2204 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2205 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002206 return request.result;
2207 }
2208
2209 /**
2210 * Asynchronous ("fire and forget") version of sendRequest():
2211 * Posts the specified command to be executed on the main thread, and
2212 * returns immediately.
2213 * @see #sendRequest
2214 */
2215 private void sendRequestAsync(int command) {
2216 mMainThreadHandler.sendEmptyMessage(command);
2217 }
2218
2219 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002220 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002221 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002222 */
2223 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002224 sendRequestAsync(command, argument, null, null);
2225 }
2226
2227 /**
2228 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2229 * @see {@link #sendRequest(int,Object)}
2230 */
2231 private void sendRequestAsync(
2232 int command, Object argument, Phone phone, WorkSource workSource) {
2233 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002234 Message msg = mMainThreadHandler.obtainMessage(command, request);
2235 msg.sendToTarget();
2236 }
2237
2238 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 * Initialize the singleton PhoneInterfaceManager instance.
2240 * This is only done once, at startup, from PhoneApp.onCreate().
2241 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002242 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243 synchronized (PhoneInterfaceManager.class) {
2244 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002245 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 } else {
2247 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2248 }
2249 return sInstance;
2250 }
2251 }
2252
2253 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002254 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002257 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002258 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002260 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002262 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002263 mTelephonySharedPreferences =
2264 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002265 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002266 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002267 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002268 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002269
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 publish();
2271 }
2272
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002273 private Phone getDefaultPhone() {
2274 Phone thePhone = getPhone(getDefaultSubscription());
2275 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2276 }
2277
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 private void publish() {
2279 if (DBG) log("publish: " + this);
2280
Peter Wangc035ce42020-01-08 21:00:22 -08002281 TelephonyFrameworkInitializer
2282 .getTelephonyServiceManager()
2283 .getTelephonyServiceRegisterer()
2284 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 }
2286
Stuart Scott584921c2015-01-15 17:10:34 -08002287 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002288 if (request.phone != null) {
2289 return request.phone;
2290 } else {
2291 return getPhoneFromSubId(request.subId);
2292 }
2293 }
2294
2295 private Phone getPhoneFromSubId(int subId) {
2296 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2297 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002298 }
2299
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002300 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002301 Phone phone = getPhoneFromRequest(request);
2302 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002303 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002304 }
2305
Wink Saville36469e72014-06-11 15:17:00 -07002306 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002307 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002308 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310
Kai Shif70f46f2021-03-03 13:59:46 -08002311 private void sendEraseModemConfig(@NonNull Phone phone) {
2312 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2313 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2314 }
2315
2316 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2317 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2318 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002319 }
2320
Peter Wang44b186e2020-01-13 23:33:09 -08002321 private boolean isImsAvailableOnDevice() {
2322 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2323 if (pm == null) {
2324 // For some reason package manger is not available.. This will fail internally anyway,
2325 // so do not throw error and allow.
2326 return true;
2327 }
2328 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2329 }
2330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002332 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002333 }
2334
Wink Savilleb564aae2014-10-23 10:18:09 -07002335 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 if (DBG) log("dial: " + number);
2337 // No permission check needed here: This is just a wrapper around the
2338 // ACTION_DIAL intent, which is available to any app since it puts up
2339 // the UI before it does anything.
2340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341 final long identity = Binder.clearCallingIdentity();
2342 try {
2343 String url = createTelUrl(number);
2344 if (url == null) {
2345 return;
2346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002348 // PENDING: should we just silently fail if phone is offhook or ringing?
2349 PhoneConstants.State state = mCM.getState(subId);
2350 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2351 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2352 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2353 mApp.startActivity(intent);
2354 }
2355 } finally {
2356 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 }
2358 }
2359
2360 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002361 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002362 }
2363
Wink Savilleb564aae2014-10-23 10:18:09 -07002364 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365 if (DBG) log("call: " + number);
2366
2367 // This is just a wrapper around the ACTION_CALL intent, but we still
2368 // need to do a permission check since we're calling startActivity()
2369 // from the context of the phone app.
2370 enforceCallPermission();
2371
Jordan Liu1617b712019-07-10 15:06:26 -07002372 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 != AppOpsManager.MODE_ALLOWED) {
2374 return;
2375 }
2376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 String url = createTelUrl(number);
2380 if (url == null) {
2381 return;
2382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002384 boolean isValid = false;
2385 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2386 if (slist != null) {
2387 for (SubscriptionInfo subInfoRecord : slist) {
2388 if (subInfoRecord.getSubscriptionId() == subId) {
2389 isValid = true;
2390 break;
2391 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002392 }
Wink Saville08874612014-08-31 19:19:58 -07002393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002394 if (!isValid) {
2395 return;
2396 }
Wink Saville08874612014-08-31 19:19:58 -07002397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002398 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2399 intent.putExtra(SUBSCRIPTION_KEY, subId);
2400 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2401 mApp.startActivity(intent);
2402 } finally {
2403 Binder.restoreCallingIdentity(identity);
2404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 }
2406
Wink Savilleb564aae2014-10-23 10:18:09 -07002407 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002408 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002409 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2410 }
2411
Wink Savilleb564aae2014-10-23 10:18:09 -07002412 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002413 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002414 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2415 }
2416
Wink Savilleb564aae2014-10-23 10:18:09 -07002417 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002419
2420 final long identity = Binder.clearCallingIdentity();
2421 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002422 Phone phone = getPhone(subId);
2423 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002424 checkSimPin.start();
2425 return checkSimPin.unlockSim(null, pin);
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
2430
Wink Savilleb564aae2014-10-23 10:18:09 -07002431 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002433
2434 final long identity = Binder.clearCallingIdentity();
2435 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002436 Phone phone = getPhone(subId);
2437 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002438 checkSimPuk.start();
2439 return checkSimPuk.unlockSim(puk, pin);
2440 } finally {
2441 Binder.restoreCallingIdentity(identity);
2442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 }
2444
2445 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002446 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 * a synchronous one.
2448 */
2449 private static class UnlockSim extends Thread {
2450
2451 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002452 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453
2454 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002455 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2456 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457
2458 // For replies from SimCard interface
2459 private Handler mHandler;
2460
2461 // For async handler to identify request type
2462 private static final int SUPPLY_PIN_COMPLETE = 100;
2463
Michele Berionne5e411512020-11-13 02:36:59 +00002464 UnlockSim(int phoneId, IccCard simCard) {
2465 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 mSimCard = simCard;
2467 }
2468
2469 @Override
2470 public void run() {
2471 Looper.prepare();
2472 synchronized (UnlockSim.this) {
2473 mHandler = new Handler() {
2474 @Override
2475 public void handleMessage(Message msg) {
2476 AsyncResult ar = (AsyncResult) msg.obj;
2477 switch (msg.what) {
2478 case SUPPLY_PIN_COMPLETE:
2479 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2480 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002481 mRetryCount = msg.arg1;
2482 if (ar.exception != null) {
2483 if (ar.exception instanceof CommandException &&
2484 ((CommandException)(ar.exception)).getCommandError()
2485 == CommandException.Error.PASSWORD_INCORRECT) {
2486 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002487 } //When UiccCardApp dispose,handle message and return exception
2488 else if (ar.exception instanceof CommandException &&
2489 ((CommandException) (ar.exception)).getCommandError()
2490 == CommandException.Error.ABORTED) {
2491 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002492 } else {
2493 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2494 }
2495 } else {
2496 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 mDone = true;
2499 UnlockSim.this.notifyAll();
2500 }
2501 break;
2502 }
2503 }
2504 };
2505 UnlockSim.this.notifyAll();
2506 }
2507 Looper.loop();
2508 }
2509
2510 /*
2511 * Use PIN or PUK to unlock SIM card
2512 *
2513 * If PUK is null, unlock SIM card with PIN
2514 *
2515 * If PUK is not null, unlock SIM card with PUK and set PIN code
2516 */
Wink Saville9de0f752013-10-22 19:04:03 -07002517 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518
2519 while (mHandler == null) {
2520 try {
2521 wait();
2522 } catch (InterruptedException e) {
2523 Thread.currentThread().interrupt();
2524 }
2525 }
2526 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2527
2528 if (puk == null) {
2529 mSimCard.supplyPin(pin, callback);
2530 } else {
2531 mSimCard.supplyPuk(puk, pin, callback);
2532 }
2533
2534 while (!mDone) {
2535 try {
2536 Log.d(LOG_TAG, "wait for done");
2537 wait();
2538 } catch (InterruptedException e) {
2539 // Restore the interrupted status
2540 Thread.currentThread().interrupt();
2541 }
2542 }
2543 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002544 int[] resultArray = new int[2];
2545 resultArray[0] = mResult;
2546 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002547
2548 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002549 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002550 }
2551
Wink Saville9de0f752013-10-22 19:04:03 -07002552 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 }
2554 }
2555
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002556 /**
2557 * This method has been removed due to privacy and stability concerns.
2558 */
2559 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002560 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002561 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2562 return;
Wink Saville36469e72014-06-11 15:17:00 -07002563 }
2564
Nathan Harold1f889d82020-06-04 17:05:26 -07002565 @Override
2566 public void updateServiceLocationWithPackageName(String callingPackage) {
2567 mApp.getSystemService(AppOpsManager.class)
2568 .checkPackage(Binder.getCallingUid(), callingPackage);
2569
Nathan Haroldf096d982020-11-18 17:18:06 -08002570 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002571 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2572 // Callers targeting S have no business invoking this method.
2573 return;
2574 }
2575
2576 LocationAccessPolicy.LocationPermissionResult locationResult =
2577 LocationAccessPolicy.checkLocationPermission(mApp,
2578 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2579 .setCallingPackage(callingPackage)
2580 .setCallingFeatureId(null)
2581 .setCallingPid(Binder.getCallingPid())
2582 .setCallingUid(Binder.getCallingUid())
2583 .setMethod("updateServiceLocation")
2584 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2585 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2586 .build());
2587 // Apps that lack location permission have no business calling this method;
2588 // however, because no permission was declared in the public API, denials must
2589 // all be "soft".
2590 switch (locationResult) {
2591 case DENIED_HARD: /* fall through */
2592 case DENIED_SOFT:
2593 return;
2594 }
2595
2596 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597 final long identity = Binder.clearCallingIdentity();
2598 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002599 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002601 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 }
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 }
2607
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002608 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002609 @Override
2610 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002611 return isRadioOnWithFeature(callingPackage, null);
2612 }
2613
2614
2615 @Override
2616 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2617 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2618 callingFeatureId);
2619 }
2620
2621 @Deprecated
2622 @Override
2623 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2624 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002625 }
2626
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002627 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002628 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2629 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002631 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002632 return false;
2633 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634
2635 final long identity = Binder.clearCallingIdentity();
2636 try {
2637 return isRadioOnForSubscriber(subId);
2638 } finally {
2639 Binder.restoreCallingIdentity(identity);
2640 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002641 }
2642
2643 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 final Phone phone = getPhone(subId);
2647 if (phone != null) {
2648 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2649 } else {
2650 return false;
2651 }
2652 } finally {
2653 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 }
2656
2657 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002658 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 }
Wink Saville36469e72014-06-11 15:17:00 -07002660
Wink Savilleb564aae2014-10-23 10:18:09 -07002661 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663
2664 final long identity = Binder.clearCallingIdentity();
2665 try {
2666 final Phone phone = getPhone(subId);
2667 if (phone != null) {
2668 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2669 }
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002672 }
Wink Saville36469e72014-06-11 15:17:00 -07002673 }
2674
2675 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002676 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002677 }
2678
Wink Savilleb564aae2014-10-23 10:18:09 -07002679 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 final Phone phone = getPhone(subId);
2685 if (phone == null) {
2686 return false;
2687 }
2688 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2689 toggleRadioOnOffForSubscriber(subId);
2690 }
2691 return true;
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 }
Wink Saville36469e72014-06-11 15:17:00 -07002696
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002697 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002698 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002699 /*
2700 * If any of the Radios are available, it will need to be
2701 * shutdown. So return true if any Radio is available.
2702 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2706 Phone phone = PhoneFactory.getPhone(i);
2707 if (phone != null && phone.isRadioAvailable()) return true;
2708 }
2709 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2710 return false;
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002713 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002714 }
2715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002717 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 enforceModifyPermission();
2719
2720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2723 logv("Shutting down Phone " + i);
2724 shutdownRadioUsingPhoneId(i);
2725 }
2726 } finally {
2727 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002728 }
2729 }
2730
2731 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002732 Phone phone = PhoneFactory.getPhone(phoneId);
2733 if (phone != null && phone.isRadioAvailable()) {
2734 phone.shutdownRadio();
2735 }
2736 }
2737
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002739 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740
2741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2744 if (defaultPhone != null) {
2745 defaultPhone.setRadioPower(turnOn);
2746 return true;
2747 } else {
2748 loge("There's no default phone.");
2749 return false;
2750 }
2751 } finally {
2752 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002753 }
Wink Saville36469e72014-06-11 15:17:00 -07002754 }
2755
Wink Savilleb564aae2014-10-23 10:18:09 -07002756 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758
2759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 final Phone phone = getPhone(subId);
2762 if (phone != null) {
2763 phone.setRadioPower(turnOn);
2764 return true;
2765 } else {
2766 return false;
2767 }
2768 } finally {
2769 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 }
2772
Wink Saville36469e72014-06-11 15:17:00 -07002773 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002774 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 public boolean enableDataConnectivity() {
2776 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777
2778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 int subId = mSubscriptionController.getDefaultDataSubId();
2781 final Phone phone = getPhone(subId);
2782 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002783 phone.getDataEnabledSettings().setDataEnabled(
2784 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 return true;
2786 } else {
2787 return false;
2788 }
2789 } finally {
2790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793
Wink Saville36469e72014-06-11 15:17:00 -07002794 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002795 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 public boolean disableDataConnectivity() {
2797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 int subId = mSubscriptionController.getDefaultDataSubId();
2802 final Phone phone = getPhone(subId);
2803 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002804 phone.getDataEnabledSettings().setDataEnabled(
2805 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 return true;
2807 } else {
2808 return false;
2809 }
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813 }
2814
Sanket Padawe356d7632015-06-22 14:03:32 -07002815 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002816 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817 final long identity = Binder.clearCallingIdentity();
2818 try {
2819 final Phone phone = getPhone(subId);
2820 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002821 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822 } else {
2823 return false;
2824 }
2825 } finally {
2826 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002828 }
2829
2830 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002831 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002832 }
2833
pkanwarae03a6b2016-11-06 20:37:09 -08002834 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 enforceCallPermission();
2836
2837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2840 return;
2841 }
2842 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2843 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
2846 }
pkanwar32d516d2016-10-14 19:37:38 -07002847 };
2848
Wink Savilleb564aae2014-10-23 10:18:09 -07002849 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851
2852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2855 return false;
2856 }
2857 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002861 }
2862
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002863 /**
2864 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2865 * tag on getCallState Binder call.
2866 */
2867 @Deprecated
2868 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002870 if (CompatChanges.isChangeEnabled(
2871 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2872 Binder.getCallingUid())) {
2873 // Do not allow this API to be called on API version 31+, it should only be
2874 // called on old apps using this Binder call directly.
2875 throw new SecurityException("This method can only be used for applications "
2876 + "targeting API version 30 or less.");
2877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878 final long identity = Binder.clearCallingIdentity();
2879 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002880 Phone phone = getPhone(getDefaultSubscription());
2881 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2882 PhoneConstantConversions.convertCallState(phone.getState());
2883 } finally {
2884 Binder.restoreCallingIdentity(identity);
2885 }
2886 }
2887
2888 @Override
2889 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2890 if (CompatChanges.isChangeEnabled(
2891 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2892 Binder.getCallingUid())) {
2893 // Check READ_PHONE_STATE for API version 31+
2894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2895 featureId, "getCallStateForSubscription")) {
2896 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2897 + "targeting API level 31+.");
2898 }
2899 }
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002903 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2904 PhoneConstantConversions.convertCallState(phone.getState());
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
2907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002908 }
2909
Sanket Padawe356d7632015-06-22 14:03:32 -07002910 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002911 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002912 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2913 }
2914
2915 @Override
2916 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917 final long identity = Binder.clearCallingIdentity();
2918 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002919 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920 if (phone != null) {
2921 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2922 } else {
2923 return PhoneConstantConversions.convertDataState(
2924 PhoneConstants.DataState.DISCONNECTED);
2925 }
2926 } finally {
2927 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
2930
Sanket Padawe356d7632015-06-22 14:03:32 -07002931 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002932 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002933 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2934 }
2935
2936 @Override
2937 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 final long identity = Binder.clearCallingIdentity();
2939 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002940 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 if (phone != null) {
2942 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2943 } else {
2944 return TelephonyManager.DATA_ACTIVITY_NONE;
2945 }
2946 } finally {
2947 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002949 }
2950
2951 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002952 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002953 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002954 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002955
2956 LocationAccessPolicy.LocationPermissionResult locationResult =
2957 LocationAccessPolicy.checkLocationPermission(mApp,
2958 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2959 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002960 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002961 .setCallingPid(Binder.getCallingPid())
2962 .setCallingUid(Binder.getCallingUid())
2963 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002964 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002965 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2966 .build());
2967 switch (locationResult) {
2968 case DENIED_HARD:
2969 throw new SecurityException("Not allowed to access cell location");
2970 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002971 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2972 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002973 }
2974
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002975 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976 final long identity = Binder.clearCallingIdentity();
2977 try {
2978 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002979 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002980 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 } finally {
2982 Binder.restoreCallingIdentity(identity);
2983 }
Svetoslav64fad262015-04-14 14:35:21 -07002984 }
2985
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002986 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002987 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002988 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2989 // registered cell info, so return a NULL country instead.
2990 final long identity = Binder.clearCallingIdentity();
2991 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002992 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2993 // Get default phone in this case.
2994 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2995 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002996 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002998 if (phone == null) return "";
2999 ServiceStateTracker sst = phone.getServiceStateTracker();
3000 if (sst == null) return "";
3001 LocaleTracker lt = sst.getLocaleTracker();
3002 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003003 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003007 }
3008
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003009 /**
3010 * This method was removed due to potential issues caused by performing partial
3011 * updates of service state, and lack of a credible use case.
3012 *
3013 * This has the ability to break the telephony implementation by disabling notification of
3014 * changes in device connectivity. DO NOT USE THIS!
3015 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003016 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003017 public void enableLocationUpdates() {
3018 mApp.enforceCallingOrSelfPermission(
3019 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020 }
3021
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003022 /**
3023 * This method was removed due to potential issues caused by performing partial
3024 * updates of service state, and lack of a credible use case.
3025 *
3026 * This has the ability to break the telephony implementation by disabling notification of
3027 * changes in device connectivity. DO NOT USE THIS!
3028 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003029 @Override
3030 public void disableLocationUpdates() {
3031 mApp.enforceCallingOrSelfPermission(
3032 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003033 }
3034
3035 @Override
3036 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003037 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3038 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003039 try {
3040 mApp.getSystemService(AppOpsManager.class)
3041 .checkPackage(Binder.getCallingUid(), callingPackage);
3042 } catch (SecurityException e) {
3043 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3044 throw e;
3045 }
3046
Nathan Haroldf096d982020-11-18 17:18:06 -08003047 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003048 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3049 throw new SecurityException(
3050 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3051 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003052
Jordan Liu1617b712019-07-10 15:06:26 -07003053 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003054 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3055 return null;
3056 }
Svetoslav64fad262015-04-14 14:35:21 -07003057
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003058 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003060 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003061 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003062
Nathan Haroldf180aac2018-06-01 18:43:55 -07003063 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3064 for (CellInfo ci : info) {
3065 if (ci instanceof CellInfoGsm) {
3066 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3067 } else if (ci instanceof CellInfoWcdma) {
3068 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3069 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003070 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003071 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003072 }
3073
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003074 private List<CellInfo> getCachedCellInfo() {
3075 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3076 for (Phone phone : PhoneFactory.getPhones()) {
3077 List<CellInfo> info = phone.getAllCellInfo();
3078 if (info != null) cellInfos.addAll(info);
3079 }
3080 return cellInfos;
3081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003082
3083 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003084 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003085 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003086 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003087
3088 LocationAccessPolicy.LocationPermissionResult locationResult =
3089 LocationAccessPolicy.checkLocationPermission(mApp,
3090 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3091 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003092 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003093 .setCallingPid(Binder.getCallingPid())
3094 .setCallingUid(Binder.getCallingUid())
3095 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003096 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003097 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3098 .build());
3099 switch (locationResult) {
3100 case DENIED_HARD:
3101 throw new SecurityException("Not allowed to access cell info");
3102 case DENIED_SOFT:
3103 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104 }
3105
Nathan Haroldf096d982020-11-18 17:18:06 -08003106 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003107 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3108 return getCachedCellInfo();
3109 }
3110
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003111 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003112 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113 final long identity = Binder.clearCallingIdentity();
3114 try {
3115 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3116 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003117 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003118 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003119 if (info != null) cellInfos.addAll(info);
3120 }
3121 return cellInfos;
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003124 }
3125 }
3126
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003127 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003128 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3129 String callingFeatureId) {
3130 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3131 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003132 }
3133
3134 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003135 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3136 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003137 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003138 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003139 }
3140
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003141 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3142 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003143 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003144 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003145
3146 LocationAccessPolicy.LocationPermissionResult locationResult =
3147 LocationAccessPolicy.checkLocationPermission(mApp,
3148 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3149 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003150 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003151 .setCallingPid(Binder.getCallingPid())
3152 .setCallingUid(Binder.getCallingUid())
3153 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003154 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3155 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003156 .build());
3157 switch (locationResult) {
3158 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003159 if (TelephonyPermissions
3160 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003161 // Safetynet logging for b/154934934
3162 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3163 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003164 throw new SecurityException("Not allowed to access cell info");
3165 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003166 if (TelephonyPermissions
3167 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003168 // Safetynet logging for b/154934934
3169 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3170 }
Nathan Harold5320c422019-05-09 10:26:08 -07003171 try {
3172 cb.onCellInfo(new ArrayList<CellInfo>());
3173 } catch (RemoteException re) {
3174 // Drop without consequences
3175 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003176 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003177 }
3178
Nathan Harolda939a962019-05-09 10:13:47 -07003179
3180 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003181 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3182
3183 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3184 }
3185
3186 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003187 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003188 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003189 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190
3191 final long identity = Binder.clearCallingIdentity();
3192 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003193 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194 } finally {
3195 Binder.restoreCallingIdentity(identity);
3196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 }
3198
Shishir Agrawala9f32182016-04-12 12:00:16 -07003199 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003200 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003201 Phone phone = PhoneFactory.getPhone(slotIndex);
3202 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003203 return null;
3204 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003205 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003206 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003207 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003208 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003209 return null;
3210 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003211
3212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 return phone.getImei();
3215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003218 }
3219
3220 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003221 public String getTypeAllocationCodeForSlot(int slotIndex) {
3222 Phone phone = PhoneFactory.getPhone(slotIndex);
3223 String tac = null;
3224 if (phone != null) {
3225 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003226 try {
3227 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3228 } catch (IndexOutOfBoundsException e) {
3229 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3230 return null;
3231 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003232 }
3233 return tac;
3234 }
3235
3236 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003237 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003238 try {
3239 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3240 } catch (SecurityException se) {
3241 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3242 throw new SecurityException("Package " + callingPackage + " does not belong to "
3243 + Binder.getCallingUid());
3244 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003245 Phone phone = PhoneFactory.getPhone(slotIndex);
3246 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003247 return null;
3248 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003249
Jeff Davidson913390f2018-02-23 17:11:49 -08003250 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003251 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003252 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003253 return null;
3254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255
3256 final long identity = Binder.clearCallingIdentity();
3257 try {
3258 return phone.getMeid();
3259 } finally {
3260 Binder.restoreCallingIdentity(identity);
3261 }
Jack Yu2af8d712017-03-15 17:14:14 -07003262 }
3263
3264 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003265 public String getManufacturerCodeForSlot(int slotIndex) {
3266 Phone phone = PhoneFactory.getPhone(slotIndex);
3267 String manufacturerCode = null;
3268 if (phone != null) {
3269 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003270 try {
3271 manufacturerCode =
3272 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3273 } catch (IndexOutOfBoundsException e) {
3274 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3275 return null;
3276 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003277 }
3278 return manufacturerCode;
3279 }
3280
3281 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003282 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3283 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003284 Phone phone = PhoneFactory.getPhone(slotIndex);
3285 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003286 return null;
3287 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003288 int subId = phone.getSubId();
3289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003290 mApp, subId, callingPackage, callingFeatureId,
3291 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003292 return null;
3293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003294
3295 final long identity = Binder.clearCallingIdentity();
3296 try {
3297 return phone.getDeviceSvn();
3298 } finally {
3299 Binder.restoreCallingIdentity(identity);
3300 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003301 }
3302
fionaxu43304da2017-11-27 22:51:16 -08003303 @Override
3304 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003305 final long identity = Binder.clearCallingIdentity();
3306 try {
3307 final Phone phone = getPhone(subId);
3308 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3309 } finally {
3310 Binder.restoreCallingIdentity(identity);
3311 }
fionaxu43304da2017-11-27 22:51:16 -08003312 }
3313
3314 @Override
3315 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316 final long identity = Binder.clearCallingIdentity();
3317 try {
3318 final Phone phone = getPhone(subId);
3319 return phone == null ? null : phone.getCarrierName();
3320 } finally {
3321 Binder.restoreCallingIdentity(identity);
3322 }
fionaxu43304da2017-11-27 22:51:16 -08003323 }
3324
calvinpanffe225e2018-11-01 19:43:06 +08003325 @Override
chen xu0026ca62019-03-06 15:28:50 -08003326 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 final Phone phone = getPhone(subId);
3330 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003331 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003332 } finally {
3333 Binder.restoreCallingIdentity(identity);
3334 }
3335 }
3336
3337 @Override
chen xu0026ca62019-03-06 15:28:50 -08003338 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003339 final long identity = Binder.clearCallingIdentity();
3340 try {
3341 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003342 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003343 } finally {
3344 Binder.restoreCallingIdentity(identity);
3345 }
3346 }
3347
chen xu651eec72018-11-11 19:03:44 -08003348 @Override
chen xu864e11c2018-12-06 22:10:03 -08003349 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3350 if (!isSubscriptionMccMnc) {
3351 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3352 }
chen xu651eec72018-11-11 19:03:44 -08003353 final Phone phone = PhoneFactory.getPhone(slotIndex);
3354 if (phone == null) {
3355 return TelephonyManager.UNKNOWN_CARRIER_ID;
3356 }
3357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3360 } finally {
3361 Binder.restoreCallingIdentity(identity);
3362 }
3363 }
3364
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003365 //
3366 // Internal helper methods.
3367 //
3368
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003369 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003370 * Make sure the caller is the calling package itself
3371 *
3372 * @throws SecurityException if the caller is not the calling package
3373 */
3374 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3375 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003376 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3377 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003378 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003379 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003380 } catch (PackageManager.NameNotFoundException e) {
3381 // packageUid is -1
3382 }
3383 if (packageUid != callingUid) {
3384 throw new SecurityException(message + ": Package " + callingPackage
3385 + " does not belong to " + callingUid);
3386 }
3387 }
3388
3389 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3391 *
3392 * @throws SecurityException if the caller does not have the required permission
3393 */
3394 private void enforceModifyPermission() {
3395 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3396 }
3397
Shuo Qiancd19c462020-01-16 20:51:11 -08003398 /**
3399 * Make sure the caller is system.
3400 *
3401 * @throws SecurityException if the caller is not system.
3402 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003403 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003404 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3405 throw new SecurityException("Caller must be system");
3406 }
3407 }
3408
Shuo Qian3b6ee772019-11-13 17:43:31 -08003409 private void enforceActiveEmergencySessionPermission() {
3410 mApp.enforceCallingOrSelfPermission(
3411 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3412 }
3413
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003414 /**
3415 * Make sure the caller has the CALL_PHONE permission.
3416 *
3417 * @throws SecurityException if the caller does not have the required permission
3418 */
3419 private void enforceCallPermission() {
3420 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3421 }
3422
paulhu5a773602019-08-23 19:17:33 +08003423 private void enforceSettingsPermission() {
3424 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003425 }
3426
Michele Berionne5e411512020-11-13 02:36:59 +00003427 private void enforceRebootPermission() {
3428 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3429 }
3430
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003431 private String createTelUrl(String number) {
3432 if (TextUtils.isEmpty(number)) {
3433 return null;
3434 }
3435
Jake Hambye994d462014-02-03 13:10:13 -08003436 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003437 }
3438
Ihab Awadf9e92732013-12-05 18:02:52 -08003439 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003440 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3441 }
3442
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003443 private static void logv(String msg) {
3444 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3445 }
3446
Ihab Awadf9e92732013-12-05 18:02:52 -08003447 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003448 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3449 }
3450
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003451 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003453 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003454 }
3455
Sanket Padawe356d7632015-06-22 14:03:32 -07003456 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003457 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003458 final long identity = Binder.clearCallingIdentity();
3459 try {
3460 final Phone phone = PhoneFactory.getPhone(slotIndex);
3461 if (phone == null) {
3462 return PhoneConstants.PHONE_TYPE_NONE;
3463 } else {
3464 return phone.getPhoneType();
3465 }
3466 } finally {
3467 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003469 }
3470
3471 /**
3472 * Returns the CDMA ERI icon index to display
3473 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003474 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003475 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3476 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3477 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003478 }
3479
Sanket Padawe356d7632015-06-22 14:03:32 -07003480 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003481 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3482 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003483 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003484 mApp, subId, callingPackage, callingFeatureId,
3485 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003486 return -1;
3487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003488
3489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 final Phone phone = getPhone(subId);
3492 if (phone != null) {
3493 return phone.getCdmaEriIconIndex();
3494 } else {
3495 return -1;
3496 }
3497 } finally {
3498 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003500 }
3501
3502 /**
3503 * Returns the CDMA ERI icon mode,
3504 * 0 - ON
3505 * 1 - FLASHING
3506 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003507 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003508 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3509 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3510 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003511 }
3512
Sanket Padawe356d7632015-06-22 14:03:32 -07003513 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003514 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3515 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003516 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003517 mApp, subId, callingPackage, callingFeatureId,
3518 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003519 return -1;
3520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003521
3522 final long identity = Binder.clearCallingIdentity();
3523 try {
3524 final Phone phone = getPhone(subId);
3525 if (phone != null) {
3526 return phone.getCdmaEriIconMode();
3527 } else {
3528 return -1;
3529 }
3530 } finally {
3531 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003533 }
3534
3535 /**
3536 * Returns the CDMA ERI text,
3537 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003539 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3540 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3541 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003542 }
3543
Sanket Padawe356d7632015-06-22 14:03:32 -07003544 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003545 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3546 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003548 mApp, subId, callingPackage, callingFeatureId,
3549 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003550 return null;
3551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003552
3553 final long identity = Binder.clearCallingIdentity();
3554 try {
3555 final Phone phone = getPhone(subId);
3556 if (phone != null) {
3557 return phone.getCdmaEriText();
3558 } else {
3559 return null;
3560 }
3561 } finally {
3562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003564 }
3565
3566 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003567 * Returns the CDMA MDN.
3568 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003569 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003570 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3572 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573
3574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003577 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578 return phone.getLine1Number();
3579 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003580 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581 return null;
3582 }
3583 } finally {
3584 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003585 }
3586 }
3587
3588 /**
3589 * Returns the CDMA MIN.
3590 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003591 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003592 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3594 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595
3596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 final Phone phone = getPhone(subId);
3599 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3600 return phone.getCdmaMin();
3601 } else {
3602 return null;
3603 }
3604 } finally {
3605 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003606 }
3607 }
3608
Hall Liud892bec2018-11-30 14:51:45 -08003609 @Override
3610 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3611 INumberVerificationCallback callback, String callingPackage) {
3612 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3613 != PERMISSION_GRANTED) {
3614 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3615 }
3616 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3617
3618 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3619 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003620 throw new SecurityException("Calling package must be configured in the device config: "
3621 + "calling package: " + callingPackage
3622 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003623 }
3624
3625 if (range == null) {
3626 throw new NullPointerException("Range must be non-null");
3627 }
3628
3629 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003630 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003631
3632 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3633 }
3634
Junda Liuca05d5d2014-08-14 22:36:34 -07003635 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003636 * Returns true if CDMA provisioning needs to run.
3637 */
3638 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003639 final long identity = Binder.clearCallingIdentity();
3640 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003641 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003642 } finally {
3643 Binder.restoreCallingIdentity(identity);
3644 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003645 }
3646
3647 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003648 * Sets the voice mail number of a given subId.
3649 */
3650 @Override
3651 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003652 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3653 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654
3655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3658 new Pair<String, String>(alphaTag, number), new Integer(subId));
3659 return success;
3660 } finally {
3661 Binder.restoreCallingIdentity(identity);
3662 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003663 }
3664
Ta-wei Yen87c49842016-05-13 21:19:52 -07003665 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003666 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3667 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003668 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3669 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003670 if (!TextUtils.equals(callingPackage, systemDialer)) {
3671 throw new SecurityException("caller must be system dialer");
3672 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673
3674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3677 if (phoneAccountHandle == null) {
3678 return null;
3679 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003680 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003681 } finally {
3682 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003683 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003684 }
3685
3686 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003687 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3688 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003689 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003690 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003691 mApp, subId, callingPackage, callingFeatureId,
3692 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003693 return null;
3694 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003695
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003696 final long identity = Binder.clearCallingIdentity();
3697 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003698 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003699 } finally {
3700 Binder.restoreCallingIdentity(identity);
3701 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003702 }
3703
3704 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003705 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3706 VisualVoicemailSmsFilterSettings settings) {
3707 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003708
3709 final long identity = Binder.clearCallingIdentity();
3710 try {
3711 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003712 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003713 } finally {
3714 Binder.restoreCallingIdentity(identity);
3715 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003716 }
3717
3718 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003719 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3720 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003721
3722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003725 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003729 }
3730
3731 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003732 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3733 String callingPackage, int subId) {
3734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003735
3736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003739 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003740 } finally {
3741 Binder.restoreCallingIdentity(identity);
3742 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003743 }
3744
3745 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003746 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748
3749 final long identity = Binder.clearCallingIdentity();
3750 try {
3751 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003752 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003753 } finally {
3754 Binder.restoreCallingIdentity(identity);
3755 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003756 }
3757
3758 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003759 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3760 String callingAttributionTag, int subId, String number, int port, String text,
3761 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003762 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003763 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003764 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003765 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003766 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3767 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003768 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003769
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003770 /**
fionaxu0152e512016-11-14 13:36:14 -08003771 * Sets the voice activation state of a given subId.
3772 */
3773 @Override
3774 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3776 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003777
3778 final long identity = Binder.clearCallingIdentity();
3779 try {
3780 final Phone phone = getPhone(subId);
3781 if (phone != null) {
3782 phone.setVoiceActivationState(activationState);
3783 } else {
3784 loge("setVoiceActivationState fails with invalid subId: " + subId);
3785 }
3786 } finally {
3787 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003788 }
3789 }
3790
3791 /**
3792 * Sets the data activation state of a given subId.
3793 */
3794 @Override
3795 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3797 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798
3799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 final Phone phone = getPhone(subId);
3802 if (phone != null) {
3803 phone.setDataActivationState(activationState);
3804 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003805 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806 }
3807 } finally {
3808 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003809 }
3810 }
3811
3812 /**
3813 * Returns the voice activation state of a given subId.
3814 */
3815 @Override
3816 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003817 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003818
fionaxu0152e512016-11-14 13:36:14 -08003819 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 if (phone != null) {
3823 return phone.getVoiceActivationState();
3824 } else {
3825 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3826 }
3827 } finally {
3828 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003829 }
3830 }
3831
3832 /**
3833 * Returns the data activation state of a given subId.
3834 */
3835 @Override
3836 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003837 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003838
fionaxu0152e512016-11-14 13:36:14 -08003839 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003840 final long identity = Binder.clearCallingIdentity();
3841 try {
3842 if (phone != null) {
3843 return phone.getDataActivationState();
3844 } else {
3845 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3846 }
3847 } finally {
3848 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003849 }
3850 }
3851
3852 /**
Wink Saville36469e72014-06-11 15:17:00 -07003853 * Returns the unread count of voicemails for a subId
3854 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003855 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003856 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3857 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003859 mApp, subId, callingPackage, callingFeatureId,
3860 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003861 return 0;
3862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003863 final long identity = Binder.clearCallingIdentity();
3864 try {
3865 final Phone phone = getPhone(subId);
3866 if (phone != null) {
3867 return phone.getVoiceMessageCount();
3868 } else {
3869 return 0;
3870 }
3871 } finally {
3872 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003874 }
3875
3876 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003877 * returns true, if the device is in a state where both voice and data
3878 * are supported simultaneously. This can change based on location or network condition.
3879 */
3880 @Override
3881 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003882 final long identity = Binder.clearCallingIdentity();
3883 try {
3884 final Phone phone = getPhone(subId);
3885 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3886 } finally {
3887 Binder.restoreCallingIdentity(identity);
3888 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003889 }
3890
3891 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003892 * Send the dialer code if called from the current default dialer or the caller has
3893 * carrier privilege.
3894 * @param inputCode The dialer code to send
3895 */
3896 @Override
3897 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003898 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003899 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003900 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3901 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003902 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003903 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003904 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003905 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003906
3907 final long identity = Binder.clearCallingIdentity();
3908 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003909 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910 } finally {
3911 Binder.restoreCallingIdentity(identity);
3912 }
fionaxu235cc5e2017-03-06 22:25:57 -08003913 }
3914
Pengquan Menga1bb6272018-09-06 09:59:22 -07003915 @Override
3916 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003917 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003918 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003919 mApp, subId, "getNetworkSelectionMode");
3920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 if (!isActiveSubscription(subId)) {
3923 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3924 }
3925 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3926 } finally {
3927 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003928 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003929 }
3930
Brad Ebinger35c841c2018-10-01 10:40:55 -07003931 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003932 public boolean isInEmergencySmsMode() {
3933 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 for (Phone phone : PhoneFactory.getPhones()) {
3937 if (phone.isInEmergencySmsMode()) {
3938 return true;
3939 }
3940 }
3941 } finally {
3942 Binder.restoreCallingIdentity(identity);
3943 }
3944 return false;
3945 }
3946
shilu366312e2019-12-17 09:28:10 -08003947 /**
3948 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3949 * @param subId The subscription to use to check the configuration.
3950 * @param c The callback that will be used to send the result.
3951 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003952 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003953 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3954 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003955 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003956 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003957
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003958 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3959 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3960 "IMS not available on device.");
3961 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003962 final long token = Binder.clearCallingIdentity();
3963 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003964 int slotId = getSlotIndexOrException(subId);
3965 verifyImsMmTelConfiguredOrThrow(slotId);
3966 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003967 } catch (ImsException e) {
3968 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 } finally {
3970 Binder.restoreCallingIdentity(token);
3971 }
3972 }
3973
shilu366312e2019-12-17 09:28:10 -08003974 /**
3975 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3976 * @param subId The subscription to use to check the configuration.
3977 * @param c The callback that will be used to send the result.
3978 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003980 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003981 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003982 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003983 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3984 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3985 }
Meng Wangafbc5852019-09-19 17:37:13 -07003986 final long token = Binder.clearCallingIdentity();
3987 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003988 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3989 .removeRegistrationCallbackForSubscription(c, subId);
3990 } catch (ImsException e) {
3991 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3992 + "is inactive, ignoring unregister.");
3993 // If the subscription is no longer active, just return, since the callback
3994 // will already have been removed internally.
3995 } finally {
3996 Binder.restoreCallingIdentity(token);
3997 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003998 }
3999
Brad Ebingera34a6c22019-10-22 17:36:18 -07004000 /**
4001 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4002 */
4003 @Override
4004 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4005 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4006 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4007 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4008 "IMS not available on device.");
4009 }
4010 final long token = Binder.clearCallingIdentity();
4011 try {
4012 Phone phone = getPhone(subId);
4013 if (phone == null) {
4014 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4015 + subId + "'");
4016 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4017 }
4018 phone.getImsRegistrationState(regState -> {
4019 try {
4020 consumer.accept((regState == null)
4021 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4022 } catch (RemoteException e) {
4023 // Ignore if the remote process is no longer available to call back.
4024 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4025 }
4026 });
4027 } finally {
4028 Binder.restoreCallingIdentity(token);
4029 }
4030 }
4031
4032 /**
4033 * Get the transport type for the IMS service registration state.
4034 */
4035 @Override
4036 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004037 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004038 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004039 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4040 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4041 "IMS not available on device.");
4042 }
4043 final long token = Binder.clearCallingIdentity();
4044 try {
4045 Phone phone = getPhone(subId);
4046 if (phone == null) {
4047 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4048 + subId + "'");
4049 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4050 }
4051 phone.getImsRegistrationTech(regTech -> {
4052 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4053 int regTechConverted = (regTech == null)
4054 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4055 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4056 regTechConverted);
4057 try {
4058 consumer.accept(regTechConverted);
4059 } catch (RemoteException e) {
4060 // Ignore if the remote process is no longer available to call back.
4061 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4062 }
4063 });
4064 } finally {
4065 Binder.restoreCallingIdentity(token);
4066 }
4067 }
4068
shilu366312e2019-12-17 09:28:10 -08004069 /**
4070 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4071 * @param subId The subscription to use to check the configuration.
4072 * @param c The callback that will be used to send the result.
4073 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004075 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4076 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004077 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004078 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004079 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4080 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4081 "IMS not available on device.");
4082 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004083 final long token = Binder.clearCallingIdentity();
4084 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004085 int slotId = getSlotIndexOrException(subId);
4086 verifyImsMmTelConfiguredOrThrow(slotId);
4087 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004088 } catch (ImsException e) {
4089 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004090 } finally {
4091 Binder.restoreCallingIdentity(token);
4092 }
4093 }
4094
shilu366312e2019-12-17 09:28:10 -08004095 /**
4096 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4097 * @param subId The subscription to use to check the configuration.
4098 * @param c The callback that will be used to send the result.
4099 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004100 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004101 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004102 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004103 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004104 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4105 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4106 }
Meng Wangafbc5852019-09-19 17:37:13 -07004107
4108 final long token = Binder.clearCallingIdentity();
4109 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004110 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004111 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004112 } catch (ImsException e) {
4113 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4114 + "is inactive, ignoring unregister.");
4115 // If the subscription is no longer active, just return, since the callback
4116 // will already have been removed internally.
4117 } finally {
4118 Binder.restoreCallingIdentity(token);
4119 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004120 }
4121
4122 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004123 public boolean isCapable(int subId, int capability, int regTech) {
4124 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004125 final long token = Binder.clearCallingIdentity();
4126 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004127 int slotId = getSlotIndexOrException(subId);
4128 verifyImsMmTelConfiguredOrThrow(slotId);
4129 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004130 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004131 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4132 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004133 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004134 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4135 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004136 } finally {
4137 Binder.restoreCallingIdentity(token);
4138 }
4139 }
4140
4141 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004142 public boolean isAvailable(int subId, int capability, int regTech) {
4143 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 final long token = Binder.clearCallingIdentity();
4145 try {
4146 Phone phone = getPhone(subId);
4147 if (phone == null) return false;
4148 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004149 } catch (com.android.ims.ImsException e) {
4150 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4151 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 } finally {
4153 Binder.restoreCallingIdentity(token);
4154 }
4155 }
4156
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004157 /**
4158 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4159 * subscription.
4160 * @param subId The subscription to use to check the configuration.
4161 * @param callback The callback that will be used to send the result.
4162 * @param capability The MmTelFeature capability that will be used to send the result.
4163 * @param transportType The transport type of the MmTelFeature capability.
4164 */
4165 @Override
4166 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4167 int transportType) {
4168 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4169 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4170 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4171 "IMS not available on device.");
4172 }
4173 final long token = Binder.clearCallingIdentity();
4174 try {
4175 int slotId = getSlotIndex(subId);
4176 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4177 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4178 + subId + "'");
4179 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4180 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004181 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004182 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4183 transportType, aBoolean -> {
4184 try {
4185 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4186 } catch (RemoteException e) {
4187 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4188 + "running. Ignore");
4189 }
4190 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004191 } catch (ImsException e) {
4192 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004193 } finally {
4194 Binder.restoreCallingIdentity(token);
4195 }
4196 }
4197
shilu366312e2019-12-17 09:28:10 -08004198 /**
4199 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4200 * @param subId The subscription to use to check the configuration.
4201 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004202 @Override
4203 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004204 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004205 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004206
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 final long token = Binder.clearCallingIdentity();
4208 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004209 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004210 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004211 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004212 } catch (ImsException e) {
4213 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 } finally {
4215 Binder.restoreCallingIdentity(token);
4216 }
4217 }
4218
4219 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004220 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004222 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004223 final long identity = Binder.clearCallingIdentity();
4224 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004225 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004226 // This setting doesn't require an active ImsService connection, so do not verify. The
4227 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004228 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004229 } catch (ImsException e) {
4230 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004231 } finally {
4232 Binder.restoreCallingIdentity(identity);
4233 }
4234 }
4235
shilu366312e2019-12-17 09:28:10 -08004236 /**
4237 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4238 * @param subId The subscription to use to check the configuration.
4239 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004240 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004241 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004242 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004243 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 final long identity = Binder.clearCallingIdentity();
4245 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004246 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004247 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004248 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004249 } catch (ImsException e) {
4250 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004251 } finally {
4252 Binder.restoreCallingIdentity(identity);
4253 }
4254 }
4255
4256 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004257 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004259 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004260 final long identity = Binder.clearCallingIdentity();
4261 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004262 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004263 // This setting doesn't require an active ImsService connection, so do not verify. The
4264 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004265 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004266 } catch (ImsException e) {
4267 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 } finally {
4269 Binder.restoreCallingIdentity(identity);
4270 }
4271 }
4272
shilu366312e2019-12-17 09:28:10 -08004273 /**
4274 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4275 * @param subId The subscription to use to check the configuration.
4276 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004277 @Override
4278 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004279 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004280 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004281 final long identity = Binder.clearCallingIdentity();
4282 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004283 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004284 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004285 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004286 } catch (ImsException e) {
4287 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004288 } finally {
4289 Binder.restoreCallingIdentity(identity);
4290 }
4291 }
4292
4293 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004294 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004296 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004297 final long identity = Binder.clearCallingIdentity();
4298 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004300 // This setting doesn't require an active ImsService connection, so do not verify. The
4301 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004302 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004303 } catch (ImsException e) {
4304 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004305 } finally {
4306 Binder.restoreCallingIdentity(identity);
4307 }
4308 }
4309
shilu366312e2019-12-17 09:28:10 -08004310 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004311 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4312 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4313 * @param subId The subscription to use to check the configuration.
4314 */
4315 @Override
4316 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004317 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004318 mApp, subId, "isCrossSimCallingEnabledByUser");
4319 final long identity = Binder.clearCallingIdentity();
4320 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004321 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004322 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004323 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004324 } catch (ImsException e) {
4325 throw new ServiceSpecificException(e.getCode());
4326 } finally {
4327 Binder.restoreCallingIdentity(identity);
4328 }
4329 }
4330
4331 /**
4332 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4333 * Requires MODIFY_PHONE_STATE permission.
4334 * @param subId The subscription to use to check the configuration.
4335 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4336 * false otherwise
4337 */
4338 @Override
4339 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4341 "setCrossSimCallingEnabled");
4342 final long identity = Binder.clearCallingIdentity();
4343 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004344 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004345 // This setting doesn't require an active ImsService connection, so do not verify. The
4346 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004347 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004348 } catch (ImsException e) {
4349 throw new ServiceSpecificException(e.getCode());
4350 } finally {
4351 Binder.restoreCallingIdentity(identity);
4352 }
4353 }
4354
4355 /**
shilu366312e2019-12-17 09:28:10 -08004356 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4357 * @param subId The subscription to use to check the configuration.
4358 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004359 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004360
Brad Ebinger35c841c2018-10-01 10:40:55 -07004361 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004362 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004363 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 final long identity = Binder.clearCallingIdentity();
4365 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004366 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004367 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004368 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004369 } catch (ImsException e) {
4370 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 } finally {
4372 Binder.restoreCallingIdentity(identity);
4373 }
4374 }
4375
4376 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004377 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004379 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004380 final long identity = Binder.clearCallingIdentity();
4381 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004382 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004383 // This setting doesn't require an active ImsService connection, so do not verify. The
4384 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004385 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004386 } catch (ImsException e) {
4387 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004388 } finally {
4389 Binder.restoreCallingIdentity(identity);
4390 }
4391 }
4392
4393 @Override
4394 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4396 "setVoWiFiNonPersistent");
4397 final long identity = Binder.clearCallingIdentity();
4398 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004399 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004400 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004401 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004402 } catch (ImsException e) {
4403 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004404 } finally {
4405 Binder.restoreCallingIdentity(identity);
4406 }
4407 }
4408
shilu366312e2019-12-17 09:28:10 -08004409 /**
4410 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4411 * @param subId The subscription to use to check the configuration.
4412 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004413 @Override
4414 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004415 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004416 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004417 final long identity = Binder.clearCallingIdentity();
4418 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004419 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004420 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004421 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004422 } catch (ImsException e) {
4423 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004424 } finally {
4425 Binder.restoreCallingIdentity(identity);
4426 }
4427 }
4428
4429 @Override
4430 public void setVoWiFiModeSetting(int subId, int mode) {
4431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4432 "setVoWiFiModeSetting");
4433 final long identity = Binder.clearCallingIdentity();
4434 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004435 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004436 // This setting doesn't require an active ImsService connection, so do not verify. The
4437 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004438 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004439 } catch (ImsException e) {
4440 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004441 } finally {
4442 Binder.restoreCallingIdentity(identity);
4443 }
4444 }
4445
4446 @Override
4447 public int getVoWiFiRoamingModeSetting(int subId) {
4448 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4449 final long identity = Binder.clearCallingIdentity();
4450 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004451 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004452 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004453 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004454 } catch (ImsException e) {
4455 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004456 } finally {
4457 Binder.restoreCallingIdentity(identity);
4458 }
4459 }
4460
4461 @Override
4462 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4464 "setVoWiFiRoamingModeSetting");
4465 final long identity = Binder.clearCallingIdentity();
4466 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004467 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004468 // This setting doesn't require an active ImsService connection, so do not verify. The
4469 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004470 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004471 } catch (ImsException e) {
4472 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004473 } finally {
4474 Binder.restoreCallingIdentity(identity);
4475 }
4476 }
4477
4478 @Override
4479 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4481 "setRttCapabilityEnabled");
4482 final long identity = Binder.clearCallingIdentity();
4483 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004484 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004485 // This setting doesn't require an active ImsService connection, so do not verify. The
4486 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004487 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004488 } catch (ImsException e) {
4489 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004490 } finally {
4491 Binder.restoreCallingIdentity(identity);
4492 }
4493 }
4494
shilu366312e2019-12-17 09:28:10 -08004495 /**
4496 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4497 * @param subId The subscription to use to check the configuration.
4498 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004499 @Override
4500 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004501 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004502 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004503 final long identity = Binder.clearCallingIdentity();
4504 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004505 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004506 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004507 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004508 } catch (ImsException e) {
4509 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004510 } finally {
4511 Binder.restoreCallingIdentity(identity);
4512 }
4513 }
4514
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004515 @Override
4516 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4517 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4518 final long identity = Binder.clearCallingIdentity();
4519 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004520 if (!isImsAvailableOnDevice()) {
4521 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4522 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004523 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004524 int slotId = getSlotIndexOrException(subId);
4525 verifyImsMmTelConfiguredOrThrow(slotId);
4526 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004527 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004528 } catch (ImsException e) {
4529 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004530 } finally {
4531 Binder.restoreCallingIdentity(identity);
4532 }
4533 }
4534
4535 @Override
4536 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4537 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4538 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004539 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4540 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4541 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004542 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004543 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004544 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004545 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004546 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4547 + "is inactive, ignoring unregister.");
4548 // If the subscription is no longer active, just return, since the callback will already
4549 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
4553 }
4554
allenwtsu99c623b2020-01-03 18:24:23 +08004555
4556 private void checkModifyPhoneStatePermission(int subId, String message) {
4557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4558 message);
4559 }
4560
4561 private boolean isImsProvisioningRequired(int subId, int capability,
4562 boolean isMmtelCapability) {
4563 Phone phone = getPhone(subId);
4564 if (phone == null) {
4565 loge("phone instance null for subid " + subId);
4566 return false;
4567 }
4568 if (isMmtelCapability) {
4569 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4570 return false;
4571 }
4572 } else {
4573 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4574 return false;
4575 }
4576 }
4577 return true;
4578 }
4579
4580 @Override
4581 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4582 boolean isProvisioned) {
4583 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4584
4585 final long identity = Binder.clearCallingIdentity();
4586 try {
4587 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4588 if (!isImsProvisioningRequired(subId, capability, false)) {
4589 return;
4590 }
4591
4592 // this capability requires provisioning, route to the correct API.
4593 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4594 switch (capability) {
4595 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4596 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4597 ims.setEabProvisioned(isProvisioned);
4598 break;
4599 default: {
4600 throw new IllegalArgumentException("Tried to set provisioning for "
4601 + "rcs capability '" + capability + "', which does not require "
4602 + "provisioning.");
4603 }
4604 }
4605 } finally {
4606 Binder.restoreCallingIdentity(identity);
4607 }
4608
4609 }
4610
4611
4612 @Override
4613 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4614 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4615 final long identity = Binder.clearCallingIdentity();
4616 try {
4617 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4618 if (!isImsProvisioningRequired(subId, capability, false)) {
4619 return true;
4620 }
4621
4622 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4623 switch (capability) {
4624 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4625 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4626 return ims.isEabProvisionedOnDevice();
4627
4628 default: {
4629 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4630 + "capability '" + capability + "', which does not require "
4631 + "provisioning.");
4632 }
4633 }
4634
4635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
4638 }
4639
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004640 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004641 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4642 boolean isProvisioned) {
4643 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004644 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4645 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4646 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004647 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4648 }
allenwtsu99c623b2020-01-03 18:24:23 +08004649 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004650 final long identity = Binder.clearCallingIdentity();
4651 try {
4652 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004653 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004654 return;
4655 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004656 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4657 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4658 loge("setImsProvisioningStatusForCapability: called for technology that does "
4659 + "not support provisioning - " + tech);
4660 return;
4661 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004662
4663 // this capability requires provisioning, route to the correct API.
4664 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4665 switch (capability) {
4666 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4667 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4668 ims.setVolteProvisioned(isProvisioned);
4669 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4670 ims.setWfcProvisioned(isProvisioned);
4671 }
4672 break;
4673 }
4674 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4675 // There is currently no difference in VT provisioning type.
4676 ims.setVtProvisioned(isProvisioned);
4677 break;
4678 }
4679 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4680 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4681 // change the capability of the feature instead if needed.
4682 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4683 == isProvisioned) {
4684 // No change in provisioning.
4685 return;
4686 }
4687 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4688 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004689 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004690 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004691 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4692 + ", Exception" + e.getMessage());
4693 }
4694 break;
4695 }
4696 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004697 throw new IllegalArgumentException("Tried to set provisioning for "
4698 + "MmTel capability '" + capability + "', which does not require "
4699 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004700 }
4701 }
4702
4703 } finally {
4704 Binder.restoreCallingIdentity(identity);
4705 }
4706 }
4707
4708 @Override
4709 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4710 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004711 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4712 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4713 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004714 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4715 }
4716 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4717 final long identity = Binder.clearCallingIdentity();
4718 try {
4719 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004720 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004721 return true;
4722 }
4723
Brad Ebinger0d79c572021-04-17 15:20:49 -07004724 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4725 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4726 loge("getImsProvisioningStatusForCapability: called for technology that does "
4727 + "not support provisioning - " + tech);
4728 return true;
4729 }
4730
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004731 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4732 switch (capability) {
4733 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4734 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4735 return ims.isVolteProvisionedOnDevice();
4736 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4737 return ims.isWfcProvisionedOnDevice();
4738 }
4739 // This should never happen, since we are checking tech above to make sure it
4740 // is either LTE or IWLAN.
4741 throw new IllegalArgumentException("Invalid radio technology for voice "
4742 + "capability.");
4743 }
4744 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4745 // There is currently no difference in VT provisioning type.
4746 return ims.isVtProvisionedOnDevice();
4747 }
4748 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4749 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4750 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4751 }
4752 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004753 throw new IllegalArgumentException(
4754 "Tried to get provisioning for MmTel capability '" + capability
4755 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004756 }
4757 }
4758
4759 } finally {
4760 Binder.restoreCallingIdentity(identity);
4761 }
4762 }
4763
4764 @Override
4765 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4766 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4767 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4768 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4769 }
4770 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4771 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4772 return (provisionedBits & capability) > 0;
4773 }
4774
4775 @Override
4776 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4777 boolean isProvisioned) {
4778 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4779 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4780 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4781 }
4782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4783 "setProvisioningStatusForCapability");
4784 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4785 // If the current provisioning status for capability already matches isProvisioned,
4786 // do nothing.
4787 if (((provisionedBits & capability) > 0) == isProvisioned) {
4788 return;
4789 }
4790 if (isProvisioned) {
4791 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4792 } else {
4793 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4794 }
4795 }
4796
4797 /**
4798 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4799 * technology. The bitfield should mirror the bitfield defined by
4800 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4801 */
4802 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4803 String key = getMmTelProvisioningKey(subId, tech);
4804 // Default is no capabilities are provisioned.
4805 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4806 }
4807
4808 /**
4809 * Sets the MmTel capability provisioning bitfield (defined by
4810 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4811 * technology specified.
4812 *
4813 * Note: This is a synchronous command and should not be called on UI thread.
4814 */
4815 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4816 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4817 String key = getMmTelProvisioningKey(subId, tech);
4818 editor.putInt(key, newField);
4819 editor.commit();
4820 }
4821
4822 private static String getMmTelProvisioningKey(int subId, int tech) {
4823 // resulting key is provision_ims_mmtel_{subId}_{tech}
4824 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4825 }
4826
4827 /**
4828 * Query CarrierConfig to see if the specified capability requires provisioning for the
4829 * carrier associated with the subscription id.
4830 */
4831 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4832 int capability) {
4833 CarrierConfigManager configManager = new CarrierConfigManager(context);
4834 PersistableBundle c = configManager.getConfigForSubId(subId);
4835 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004836 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004837 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4838 false);
4839 boolean requireVoiceVtProvisioning = c.getBoolean(
4840 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4841
4842 // First check to make sure that the capability requires provisioning.
4843 switch (capability) {
4844 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4845 // intentional fallthrough
4846 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4847 if (requireVoiceVtProvisioning) {
4848 // Voice and Video requires provisioning
4849 return true;
4850 }
4851 break;
4852 }
4853 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4854 if (requireUtProvisioning) {
4855 // UT requires provisioning
4856 return true;
4857 }
4858 break;
4859 }
4860 }
4861 return false;
4862 }
4863
allenwtsu99c623b2020-01-03 18:24:23 +08004864 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4865 int capability) {
4866 CarrierConfigManager configManager = new CarrierConfigManager(context);
4867 PersistableBundle c = configManager.getConfigForSubId(subId);
4868
4869 boolean requireRcsProvisioning = c.getBoolean(
4870 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4871
4872 // First check to make sure that the capability requires provisioning.
4873 switch (capability) {
4874 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4875 // intentional fallthrough
4876 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4877 if (requireRcsProvisioning) {
4878 // OPTION or PRESENCE requires provisioning
4879 return true;
4880 }
4881 break;
4882 }
4883 }
4884 return false;
4885 }
4886
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004887 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004888 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004889 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4890 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4891 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004892 enforceReadPrivilegedPermission("getImsProvisioningInt");
4893 final long identity = Binder.clearCallingIdentity();
4894 try {
4895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004896 int slotId = getSlotIndex(subId);
4897 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4898 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4899 + subId + "' for key:" + key);
4900 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4901 }
calvinpanb5a34062021-02-08 19:59:36 +08004902 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004903 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004904 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4905 + subId + "' for key:" + key);
4906 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004907 } finally {
4908 Binder.restoreCallingIdentity(identity);
4909 }
4910 }
4911
4912 @Override
4913 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004914 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4915 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4916 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004917 enforceReadPrivilegedPermission("getImsProvisioningString");
4918 final long identity = Binder.clearCallingIdentity();
4919 try {
4920 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004921 int slotId = getSlotIndex(subId);
4922 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4923 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4924 + subId + "' for key:" + key);
4925 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4926 }
calvinpanb5a34062021-02-08 19:59:36 +08004927 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004928 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004929 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4930 + subId + "' for key:" + key);
4931 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
4935 }
4936
4937 @Override
4938 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004939 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4940 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4941 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4943 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004944 final long identity = Binder.clearCallingIdentity();
4945 try {
4946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004947 int slotId = getSlotIndex(subId);
4948 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4949 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4950 + subId + "' for key:" + key);
4951 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4952 }
calvinpanb5a34062021-02-08 19:59:36 +08004953 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4954 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004955 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004956 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004957 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004958 } finally {
4959 Binder.restoreCallingIdentity(identity);
4960 }
4961 }
4962
4963 @Override
4964 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004965 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4966 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4967 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4969 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004973 int slotId = getSlotIndex(subId);
4974 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4975 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4976 + subId + "' for key:" + key);
4977 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4978 }
calvinpanb5a34062021-02-08 19:59:36 +08004979 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4980 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004981 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004982 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004983 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004984 } finally {
4985 Binder.restoreCallingIdentity(identity);
4986 }
4987 }
4988
Brad Ebinger919631e2021-06-02 17:46:35 -07004989 /**
4990 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4991 * for the given slot ID or no ImsResolver instance has been created.
4992 * @param slotId The slot ID that the IMS service is created for.
4993 * @throws ImsException If there is no ImsService configured for this slot.
4994 */
4995 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4996 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4997 ImsFeature.FEATURE_MMTEL)) {
4998 throw new ImsException("This subscription does not support MMTEL over IMS",
4999 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5000 }
5001 }
5002
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005003 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005004 int slotId = SubscriptionManager.getSlotIndex(subId);
5005 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005006 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5007 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005008 }
5009 return slotId;
5010 }
5011
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005012 private int getSlotIndex(int subId) {
5013 int slotId = SubscriptionManager.getSlotIndex(subId);
5014 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5015 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5016 }
5017 return slotId;
5018 }
5019
Wink Saville36469e72014-06-11 15:17:00 -07005020 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005021 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005022 */
5023 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005024 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5025 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005026 try {
5027 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5028 } catch (SecurityException se) {
5029 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5030 throw new SecurityException("Package " + callingPackage + " does not belong to "
5031 + Binder.getCallingUid());
5032 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005033 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005034 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005035 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005036 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005037 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005038 mApp, subId, callingPackage, callingFeatureId,
5039 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005040 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5041 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005042
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 final long identity = Binder.clearCallingIdentity();
5044 try {
5045 final Phone phone = getPhone(subId);
5046 if (phone != null) {
5047 return phone.getServiceState().getDataNetworkType();
5048 } else {
5049 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5050 }
5051 } finally {
5052 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005053 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005054 }
5055
5056 /**
5057 * Returns the data network type
5058 */
5059 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005060 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005061 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5062 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005063 }
5064
5065 /**
5066 * Returns the data network type for a subId
5067 */
5068 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005069 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5070 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005071 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005072 mApp, subId, callingPackage, callingFeatureId,
5073 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005074 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5075 }
5076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077 final long identity = Binder.clearCallingIdentity();
5078 try {
5079 final Phone phone = getPhone(subId);
5080 if (phone != null) {
5081 return phone.getServiceState().getDataNetworkType();
5082 } else {
5083 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5084 }
5085 } finally {
5086 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005087 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005088 }
5089
5090 /**
Wink Saville36469e72014-06-11 15:17:00 -07005091 * Returns the Voice network type for a subId
5092 */
5093 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005094 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5095 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005096 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005097 mApp, subId, callingPackage, callingFeatureId,
5098 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005099 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5100 }
5101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 final long identity = Binder.clearCallingIdentity();
5103 try {
5104 final Phone phone = getPhone(subId);
5105 if (phone != null) {
5106 return phone.getServiceState().getVoiceNetworkType();
5107 } else {
5108 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5109 }
5110 } finally {
5111 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005113 }
5114
5115 /**
5116 * @return true if a ICC card is present
5117 */
5118 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005119 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005120 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5121 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005122 }
5123
5124 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005125 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005126 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005127 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005128 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005129 final long identity = Binder.clearCallingIdentity();
5130 try {
5131 final Phone phone = PhoneFactory.getPhone(slotIndex);
5132 if (phone != null) {
5133 return phone.getIccCard().hasIccCard();
5134 } else {
5135 return false;
5136 }
5137 } finally {
5138 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005139 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005140 }
5141
5142 /**
5143 * Return if the current radio is LTE on CDMA. This
5144 * is a tri-state return value as for a period of time
5145 * the mode may be unknown.
5146 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005147 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005148 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005149 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005150 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005151 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005152 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5153 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5154 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005155 }
5156
Sanket Padawe356d7632015-06-22 14:03:32 -07005157 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005158 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5159 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005160 try {
5161 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5162 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005163 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5164 }
5165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 final long identity = Binder.clearCallingIdentity();
5167 try {
5168 final Phone phone = getPhone(subId);
5169 if (phone == null) {
5170 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5171 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005172 return TelephonyProperties.lte_on_cdma_device()
5173 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 }
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005177 }
Wink Saville36469e72014-06-11 15:17:00 -07005178 }
5179
Wink Saville36469e72014-06-11 15:17:00 -07005180 /**
5181 * {@hide}
5182 * Returns Default subId, 0 in the case of single standby.
5183 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005184 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005185 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005186 }
5187
Shishir Agrawala9f32182016-04-12 12:00:16 -07005188 private int getSlotForDefaultSubscription() {
5189 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5190 }
5191
Wink Savilleb564aae2014-10-23 10:18:09 -07005192 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005193 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005194 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005195
Pengquan Menge92a50d2018-09-21 15:54:48 -07005196 private boolean isActiveSubscription(int subId) {
5197 return mSubscriptionController.isActiveSubId(subId);
5198 }
5199
Ihab Awadf2177b72013-11-25 13:33:23 -08005200 /**
5201 * @see android.telephony.TelephonyManager.WifiCallingChoices
5202 */
5203 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 final long identity = Binder.clearCallingIdentity();
5205 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005206 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5208 getWhenToMakeWifiCallsDefaultPreference());
5209 } finally {
5210 Binder.restoreCallingIdentity(identity);
5211 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005212 }
5213
5214 /**
5215 * @see android.telephony.TelephonyManager.WifiCallingChoices
5216 */
5217 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 final long identity = Binder.clearCallingIdentity();
5219 try {
5220 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005221 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005222 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5223 } finally {
5224 Binder.restoreCallingIdentity(identity);
5225 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005226 }
5227
Sailesh Nepald1e68152013-12-12 19:08:02 -08005228 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005229 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005230 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005231 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005232
Jordan Liu4c733742019-02-28 12:03:40 -08005233 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5234 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5235 if (phoneId == -1) {
5236 throw new IllegalArgumentException("Given slot index: " + slotIndex
5237 + " does not correspond to an active phone");
5238 }
5239 return PhoneFactory.getPhone(phoneId);
5240 }
5241
Shishir Agrawal566b7612013-10-28 14:41:00 -07005242 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005243 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5244 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5246 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005248 if (DBG) {
5249 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5250 }
5251 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5252 p2);
5253 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005254
Jordan Liu4c733742019-02-28 12:03:40 -08005255
5256 @Override
5257 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5258 int slotIndex, String callingPackage, String aid, int p2) {
5259 enforceModifyPermission();
5260 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5261 if (DBG) {
5262 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5263 }
5264 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5265 callingPackage, aid, p2);
5266 }
5267
5268 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5269 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 if (TextUtils.equals(ISDR_AID, aid)) {
5273 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005274 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5275 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 if (bestComponent == null
5277 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5278 loge("The calling package is not allowed to access ISD-R.");
5279 throw new SecurityException(
5280 "The calling package is not allowed to access ISD-R.");
5281 }
Derek Tan740e1672017-06-27 14:56:27 -07005282 }
Derek Tan740e1672017-06-27 14:56:27 -07005283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005285 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5286 null /* workSource */);
5287 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 return response;
5289 } finally {
5290 Binder.restoreCallingIdentity(identity);
5291 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005292 }
5293
5294 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005295 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5297 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005298 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5299 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5300 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005301
Jordan Liu4c733742019-02-28 12:03:40 -08005302 @Override
5303 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5304 enforceModifyPermission();
5305 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5306 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5307 channel);
5308 }
5309
5310 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 final long identity = Binder.clearCallingIdentity();
5312 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313 if (channel < 0) {
5314 return false;
5315 }
Jordan Liu4c733742019-02-28 12:03:40 -08005316 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5317 null /* workSource */);
5318 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 return success;
5320 } finally {
5321 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005322 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005323 }
5324
5325 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005326 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005327 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5329 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005330 if (DBG) {
5331 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5332 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5333 + p3 + " data=" + data);
5334 }
5335 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5336 command, p1, p2, p3, data);
5337 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005338
Jordan Liu4c733742019-02-28 12:03:40 -08005339 @Override
5340 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5341 int command, int p1, int p2, int p3, String data) {
5342 enforceModifyPermission();
5343 if (DBG) {
5344 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5345 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5346 + p3 + " data=" + data);
5347 }
5348 return iccTransmitApduLogicalChannelWithPermission(
5349 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5350 data);
5351 }
5352
5353 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5354 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355 final long identity = Binder.clearCallingIdentity();
5356 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005357 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 return "";
5359 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005362 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5363 null /* workSource */);
5364 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366 // Append the returned status code to the end of the response payload.
5367 String s = Integer.toHexString(
5368 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5369 if (response.payload != null) {
5370 s = IccUtils.bytesToHexString(response.payload) + s;
5371 }
5372 return s;
5373 } finally {
5374 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005375 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005376 }
Jake Hambye994d462014-02-03 13:10:13 -08005377
Evan Charltonc66da362014-05-16 14:06:40 -07005378 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005379 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5380 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5382 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005384 if (DBG) {
5385 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5386 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5387 }
5388 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5389 cla, command, p1, p2, p3, data);
5390 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005391
Jordan Liu4c733742019-02-28 12:03:40 -08005392 @Override
5393 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5394 int command, int p1, int p2, int p3, String data) {
5395 enforceModifyPermission();
5396 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5397 if (DBG) {
5398 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5399 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5400 + " data=" + data);
5401 }
5402
5403 return iccTransmitApduBasicChannelWithPermission(
5404 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5405 p2, p3, data);
5406 }
5407
5408 // open APDU basic channel assuming the caller has sufficient permissions
5409 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5410 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 final long identity = Binder.clearCallingIdentity();
5412 try {
5413 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5414 && TextUtils.equals(ISDR_AID, data)) {
5415 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005416 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5417 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 if (bestComponent == null
5419 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5420 loge("The calling package is not allowed to select ISD-R.");
5421 throw new SecurityException(
5422 "The calling package is not allowed to select ISD-R.");
5423 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005424 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005427 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5428 null /* workSource */);
5429 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005430
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 // Append the returned status code to the end of the response payload.
5432 String s = Integer.toHexString(
5433 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5434 if (response.payload != null) {
5435 s = IccUtils.bytesToHexString(response.payload) + s;
5436 }
5437 return s;
5438 } finally {
5439 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005440 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005441 }
5442
5443 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005444 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005445 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5447 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 final long identity = Binder.clearCallingIdentity();
5450 try {
5451 if (DBG) {
5452 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5453 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5454 }
5455
5456 IccIoResult response =
5457 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5458 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5459 subId);
5460
5461 if (DBG) {
5462 log("Exchange SIM_IO [R]" + response);
5463 }
5464
5465 byte[] result = null;
5466 int length = 2;
5467 if (response.payload != null) {
5468 length = 2 + response.payload.length;
5469 result = new byte[length];
5470 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5471 } else {
5472 result = new byte[length];
5473 }
5474
5475 result[length - 1] = (byte) response.sw2;
5476 result[length - 2] = (byte) response.sw1;
5477 return result;
5478 } finally {
5479 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005480 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005481 }
5482
Nathan Haroldb3014052017-01-25 15:57:32 -08005483 /**
5484 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5485 * on a particular subscription
5486 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005487 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5488 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005490 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005491 return null;
5492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493
5494 final long identity = Binder.clearCallingIdentity();
5495 try {
5496 if (appType != TelephonyManager.APPTYPE_USIM
5497 && appType != TelephonyManager.APPTYPE_SIM) {
5498 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5499 return null;
5500 }
5501 Object response = sendRequest(
5502 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5503 if (response instanceof String[]) {
5504 return (String[]) response;
5505 }
yincheng zhao2737e882019-09-06 17:06:54 -07005506 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005508 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509 } finally {
5510 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005511 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005512 }
5513
yincheng zhao2737e882019-09-06 17:06:54 -07005514 /**
5515 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5516 * subscription.
5517 *
5518 * @param subId the id of the subscription.
5519 * @param appType the uicc app type, must be USIM or SIM.
5520 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5521 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005522 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005523 * @return number of fplmns that is successfully written to the SIM.
5524 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005525 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5526 String callingFeatureId) {
5527 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5528 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005529 if (DBG) logv("no permissions for setForbiddenplmns");
5530 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5531 }
5532 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5533 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5534 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5535 }
5536 if (fplmns == null) {
5537 throw new IllegalArgumentException("Fplmn List provided is null");
5538 }
5539 for (String fplmn : fplmns) {
5540 if (!CellIdentity.isValidPlmn(fplmn)) {
5541 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5542 }
5543 }
5544 final long identity = Binder.clearCallingIdentity();
5545 try {
5546 Object response = sendRequest(
5547 CMD_SET_FORBIDDEN_PLMNS,
5548 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5549 subId);
5550 return (int) response;
5551 } finally {
5552 Binder.restoreCallingIdentity(identity);
5553 }
5554 }
5555
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005556 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005557 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5559 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561 final long identity = Binder.clearCallingIdentity();
5562 try {
5563 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5564 if (response.payload == null) {
5565 return "";
5566 }
Evan Charltonc66da362014-05-16 14:06:40 -07005567
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005568 // Append the returned status code to the end of the response payload.
5569 String s = Integer.toHexString(
5570 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5571 s = IccUtils.bytesToHexString(response.payload) + s;
5572 return s;
5573 } finally {
5574 Binder.restoreCallingIdentity(identity);
5575 }
Evan Charltonc66da362014-05-16 14:06:40 -07005576 }
5577
Jake Hambye994d462014-02-03 13:10:13 -08005578 /**
5579 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5580 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5581 *
5582 * @param itemID the ID of the item to read
5583 * @return the NV item as a String, or null on error.
5584 */
5585 @Override
5586 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005587 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5589 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590
5591 final long identity = Binder.clearCallingIdentity();
5592 try {
5593 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005594 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5596 return value;
5597 } finally {
5598 Binder.restoreCallingIdentity(identity);
5599 }
Jake Hambye994d462014-02-03 13:10:13 -08005600 }
5601
5602 /**
5603 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5604 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5605 *
5606 * @param itemID the ID of the item to read
5607 * @param itemValue the value to write, as a String
5608 * @return true on success; false on any failure
5609 */
5610 @Override
5611 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005612 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5614 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615
5616 final long identity = Binder.clearCallingIdentity();
5617 try {
5618 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5619 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005620 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5622 return success;
5623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
Jake Hambye994d462014-02-03 13:10:13 -08005626 }
5627
5628 /**
5629 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5630 * Used for device configuration by some CDMA operators.
5631 *
5632 * @param preferredRoamingList byte array containing the new PRL
5633 * @return true on success; false on any failure
5634 */
5635 @Override
5636 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5638 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639
5640 final long identity = Binder.clearCallingIdentity();
5641 try {
5642 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5643 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5644 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5645 return success;
5646 } finally {
5647 Binder.restoreCallingIdentity(identity);
5648 }
Jake Hambye994d462014-02-03 13:10:13 -08005649 }
5650
5651 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005652 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005653 * Used for device configuration by some CDMA operators.
5654 *
chen xu6dac5ab2018-10-26 17:39:23 -07005655 * @param slotIndex - device slot.
5656 *
Jake Hambye994d462014-02-03 13:10:13 -08005657 * @return true on success; false on any failure
5658 */
5659 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005660 public boolean resetModemConfig(int slotIndex) {
5661 Phone phone = PhoneFactory.getPhone(slotIndex);
5662 if (phone != null) {
5663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5664 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665
chen xu6dac5ab2018-10-26 17:39:23 -07005666 final long identity = Binder.clearCallingIdentity();
5667 try {
5668 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5669 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5670 return success;
5671 } finally {
5672 Binder.restoreCallingIdentity(identity);
5673 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 }
chen xu6dac5ab2018-10-26 17:39:23 -07005675 return false;
5676 }
5677
5678 /**
5679 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5680 *
5681 * @param slotIndex - device slot.
5682 *
5683 * @return true on success; false on any failure
5684 */
5685 @Override
5686 public boolean rebootModem(int slotIndex) {
5687 Phone phone = PhoneFactory.getPhone(slotIndex);
5688 if (phone != null) {
5689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5690 mApp, phone.getSubId(), "rebootModem");
5691
5692 final long identity = Binder.clearCallingIdentity();
5693 try {
5694 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5695 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5696 return success;
5697 } finally {
5698 Binder.restoreCallingIdentity(identity);
5699 }
5700 }
5701 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005702 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005703
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005704 public String[] getPcscfAddress(String apnType, String callingPackage,
5705 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005706 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005707 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5708 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005709 return new String[0];
5710 }
5711
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712 final long identity = Binder.clearCallingIdentity();
5713 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005714 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715 } finally {
5716 Binder.restoreCallingIdentity(identity);
5717 }
Wink Saville36469e72014-06-11 15:17:00 -07005718 }
5719
Brad Ebinger51f743a2017-01-23 13:50:20 -08005720 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005721 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5722 * {@link #disableIms(int)}.
5723 * @param slotIndex device slot.
5724 */
5725 public void resetIms(int slotIndex) {
5726 enforceModifyPermission();
5727
5728 final long identity = Binder.clearCallingIdentity();
5729 try {
5730 if (mImsResolver == null) {
5731 // may happen if the does not support IMS.
5732 return;
5733 }
5734 mImsResolver.disableIms(slotIndex);
5735 mImsResolver.enableIms(slotIndex);
5736 } finally {
5737 Binder.restoreCallingIdentity(identity);
5738 }
5739 }
5740
5741 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005742 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5743 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005744 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005745 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005746 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747
5748 final long identity = Binder.clearCallingIdentity();
5749 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005750 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005751 // may happen if the device does not support IMS.
5752 return;
5753 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005754 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005755 } finally {
5756 Binder.restoreCallingIdentity(identity);
5757 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005758 }
5759
5760 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005761 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5762 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005763 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005764 public void disableIms(int slotId) {
5765 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766
5767 final long identity = Binder.clearCallingIdentity();
5768 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005769 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005770 // may happen if the device does not support IMS.
5771 return;
5772 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005773 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 } finally {
5775 Binder.restoreCallingIdentity(identity);
5776 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005777 }
5778
5779 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005780 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5781 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005782 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005783 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005784 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005785 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786
5787 final long identity = Binder.clearCallingIdentity();
5788 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005789 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005790 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5791 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005792 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005793 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 } finally {
5795 Binder.restoreCallingIdentity(identity);
5796 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005797 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005798 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005799 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5800 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005801 @Override
5802 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005803 enforceModifyPermission();
5804
5805 final long identity = Binder.clearCallingIdentity();
5806 try {
5807 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005808 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005809 } finally {
5810 Binder.restoreCallingIdentity(identity);
5811 }
5812 }
5813
5814 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005815 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005816 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005817 */
5818 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5819 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005820
5821 final long identity = Binder.clearCallingIdentity();
5822 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005823 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005824 // may happen if the device does not support IMS.
5825 return null;
5826 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005827 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005828 } finally {
5829 Binder.restoreCallingIdentity(identity);
5830 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005831 }
5832
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005833 /**
5834 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005835 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005836 */
5837 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5838 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839
5840 final long identity = Binder.clearCallingIdentity();
5841 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005842 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005843 // may happen if the device does not support IMS.
5844 return null;
5845 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005846 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847 } finally {
5848 Binder.restoreCallingIdentity(identity);
5849 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005850 }
5851
Brad Ebinger884c07b2018-02-15 16:17:40 -08005852 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005853 * Sets the ImsService Package Name that Telephony will bind to.
5854 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005855 * @param slotIndex the slot ID that the ImsService should bind for.
5856 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005857 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005858 * @param featureTypes An integer array of feature types associated with a packageName.
5859 * @param packageName The name of the package that the current configuration will be replaced
5860 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005861 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005862 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5864 int[] featureTypes, String packageName) {
5865 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5866 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5868 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005869 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005871 final long identity = Binder.clearCallingIdentity();
5872 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005873 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005874 // may happen if the device does not support IMS.
5875 return false;
5876 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005877 Map<Integer, String> featureConfig = new HashMap<>();
5878 for (int featureType : featureTypes) {
5879 featureConfig.put(featureType, packageName);
5880 }
5881 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5882 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883 } finally {
5884 Binder.restoreCallingIdentity(identity);
5885 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005886 }
5887
5888 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005889 * Clears any carrier ImsService overrides for the slot index specified that were previously
5890 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5891 *
5892 * This should only be used for testing.
5893 *
5894 * @param slotIndex the slot ID that the ImsService should bind for.
5895 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5896 */
5897 @Override
5898 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5899 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5900 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5901 "clearCarrierImsServiceOverride");
5902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5903 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5904 "clearCarrierImsServiceOverride");
5905
5906 final long identity = Binder.clearCallingIdentity();
5907 try {
5908 if (mImsResolver == null) {
5909 // may happen if the device does not support IMS.
5910 return false;
5911 }
5912 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5913 } finally {
5914 Binder.restoreCallingIdentity(identity);
5915 }
5916 }
5917
5918 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005919 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005920 *
5921 * @param slotId The slot that the ImsService is associated with.
5922 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5923 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005924 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005925 * @return the package name of the ImsService configuration.
5926 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005927 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5928 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005929 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005930 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005931 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005932 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5933 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 final long identity = Binder.clearCallingIdentity();
5936 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005937 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005938 // may happen if the device does not support IMS.
5939 return "";
5940 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005941 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005942 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5943 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944 } finally {
5945 Binder.restoreCallingIdentity(identity);
5946 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005947 }
5948
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005949 /**
5950 * Get the MmTelFeature state associated with the requested subscription id.
5951 * @param subId The subscription that the MmTelFeature is associated with.
5952 * @param callback A callback with an integer containing the
5953 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5954 */
5955 @Override
5956 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5957 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5958 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5959 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5960 "IMS not available on device.");
5961 }
5962 final long token = Binder.clearCallingIdentity();
5963 try {
5964 int slotId = getSlotIndex(subId);
5965 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5966 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5967 + subId + "'");
5968 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5969 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005970 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005971 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5972 try {
5973 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5974 } catch (RemoteException e) {
5975 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5976 + "Ignore");
5977 }
5978 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005979 } catch (ImsException e) {
5980 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005981 } finally {
5982 Binder.restoreCallingIdentity(token);
5983 }
5984 }
5985
Daniel Brightbb5840b2021-01-12 15:48:18 -08005986 /**
5987 * Sets the ims registration state on all valid {@link Phone}s.
5988 */
5989 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005990 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991
5992 final long identity = Binder.clearCallingIdentity();
5993 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005994 // NOTE: Before S, this method only set the default phone.
5995 for (final Phone phone : PhoneFactory.getPhones()) {
5996 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5997 phone.setImsRegistrationState(registered);
5998 }
5999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 } finally {
6001 Binder.restoreCallingIdentity(identity);
6002 }
Wink Saville36469e72014-06-11 15:17:00 -07006003 }
6004
6005 /**
Stuart Scott54788802015-03-30 13:18:01 -07006006 * Set the network selection mode to automatic.
6007 *
6008 */
6009 @Override
6010 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6012 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013
6014 final long identity = Binder.clearCallingIdentity();
6015 try {
shilufc958392020-01-20 11:36:01 -08006016 if (!isActiveSubscription(subId)) {
6017 return;
6018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006020 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6021 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 } finally {
6023 Binder.restoreCallingIdentity(identity);
6024 }
Stuart Scott54788802015-03-30 13:18:01 -07006025 }
6026
Jack Yud10cdd42020-09-28 20:28:01 -07006027 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006028 * Ask the radio to connect to the input network and change selection mode to manual.
6029 *
6030 * @param subId the id of the subscription.
6031 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6032 * the operator to attach to.
6033 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6034 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6035 * normal network selection next time.
6036 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006037 */
6038 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006039 public boolean setNetworkSelectionModeManual(
6040 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6042 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006043
6044 if (!isActiveSubscription(subId)) {
6045 return false;
6046 }
6047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 final long identity = Binder.clearCallingIdentity();
6049 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006050 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006052 if (DBG) {
6053 log("setNetworkSelectionModeManual: subId: " + subId
6054 + " operator: " + operatorInfo);
6055 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6057 } finally {
6058 Binder.restoreCallingIdentity(identity);
6059 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006060 }
shilu84f6e8b2019-12-19 13:58:01 -08006061 /**
6062 * Get the manual network selection
6063 *
6064 * @param subId the id of the subscription.
6065 *
6066 * @return the previously saved user selected PLMN
6067 */
6068 @Override
6069 public String getManualNetworkSelectionPlmn(int subId) {
6070 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006071 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006072 mApp, subId, "getManualNetworkSelectionPlmn");
6073
6074 final long identity = Binder.clearCallingIdentity();
6075 try {
6076 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006077 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006078 }
6079
6080 final Phone phone = getPhone(subId);
6081 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006082 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006083 }
6084 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6085 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6086 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6087 } finally {
6088 Binder.restoreCallingIdentity(identity);
6089 }
6090 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006091
6092 /**
6093 * Scans for available networks.
6094 */
6095 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006096 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6097 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6099 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006100 LocationAccessPolicy.LocationPermissionResult locationResult =
6101 LocationAccessPolicy.checkLocationPermission(mApp,
6102 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6103 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006104 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006105 .setCallingPid(Binder.getCallingPid())
6106 .setCallingUid(Binder.getCallingUid())
6107 .setMethod("getCellNetworkScanResults")
6108 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006109 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6110 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006111 .build());
6112 switch (locationResult) {
6113 case DENIED_HARD:
6114 throw new SecurityException("Not allowed to access scan results -- location");
6115 case DENIED_SOFT:
6116 return null;
6117 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006118
Pengquan Menga1bb6272018-09-06 09:59:22 -07006119 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006120 try {
6121 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006122 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006124 } finally {
6125 Binder.restoreCallingIdentity(identity);
6126 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006127 }
6128
6129 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006130 * Get the call forwarding info, given the call forwarding reason.
6131 */
6132 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006133 public void getCallForwarding(int subId, int callForwardingReason,
6134 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006135 enforceReadPrivilegedPermission("getCallForwarding");
6136 long identity = Binder.clearCallingIdentity();
6137 try {
6138 if (DBG) {
6139 log("getCallForwarding: subId " + subId
6140 + " callForwardingReason" + callForwardingReason);
6141 }
Hall Liu27d24262020-09-18 19:04:59 -07006142
6143 Phone phone = getPhone(subId);
6144 if (phone == null) {
6145 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006146 callback.onError(
6147 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006148 } catch (RemoteException e) {
6149 // ignore
6150 }
6151 return;
6152 }
6153
6154 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6155 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6156 @Override
6157 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6158 try {
6159 callback.onCallForwardingInfoAvailable(info);
6160 } catch (RemoteException e) {
6161 // ignore
6162 }
6163 }
6164
6165 @Override
6166 public void onError(int error) {
6167 try {
6168 callback.onError(error);
6169 } catch (RemoteException e) {
6170 // ignore
6171 }
6172 }
6173 });
6174 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006175 } finally {
6176 Binder.restoreCallingIdentity(identity);
6177 }
6178 }
6179
6180 /**
6181 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6182 * reason, the number to forward, and the timeout before the forwarding is attempted.
6183 */
6184 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006185 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6186 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006187 enforceModifyPermission();
6188 long identity = Binder.clearCallingIdentity();
6189 try {
6190 if (DBG) {
6191 log("setCallForwarding: subId " + subId
6192 + " callForwardingInfo" + callForwardingInfo);
6193 }
Hall Liu27d24262020-09-18 19:04:59 -07006194
6195 Phone phone = getPhone(subId);
6196 if (phone == null) {
6197 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006198 callback.accept(
6199 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006200 } catch (RemoteException e) {
6201 // ignore
6202 }
6203 return;
6204 }
6205
6206 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6207 FunctionalUtils.ignoreRemoteException(callback::accept));
6208
6209 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006210 } finally {
6211 Binder.restoreCallingIdentity(identity);
6212 }
6213 }
6214
6215 /**
Hall Liu27d24262020-09-18 19:04:59 -07006216 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006217 */
6218 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006219 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006220 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006221 long identity = Binder.clearCallingIdentity();
6222 try {
Hall Liu27d24262020-09-18 19:04:59 -07006223 Phone phone = getPhone(subId);
6224 if (phone == null) {
6225 try {
6226 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6227 } catch (RemoteException e) {
6228 // ignore
6229 }
6230 return;
6231 }
SongFerngWang0e767992021-03-31 22:08:45 +08006232 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6233 PersistableBundle c = configManager.getConfigForSubId(subId);
6234 boolean requireUssd = c.getBoolean(
6235 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006236
Shuo Qian4a594052020-01-23 11:59:30 -08006237 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006238 if (requireUssd) {
6239 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6240 getSubscriptionCarrierId(subId));
6241 String newUssdCommand = "";
6242 try {
6243 newUssdCommand = carrierXmlParser.getFeature(
6244 CarrierXmlParser.FEATURE_CALL_WAITING)
6245 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6246 } catch (NullPointerException e) {
6247 loge("Failed to generate USSD number" + e);
6248 }
6249 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6250 mMainThreadHandler, callback, carrierXmlParser,
6251 CarrierXmlParser.SsEntry.SSAction.QUERY);
6252 final String ussdCommand = newUssdCommand;
6253 Executors.newSingleThreadExecutor().execute(() -> {
6254 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6255 });
6256 } else {
6257 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6258 callback::accept);
6259 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6260 }
Shuo Qian4a594052020-01-23 11:59:30 -08006261 } finally {
6262 Binder.restoreCallingIdentity(identity);
6263 }
6264 }
6265
6266 /**
Hall Liu27d24262020-09-18 19:04:59 -07006267 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006268 */
6269 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006270 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006271 enforceModifyPermission();
6272 long identity = Binder.clearCallingIdentity();
6273 try {
Hall Liu27d24262020-09-18 19:04:59 -07006274 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6275
6276 Phone phone = getPhone(subId);
6277 if (phone == null) {
6278 try {
6279 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6280 } catch (RemoteException e) {
6281 // ignore
6282 }
6283 return;
6284 }
6285
SongFerngWang0e767992021-03-31 22:08:45 +08006286 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6287 PersistableBundle c = configManager.getConfigForSubId(subId);
6288 boolean requireUssd = c.getBoolean(
6289 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006290
SongFerngWang0e767992021-03-31 22:08:45 +08006291 if (DBG) log("getCallWaitingStatus: subId " + subId);
6292 if (requireUssd) {
6293 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6294 getSubscriptionCarrierId(subId));
6295 CarrierXmlParser.SsEntry.SSAction ssAction =
6296 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6297 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6298 String newUssdCommand = "";
6299 try {
6300 newUssdCommand = carrierXmlParser.getFeature(
6301 CarrierXmlParser.FEATURE_CALL_WAITING)
6302 .makeCommand(ssAction, null);
6303 } catch (NullPointerException e) {
6304 loge("Failed to generate USSD number" + e);
6305 }
6306 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6307 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6308 final String ussdCommand = newUssdCommand;
6309 Executors.newSingleThreadExecutor().execute(() -> {
6310 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6311 });
6312 } else {
6313 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6314 FunctionalUtils.ignoreRemoteException(callback::accept));
6315
6316 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6317 }
Shuo Qian4a594052020-01-23 11:59:30 -08006318 } finally {
6319 Binder.restoreCallingIdentity(identity);
6320 }
6321 }
6322
6323 /**
yinxub1bed742017-04-17 11:45:04 -07006324 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006325 *
yinxub1bed742017-04-17 11:45:04 -07006326 * @param subId id of the subscription
6327 * @param request contains the radio access networks with bands/channels to scan
6328 * @param messenger callback messenger for scan results or errors
6329 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006330 * @return the id of the requested scan which can be used to stop the scan.
6331 */
6332 @Override
6333 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006334 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6336 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006337 LocationAccessPolicy.LocationPermissionResult locationResult =
6338 LocationAccessPolicy.checkLocationPermission(mApp,
6339 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6340 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006341 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006342 .setCallingPid(Binder.getCallingPid())
6343 .setCallingUid(Binder.getCallingUid())
6344 .setMethod("requestNetworkScan")
6345 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006346 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6347 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006348 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006349 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006350 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6351 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006352 if (e != null) {
6353 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6354 throw e;
6355 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006356 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006357 return TelephonyScanManager.INVALID_SCAN_ID;
6358 }
6359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360 }
Hall Liu912dfd32019-04-25 14:02:26 -07006361 int callingUid = Binder.getCallingUid();
6362 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006363 final long identity = Binder.clearCallingIdentity();
6364 try {
6365 return mNetworkScanRequestTracker.startNetworkScan(
6366 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006367 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006368 } finally {
6369 Binder.restoreCallingIdentity(identity);
6370 }
yinxu504e1392017-04-12 16:03:22 -07006371 }
6372
Hall Liub2ac8ef2019-02-28 15:56:23 -08006373 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006374 NetworkScanRequest request, int subId, String callingPackage) {
6375 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006376 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6377 boolean hasNetworkScanPermission =
6378 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6379 == PERMISSION_GRANTED;
6380
6381 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6382 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6383 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006384 }
6385
6386 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6387 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006388 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6389 return new SecurityException("Specific channels must not be"
6390 + " scanned without location access.");
6391 }
6392 }
6393 }
6394
Hall Liub2ac8ef2019-02-28 15:56:23 -08006395 return null;
6396 }
6397
yinxu504e1392017-04-12 16:03:22 -07006398 /**
6399 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006400 *
6401 * @param subId id of the subscription
6402 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006403 */
6404 @Override
6405 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6407 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006408
Hall Liu912dfd32019-04-25 14:02:26 -07006409 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006410 final long identity = Binder.clearCallingIdentity();
6411 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006412 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 } finally {
6414 Binder.restoreCallingIdentity(identity);
6415 }
yinxu504e1392017-04-12 16:03:22 -07006416 }
6417
6418 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006419 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006420 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006421 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006422 */
6423 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006424 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006425 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006426 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006427 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006428
6429 final long identity = Binder.clearCallingIdentity();
6430 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006431 if (DBG) log("getAllowedNetworkTypesBitmask");
6432 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6433 int networkTypesBitmask = (result != null ? result[0] : -1);
6434 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6435 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006436 } finally {
6437 Binder.restoreCallingIdentity(identity);
6438 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006439 }
6440
6441 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006442 * Get the allowed network types for certain reason.
6443 *
6444 * @param subId the id of the subscription.
6445 * @param reason the reason the allowed network type change is taking place
6446 * @return the allowed network types.
6447 */
6448 @Override
6449 public long getAllowedNetworkTypesForReason(int subId,
6450 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006451 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006452 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006453 final long identity = Binder.clearCallingIdentity();
6454 try {
6455 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6456 } finally {
6457 Binder.restoreCallingIdentity(identity);
6458 }
6459 }
6460
6461 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006462 * Enable/Disable E-UTRA-NR Dual Connectivity
6463 * @param subId subscription id of the sim card
6464 * @param nrDualConnectivityState expected NR dual connectivity state
6465 * This can be passed following states
6466 * <ol>
6467 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6468 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6469 * <li>Disable NR dual connectivity and force secondary cell to be released
6470 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6471 * </ol>
6472 * @return operation result.
6473 */
6474 @Override
6475 public int setNrDualConnectivityState(int subId,
6476 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6478 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006479 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006480 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6481 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6482 }
6483
Sooraj Sasindran37444802020-08-11 10:40:43 -07006484 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6485 final long identity = Binder.clearCallingIdentity();
6486 try {
6487 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6488 nrDualConnectivityState, subId,
6489 workSource);
6490 if (DBG) log("enableNRDualConnectivity result: " + result);
6491 return result;
6492 } finally {
6493 Binder.restoreCallingIdentity(identity);
6494 }
6495 }
6496
6497 /**
6498 * Is E-UTRA-NR Dual Connectivity enabled
6499 * @return true if dual connectivity is enabled else false
6500 */
6501 @Override
6502 public boolean isNrDualConnectivityEnabled(int subId) {
6503 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006504 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006505 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006506 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006507 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6508 return false;
6509 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006510 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6511 final long identity = Binder.clearCallingIdentity();
6512 try {
6513 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6514 null, subId, workSource);
6515 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6516 return isEnabled;
6517 } finally {
6518 Binder.restoreCallingIdentity(identity);
6519 }
6520 }
6521
6522 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006523 * Set the allowed network types of the device and
6524 * provide the reason triggering the allowed network change.
6525 *
6526 * @param subId the id of the subscription.
6527 * @param reason the reason the allowed network type change is taking place
6528 * @param allowedNetworkTypes the allowed network types.
6529 * @return true on success; false on any failure.
6530 */
6531 @Override
6532 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006533 @TelephonyManager.AllowedNetworkTypesReason int reason,
6534 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6536 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006537 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006538 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6539 return false;
6540 }
6541 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6542 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006543 return false;
6544 }
6545
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006546 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6547 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6548
6549
6550 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6551 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6552 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006553 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006554
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006555 final long identity = Binder.clearCallingIdentity();
6556 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006557 Boolean success = (Boolean) sendRequest(
6558 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6559 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6560
6561 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6562 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006563 } finally {
6564 Binder.restoreCallingIdentity(identity);
6565 }
6566 }
6567
6568 /**
Miaoa84611c2019-03-15 09:21:10 +08006569 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006570 *
Miaoa84611c2019-03-15 09:21:10 +08006571 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006572 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006573 * @hide
6574 */
6575 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006576 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006577 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006579 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580 try {
Miaoa84611c2019-03-15 09:21:10 +08006581 if (phone != null) {
6582 return phone.hasMatchedTetherApnSetting();
6583 } else {
6584 return false;
6585 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586 } finally {
6587 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006588 }
Junda Liu475951f2014-11-07 16:45:03 -08006589 }
6590
6591 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006592 * Enable or disable always reporting signal strength changes from radio.
6593 *
6594 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6595 */
6596 @Override
6597 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6598 enforceModifyPermission();
6599 enforceSystemCaller();
6600
6601 final long identity = Binder.clearCallingIdentity();
6602 final Phone phone = getPhone(subId);
6603 try {
6604 if (phone != null) {
6605 if (DBG) {
6606 log("setAlwaysReportSignalStrength: subId=" + subId
6607 + " isEnable=" + isEnable);
6608 }
6609 phone.setAlwaysReportSignalStrength(isEnable);
6610 } else {
6611 loge("setAlwaysReportSignalStrength: no phone found for subId="
6612 + subId);
6613 }
6614 } finally {
6615 Binder.restoreCallingIdentity(identity);
6616 }
6617 }
6618
6619 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006620 * Get the user enabled state of Mobile Data.
6621 *
6622 * TODO: remove and use isUserDataEnabled.
6623 * This can't be removed now because some vendor codes
6624 * calls through ITelephony directly while they should
6625 * use TelephonyManager.
6626 *
6627 * @return true on enabled
6628 */
6629 @Override
6630 public boolean getDataEnabled(int subId) {
6631 return isUserDataEnabled(subId);
6632 }
6633
6634 /**
6635 * Get whether mobile data is enabled per user setting.
6636 *
6637 * There are other factors deciding whether mobile data is actually enabled, but they are
6638 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006639 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006640 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006641 *
6642 * @return {@code true} if data is enabled else {@code false}
6643 */
6644 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006645 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006646 try {
6647 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6648 null);
6649 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6651 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006653
6654 final long identity = Binder.clearCallingIdentity();
6655 try {
6656 int phoneId = mSubscriptionController.getPhoneId(subId);
6657 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6658 Phone phone = PhoneFactory.getPhone(phoneId);
6659 if (phone != null) {
6660 boolean retVal = phone.isUserDataEnabled();
6661 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6662 return retVal;
6663 } else {
6664 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6665 return false;
6666 }
6667 } finally {
6668 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006669 }
6670 }
6671
6672 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006673 * Checks if the device is capable of mobile data by considering whether whether the
6674 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6675 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006676 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006677 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006678 */
6679 @Override
6680 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006681 try {
6682 try {
6683 mApp.enforceCallingOrSelfPermission(
6684 android.Manifest.permission.ACCESS_NETWORK_STATE,
6685 null);
6686 } catch (Exception e) {
6687 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6688 "isDataEnabled");
6689 }
6690 } catch (Exception e) {
6691 enforceReadPrivilegedPermission("isDataEnabled");
6692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693
6694 final long identity = Binder.clearCallingIdentity();
6695 try {
6696 int phoneId = mSubscriptionController.getPhoneId(subId);
6697 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6698 Phone phone = PhoneFactory.getPhone(phoneId);
6699 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006700 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6702 return retVal;
6703 } else {
6704 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6705 return false;
6706 }
6707 } finally {
6708 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006709 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006710 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006711
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006712 /**
6713 * Check if data is enabled for a specific reason
6714 * @param subId Subscription index
6715 * @param reason the reason the data enable change is taking place
6716 * @return {@code true} if the overall data is enabled; {@code false} if not.
6717 */
6718 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006719 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006720 @TelephonyManager.DataEnabledReason int reason) {
6721 try {
6722 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6723 null);
6724 } catch (Exception e) {
6725 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006726 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006727 }
6728
6729
6730 final long identity = Binder.clearCallingIdentity();
6731 try {
6732 int phoneId = mSubscriptionController.getPhoneId(subId);
6733 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006734 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006735 + " reason=" + reason);
6736 }
6737 Phone phone = PhoneFactory.getPhone(phoneId);
6738 if (phone != null) {
6739 boolean retVal;
6740 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6741 retVal = phone.isUserDataEnabled();
6742 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006743 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006744 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006745 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006746 return retVal;
6747 } else {
6748 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006749 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006750 + subId + " retVal=false");
6751 }
6752 return false;
6753 }
6754 } finally {
6755 Binder.restoreCallingIdentity(identity);
6756 }
6757 }
6758
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006759 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006760 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006761 if (uid == Process.PHONE_UID) {
6762 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6763 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006764 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6765 }
6766
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006767 //load access rules from carrier configs, and check those as well: b/139133814
6768 SubscriptionController subController = SubscriptionController.getInstance();
6769 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6770 || subController == null) return privilegeFromSim;
6771
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006772 PackageManager pkgMgr = phone.getContext().getPackageManager();
6773 String[] packages = pkgMgr.getPackagesForUid(uid);
6774
6775 final long identity = Binder.clearCallingIdentity();
6776 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006777 int subId = phone.getSubId();
6778 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6779 // A test override is in place for the privileges for this subId, so don't try to
6780 // read the subscription privileges.
6781 return privilegeFromSim;
6782 }
6783 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006784 SubscriptionManager subManager = (SubscriptionManager)
6785 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6786 for (String pkg : packages) {
6787 if (subManager.canManageSubscription(subInfo, pkg)) {
6788 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6789 }
6790 }
6791 return privilegeFromSim;
6792 } finally {
6793 Binder.restoreCallingIdentity(identity);
6794 }
6795 }
6796
6797 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6798 String pkgName) {
6799 //load access rules from carrier configs, and check those as well: b/139133814
6800 SubscriptionController subController = SubscriptionController.getInstance();
6801 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6802 || subController == null) return privilegeFromSim;
6803
6804 final long identity = Binder.clearCallingIdentity();
6805 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006806 int subId = phone.getSubId();
6807 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6808 // A test override is in place for the privileges for this subId, so don't try to
6809 // read the subscription privileges.
6810 return privilegeFromSim;
6811 }
6812 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006813 SubscriptionManager subManager = (SubscriptionManager)
6814 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6815 return subManager.canManageSubscription(subInfo, pkgName)
6816 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6817 } finally {
6818 Binder.restoreCallingIdentity(identity);
6819 }
6820 }
6821
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006822 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006823 public int getCarrierPrivilegeStatus(int subId) {
6824 final Phone phone = getPhone(subId);
6825 if (phone == null) {
6826 loge("getCarrierPrivilegeStatus: Invalid subId");
6827 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6828 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006829 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6830 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006831 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006832 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6833 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006834
6835 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006836 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006837 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006838 }
Junda Liu29340342014-07-10 15:23:27 -07006839
6840 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006841 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006842 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006843 final Phone phone = getPhone(subId);
6844 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006845 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006846 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6847 }
6848 UiccProfile profile =
6849 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6850 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006851 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006852 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6853 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006854 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006855 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006856 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006857 }
6858
6859 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006860 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006861 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006862 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006863 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006864 }
6865
6866 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006867 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6868 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006869 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006870 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6871 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006872 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006873 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006874 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006875 }
6876
6877 @Override
6878 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006879 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006880 if (TextUtils.isEmpty(pkgName))
6881 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006882 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6883 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006884 UiccPort port = UiccController.getInstance().getUiccPort(i);
6885 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006886 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006887 continue;
6888 }
6889
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006890 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006891 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006892 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006893 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6894 break;
6895 }
6896 }
6897
6898 return result;
Junda Liu29340342014-07-10 15:23:27 -07006899 }
Derek Tan89e89d42014-07-08 17:00:10 -07006900
6901 @Override
Junda Liue64de782015-04-16 17:19:16 -07006902 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006903 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006904 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6905 loge("phoneId " + phoneId + " is not valid.");
6906 return null;
6907 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006908 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6909 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006910 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006911 return null ;
6912 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006913 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006914 }
6915
Amith Yamasani6e118872016-02-19 12:53:51 -08006916 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006917 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006918 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006919 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006920 List<String> privilegedPackages = new ArrayList<>();
6921 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006922 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006923 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006924 if (port != null) {
6925 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006926 if (packages == null) {
6927 // Only check packages in user 0 for now
6928 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006929 PackageManager.MATCH_DISABLED_COMPONENTS
6930 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006931 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006932 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006933 }
6934 for (int p = packages.size() - 1; p >= 0; p--) {
6935 PackageInfo pkgInfo = packages.get(p);
6936 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00006937 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6938 port.getCarrierPrivilegeStatus(pkgInfo),
6939 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006940 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006941 privilegedPackages.add(pkgInfo.packageName);
6942 }
6943 }
6944 }
6945 }
6946 return privilegedPackages;
6947 }
6948
chen xuf7e9fe82019-05-09 19:31:02 -07006949 @Override
6950 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006951 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6952
6953 final long identity = Binder.clearCallingIdentity();
6954
chen xuf7e9fe82019-05-09 19:31:02 -07006955 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006956 try {
6957 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6958 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6959 }
6960 } finally {
6961 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006962 }
6963 return privilegedPackages;
6964 }
6965
Wink Savilleb564aae2014-10-23 10:18:09 -07006966 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006967 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006968 UiccPort port = phone == null ? null : phone.getUiccPort();
6969 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006970 return null;
6971 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006972 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006973 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006974 return null;
6975 }
6976 return iccId;
6977 }
6978
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006979 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006980 public void setCallComposerStatus(int subId, int status) {
6981 enforceModifyPermission();
6982
6983 final long identity = Binder.clearCallingIdentity();
6984 try {
6985 Phone phone = getPhone(subId);
6986 if (phone != null) {
6987 Phone defaultPhone = phone.getImsPhone();
6988 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6989 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6990 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006991 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6992 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006993 }
6994 }
Shuo Qian284ae752020-12-22 19:10:14 -08006995 } catch (ImsException e) {
6996 throw new ServiceSpecificException(e.getCode());
6997 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006998 Binder.restoreCallingIdentity(identity);
6999 }
7000 }
7001
7002 @Override
7003 public int getCallComposerStatus(int subId) {
7004 enforceReadPrivilegedPermission("getCallComposerStatus");
7005
7006 final long identity = Binder.clearCallingIdentity();
7007 try {
7008 Phone phone = getPhone(subId);
7009 if (phone != null) {
7010 Phone defaultPhone = phone.getImsPhone();
7011 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7012 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7013 return imsPhone.getCallComposerStatus();
7014 }
7015 }
7016 } finally {
7017 Binder.restoreCallingIdentity(identity);
7018 }
7019 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7020 }
7021
7022 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007023 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7024 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007025 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007026 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007027
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007028 final long identity = Binder.clearCallingIdentity();
7029 try {
7030 final String iccId = getIccId(subId);
7031 final Phone phone = getPhone(subId);
7032 if (phone == null) {
7033 return false;
7034 }
7035 final String subscriberId = phone.getSubscriberId();
7036
7037 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007038 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007039 + subscriberId + " to " + number);
7040 }
7041
7042 if (TextUtils.isEmpty(iccId)) {
7043 return false;
7044 }
7045
7046 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7047
7048 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7049 if (alphaTag == null) {
7050 editor.remove(alphaTagPrefKey);
7051 } else {
7052 editor.putString(alphaTagPrefKey, alphaTag);
7053 }
7054
7055 // Record both the line number and IMSI for this ICCID, since we need to
7056 // track all merged IMSIs based on line number
7057 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7058 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7059 if (number == null) {
7060 editor.remove(numberPrefKey);
7061 editor.remove(subscriberPrefKey);
7062 } else {
7063 editor.putString(numberPrefKey, number);
7064 editor.putString(subscriberPrefKey, subscriberId);
7065 }
7066
7067 editor.commit();
7068 return true;
7069 } finally {
7070 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007071 }
Derek Tan7226c842014-07-02 17:42:23 -07007072 }
7073
7074 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007075 public String getLine1NumberForDisplay(int subId, String callingPackage,
7076 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007077 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007078 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007079 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007080 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007081 return null;
7082 }
Derek Tan97ebb422014-09-05 16:55:38 -07007083
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084 final long identity = Binder.clearCallingIdentity();
7085 try {
7086 String iccId = getIccId(subId);
7087 if (iccId != null) {
7088 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7089 if (DBG_MERGE) {
7090 log("getLine1NumberForDisplay returning "
7091 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7092 }
7093 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007094 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7096 return null;
7097 } finally {
7098 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007099 }
Derek Tan7226c842014-07-02 17:42:23 -07007100 }
7101
7102 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007103 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7104 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007105 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007106 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007107 return null;
7108 }
Derek Tan97ebb422014-09-05 16:55:38 -07007109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110 final long identity = Binder.clearCallingIdentity();
7111 try {
7112 String iccId = getIccId(subId);
7113 if (iccId != null) {
7114 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7115 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7116 }
7117 return null;
7118 } finally {
7119 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007120 }
Derek Tan7226c842014-07-02 17:42:23 -07007121 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007122
7123 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007124 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7125 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007126 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7127 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007129 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007130 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007131 return null;
7132 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007133
Jordan Liub49b04b2019-05-06 14:45:15 -07007134 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7135 // the process, where TelephonyManager was instantiated.
7136 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007137 final long identity = Binder.clearCallingIdentity();
7138 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007139 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140 final TelephonyManager tele = TelephonyManager.from(context);
7141 final SubscriptionManager sub = SubscriptionManager.from(context);
7142
7143 // Figure out what subscribers are currently active
7144 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007145
Jordan Liub49b04b2019-05-06 14:45:15 -07007146 // Only consider subs which match the current subId
7147 // This logic can be simplified. See b/131189269 for progress.
7148 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007149 activeSubscriberIds.add(tele.getSubscriberId(subId));
7150 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151
7152 // First pass, find a number override for an active subscriber
7153 String mergeNumber = null;
7154 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7155 for (String key : prefs.keySet()) {
7156 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7157 final String subscriberId = (String) prefs.get(key);
7158 if (activeSubscriberIds.contains(subscriberId)) {
7159 final String iccId = key.substring(
7160 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7161 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7162 mergeNumber = (String) prefs.get(numberKey);
7163 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007164 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007165 + " for active subscriber " + subscriberId);
7166 }
7167 if (!TextUtils.isEmpty(mergeNumber)) {
7168 break;
7169 }
7170 }
7171 }
7172 }
7173
7174 // Shortcut when no active merged subscribers
7175 if (TextUtils.isEmpty(mergeNumber)) {
7176 return null;
7177 }
7178
7179 // Second pass, find all subscribers under that line override
7180 final ArraySet<String> result = new ArraySet<>();
7181 for (String key : prefs.keySet()) {
7182 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7183 final String number = (String) prefs.get(key);
7184 if (mergeNumber.equals(number)) {
7185 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7186 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7187 final String subscriberId = (String) prefs.get(subscriberKey);
7188 if (!TextUtils.isEmpty(subscriberId)) {
7189 result.add(subscriberId);
7190 }
7191 }
7192 }
7193 }
7194
7195 final String[] resultArray = result.toArray(new String[result.size()]);
7196 Arrays.sort(resultArray);
7197 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007198 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007199 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7200 }
7201 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007202 } finally {
7203 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007204 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007205 }
7206
7207 @Override
zoey chen38003472019-12-13 17:16:31 +08007208 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7209 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007210
7211 final long identity = Binder.clearCallingIdentity();
7212 try {
7213 final TelephonyManager telephonyManager = mApp.getSystemService(
7214 TelephonyManager.class);
7215 String subscriberId = telephonyManager.getSubscriberId(subId);
7216 if (subscriberId == null) {
7217 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007218 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007219 + subId);
7220 }
7221 return null;
7222 }
7223
7224 final SubscriptionInfo info = SubscriptionController.getInstance()
7225 .getSubscriptionInfo(subId);
7226 final ParcelUuid groupUuid = info.getGroupUuid();
7227 // If it doesn't belong to any group, return just subscriberId of itself.
7228 if (groupUuid == null) {
7229 return new String[]{subscriberId};
7230 }
7231
7232 // Get all subscriberIds from the group.
7233 final List<String> mergedSubscriberIds = new ArrayList<>();
7234 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007235 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007236 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007237 for (SubscriptionInfo subInfo : groupInfos) {
7238 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7239 if (subscriberId != null) {
7240 mergedSubscriberIds.add(subscriberId);
7241 }
7242 }
7243
7244 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7245 } finally {
7246 Binder.restoreCallingIdentity(identity);
7247
7248 }
7249 }
7250
7251 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007252 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007253 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007254 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255
7256 final long identity = Binder.clearCallingIdentity();
7257 try {
7258 final Phone phone = getPhone(subId);
7259 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7260 } finally {
7261 Binder.restoreCallingIdentity(identity);
7262 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007263 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007264
7265 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007266 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007267 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7268 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007269 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7270 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007271
7272 final long identity = Binder.clearCallingIdentity();
7273 try {
7274 final Phone phone = getPhone(subId);
7275 if (phone == null) {
7276 return false;
7277 }
7278 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7279 cdmaNonRoamingList);
7280 } finally {
7281 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007282 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007283 }
7284
7285 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007286 @Deprecated
7287 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7288 enforceModifyPermission();
7289
7290 int returnValue = 0;
7291 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007292 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007293 if(result.exception == null) {
7294 if (result.result != null) {
7295 byte[] responseData = (byte[])(result.result);
7296 if(responseData.length > oemResp.length) {
7297 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7298 responseData.length + "bytes. Buffer Size is " +
7299 oemResp.length + "bytes.");
7300 }
7301 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7302 returnValue = responseData.length;
7303 }
7304 } else {
7305 CommandException ex = (CommandException) result.exception;
7306 returnValue = ex.getCommandError().ordinal();
7307 if(returnValue > 0) returnValue *= -1;
7308 }
7309 } catch (RuntimeException e) {
7310 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7311 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7312 if(returnValue > 0) returnValue *= -1;
7313 }
7314
7315 return returnValue;
7316 }
7317
7318 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007319 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007320 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007321 try {
7322 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007323 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007324 mApp, phone.getSubId(), "getRadioAccessFamily");
7325 } catch (SecurityException e) {
7326 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7327 throw e;
7328 }
chen xub97461a2018-10-26 14:17:57 -07007329 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007330 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007331 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007332 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007333 final long identity = Binder.clearCallingIdentity();
7334 try {
chen xub97461a2018-10-26 14:17:57 -07007335 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007336 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007337 mApp, phone.getSubId(), "getRadioAccessFamily");
7338 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007339 } finally {
7340 Binder.restoreCallingIdentity(identity);
7341 }
chen xub97461a2018-10-26 14:17:57 -07007342 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007343 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007344
7345 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007346 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007347 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007348 try {
7349 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7350 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007351 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007352 }
7353 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007354 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007355 }
7356 RoleManager rm = mApp.getSystemService(RoleManager.class);
7357 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7358 if (!dialerRoleHolders.contains(callingPackage)) {
7359 throw new SecurityException("App must be the dialer role holder to"
7360 + " upload a call composer pic");
7361 }
7362
7363 Executors.newSingleThreadExecutor().execute(() -> {
7364 ByteArrayOutputStream output = new ByteArrayOutputStream(
7365 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7366 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7367 boolean readUntilEnd = false;
7368 int totalBytesRead = 0;
7369 byte[] buffer = new byte[16 * 1024];
7370 while (true) {
7371 int numRead;
7372 try {
7373 numRead = input.read(buffer);
7374 } catch (IOException e) {
7375 try {
7376 fd.checkError();
7377 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7378 null);
7379 } catch (IOException e1) {
7380 // This means that the other side closed explicitly with an error. If this
7381 // happens, log and ignore.
7382 loge("Remote end of call composer picture pipe closed: " + e1);
7383 }
7384 break;
7385 }
7386 if (numRead == -1) {
7387 readUntilEnd = true;
7388 break;
7389 }
7390 totalBytesRead += numRead;
7391 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7392 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7393 try {
7394 input.close();
7395 } catch (IOException e) {
7396 // ignore
7397 }
7398 break;
7399 }
7400 output.write(buffer, 0, numRead);
7401 }
7402 // Generally, the remote end will close the file descriptors. The only case where we
7403 // close is above, where the picture size is too big.
7404
7405 try {
7406 fd.checkError();
7407 } catch (IOException e) {
7408 loge("Remote end for call composer closed with an error: " + e);
7409 return;
7410 }
7411
Hall Liuaa4211e2021-01-20 15:43:39 -08007412 if (!readUntilEnd) {
7413 loge("Did not finish reading entire image; aborting");
7414 return;
7415 }
Hall Liu82694d52020-12-11 18:22:04 -08007416
Hall Liuaa4211e2021-01-20 15:43:39 -08007417 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7418 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7419 new CallComposerPictureTransfer.Factory() {},
7420 imageData,
7421 (result) -> {
7422 if (result.first != null) {
7423 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7424 Bundle outputResult = new Bundle();
7425 outputResult.putParcelable(
7426 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7427 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7428 outputResult);
7429 } else {
7430 callback.send(result.second, null);
7431 }
7432 }
7433 );
Hall Liu82694d52020-12-11 18:22:04 -08007434 });
7435 }
7436
7437 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007438 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007439 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007440 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441
7442 final long identity = Binder.clearCallingIdentity();
7443 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007444 ImsManager.getInstance(defaultPhone.getContext(),
7445 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 } finally {
7447 Binder.restoreCallingIdentity(identity);
7448 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007449 }
7450
7451 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007452 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007453 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007454 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7455 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007456 return false;
7457 }
Svet Ganovb320e182015-04-16 12:30:10 -07007458
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459 final long identity = Binder.clearCallingIdentity();
7460 try {
7461 // Check the user preference and the system-level IMS setting. Even if the user has
7462 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7463 // In the long run, we may instead need to check if there exists a connection service
7464 // which can support video calling.
7465 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007466 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 return imsManager.isVtEnabledByPlatform()
7468 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7469 && imsManager.isVtEnabledByUser();
7470 } finally {
7471 Binder.restoreCallingIdentity(identity);
7472 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007473 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007474
Andrew Leea1239f22015-03-02 17:44:07 -08007475 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007476 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7477 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007479 mApp, subId, callingPackage, callingFeatureId,
7480 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 return false;
7482 }
7483
7484 final long identity = Binder.clearCallingIdentity();
7485 try {
7486 CarrierConfigManager configManager =
7487 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007488 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7490 } finally {
7491 Binder.restoreCallingIdentity(identity);
7492 }
Andrew Leea1239f22015-03-02 17:44:07 -08007493 }
7494
7495 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007496 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007498 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499 return false;
7500 }
7501
7502 final long identity = Binder.clearCallingIdentity();
7503 try {
7504 CarrierConfigManager configManager =
7505 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007506 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7508 } finally {
7509 Binder.restoreCallingIdentity(identity);
7510 }
Andrew Leea1239f22015-03-02 17:44:07 -08007511 }
7512
Andrew Lee9431b832015-03-09 18:46:45 -07007513 @Override
7514 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007515 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007516 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007517 }
7518
7519 @Override
7520 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 final long identity = Binder.clearCallingIdentity();
7522 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007523 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524 } finally {
7525 Binder.restoreCallingIdentity(identity);
7526 }
Andrew Lee9431b832015-03-09 18:46:45 -07007527 }
7528
Hall Liuf6668912018-10-31 17:05:23 -07007529 /**
7530 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7531 * support for the feature and device firmware support.
7532 *
7533 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7534 */
7535 @Override
7536 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007538 final Phone phone = getPhone(subscriptionId);
7539 if (phone == null) {
7540 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7541 return false;
7542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007544 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7546 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007547 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 return isCarrierSupported && isDeviceSupported;
7549 } finally {
7550 Binder.restoreCallingIdentity(identity);
7551 }
Hall Liu98187582018-01-22 19:15:32 -08007552 }
7553
Hall Liuf6668912018-10-31 17:05:23 -07007554 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007555 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7556 * RTT setting, will return true if the device and carrier both support RTT.
7557 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007558 */
7559 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560 final long identity = Binder.clearCallingIdentity();
7561 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007562 boolean isRttSupported = isRttSupported(subscriptionId);
7563 boolean isUserRttSettingOn = Settings.Secure.getInt(
7564 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7565 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7566 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7567 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007568 } finally {
7569 Binder.restoreCallingIdentity(identity);
7570 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007571 }
7572
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007573 @Deprecated
7574 @Override
7575 public String getDeviceId(String callingPackage) {
7576 return getDeviceIdWithFeature(callingPackage, null);
7577 }
7578
Sanket Padawe7310cc72015-01-14 09:53:20 -08007579 /**
7580 * Returns the unique device ID of phone, for example, the IMEI for
7581 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7582 *
7583 * <p>Requires Permission:
7584 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7585 */
7586 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007587 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007588 try {
7589 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7590 } catch (SecurityException se) {
7591 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7592 throw new SecurityException("Package " + callingPackage + " does not belong to "
7593 + Binder.getCallingUid());
7594 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007595 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007596 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007597 return null;
7598 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007599 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007600 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007601 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007602 return null;
7603 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007604
7605 final long identity = Binder.clearCallingIdentity();
7606 try {
7607 return phone.getDeviceId();
7608 } finally {
7609 Binder.restoreCallingIdentity(identity);
7610 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007611 }
7612
Ping Sunc67b7c22016-03-02 19:16:45 +08007613 /**
7614 * {@hide}
7615 * Returns the IMS Registration Status on a particular subid
7616 *
7617 * @param subId
7618 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007619 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007620 Phone phone = getPhone(subId);
7621 if (phone != null) {
7622 return phone.isImsRegistered();
7623 } else {
7624 return false;
7625 }
7626 }
7627
Santos Cordon7a1885b2015-02-03 11:15:19 -08007628 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007629 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007630 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007632 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007633 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7634 }
7635 final long identity = Binder.clearCallingIdentity();
7636 try {
7637 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7638 } finally {
7639 Binder.restoreCallingIdentity(identity);
7640 }
7641 }
7642
7643 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007644 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007645 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007646 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007647 mApp,
7648 subscriptionId,
7649 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007650 final long identity = Binder.clearCallingIdentity();
7651 try {
7652 Phone phone = getPhone(subscriptionId);
7653 if (phone == null) {
7654 return null;
7655 }
7656 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7657 } finally {
7658 Binder.restoreCallingIdentity(identity);
7659 }
7660 }
7661
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007662 /**
7663 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007664 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007665 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007666 final long identity = Binder.clearCallingIdentity();
7667 try {
7668 Phone phone = getPhone(subId);
7669 if (phone != null) {
7670 return phone.isWifiCallingEnabled();
7671 } else {
7672 return false;
7673 }
7674 } finally {
7675 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007676 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007677 }
7678
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007679 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007680 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007681 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007682 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007683 final long identity = Binder.clearCallingIdentity();
7684 try {
7685 Phone phone = getPhone(subId);
7686 if (phone != null) {
7687 return phone.isVideoEnabled();
7688 } else {
7689 return false;
7690 }
7691 } finally {
7692 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007693 }
7694 }
7695
7696 /**
7697 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7698 * defined in {@link ImsRegistrationImplBase}.
7699 */
7700 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 final long identity = Binder.clearCallingIdentity();
7702 try {
7703 Phone phone = getPhone(subId);
7704 if (phone != null) {
7705 return phone.getImsRegistrationTech();
7706 } else {
7707 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7708 }
7709 } finally {
7710 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007711 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007712 }
7713
Stuart Scott8eef64f2015-04-08 15:13:54 -07007714 @Override
7715 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007716 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007717 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7718 return;
7719 }
Kai Shif70f46f2021-03-03 13:59:46 -08007720 Phone defaultPhone = getDefaultPhone();
7721 if (defaultPhone != null) {
7722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7723 mApp, getDefaultPhone().getSubId(), "factoryReset");
7724 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007725 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007726
Svet Ganovcc087f82015-05-12 20:35:54 -07007727 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007728 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7729 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007730 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007731 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007732 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007733 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007734 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007735 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007736 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007737 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007738 // There has been issues when Sms raw table somehow stores orphan
7739 // fragments. They lead to garbled message when new fragments come
7740 // in and combined with those stale ones. In case this happens again,
7741 // user can reset all network settings which will clean up this table.
7742 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007743 // Clean up IMS settings as well here.
7744 int slotId = getSlotIndex(subId);
7745 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7746 ImsManager.getInstance(mApp, slotId).factoryReset();
7747 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007748
Kai Shif70f46f2021-03-03 13:59:46 -08007749 if (defaultPhone == null) {
7750 return;
7751 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007752 // Erase modem config if erase modem on network setting is enabled.
7753 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7754 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7755 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007756 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007757 }
Kai Shif70f46f2021-03-03 13:59:46 -08007758
7759 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007760 } finally {
7761 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007762 }
7763 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007764
SongFerngWangfd89b102021-05-27 22:44:54 +08007765 @VisibleForTesting
7766 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7767 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7768 return;
7769 }
7770 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7771 RILConstants.PREFERRED_NETWORK_MODE);
7772 SubscriptionManager.setSubscriptionProperty(subId,
7773 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7774 "user=" + defaultNetworkType);
7775 phone.loadAllowedNetworksFromSubscriptionDatabase();
7776 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7777 defaultNetworkType, null);
7778 }
7779
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007780 private void cleanUpSmsRawTable(Context context) {
7781 ContentResolver resolver = context.getContentResolver();
7782 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7783 resolver.delete(uri, null, null);
7784 }
7785
Narayan Kamath1c496c22015-04-16 14:40:19 +01007786 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007787 public String getSimLocaleForSubscriber(int subId) {
7788 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7789 final Phone phone = getPhone(subId);
7790 if (phone == null) {
7791 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007792 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794 final long identity = Binder.clearCallingIdentity();
7795 try {
chen xu5d3637b2019-01-21 23:31:38 -08007796 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007797 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007798 if (info == null) {
7799 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7800 return null;
7801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802 // Try and fetch the locale from the carrier properties or from the SIM language
7803 // preferences (EF-PL and EF-LI)...
7804 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007805 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007806 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7807 if (localeFromDefaultSim != null) {
7808 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7809 if (DBG) log("Using locale from subId: " + subId + " locale: "
7810 + localeFromDefaultSim);
7811 return localeFromDefaultSim.toLanguageTag();
7812 } else {
7813 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814 }
7815 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007816
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007817 // The SIM language preferences only store a language (e.g. fr = French), not an
7818 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7819 // the SIM and carrier preferences does not include a country we add the country
7820 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007821 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007823 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007824 return mccLocale.toLanguageTag();
7825 }
7826
7827 if (DBG) log("No locale found - returning null");
7828 return null;
7829 } finally {
7830 Binder.restoreCallingIdentity(identity);
7831 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007832 }
7833
7834 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007835 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007836 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007837 }
7838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007839 /**
7840 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7841 */
7842 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007843 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007844 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007845 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007846
Chenjie Yu1ba97252018-01-11 18:16:20 -08007847 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007848 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007849
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007850 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007851 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7852 * representing the state of the modem.
7853 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007854 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7855 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007856 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007857 */
7858 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007859 public void requestModemActivityInfo(ResultReceiver result) {
7860 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007861 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007862
7863 final long identity = Binder.clearCallingIdentity();
7864 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007865 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007866 } finally {
7867 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007868 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007869 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007870
Siddharth Rayb8114062018-06-17 15:02:38 -07007871 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7872 // less than total activity duration.
7873 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7874 if (info == null) {
7875 return false;
7876 }
7877 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007878 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7879 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7880
Siddharth Rayb8114062018-06-17 15:02:38 -07007881 return (info.isValid()
7882 && (info.getSleepTimeMillis() <= activityDurationMs)
7883 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007884 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007885 && (totalTxTimeMs <= activityDurationMs));
7886 }
7887
Jack Yu85bd38a2015-11-09 11:34:32 -08007888 /**
7889 * {@hide}
7890 * Returns the service state information on specified subscription.
7891 */
7892 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007893 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7894 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007896 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007897 return null;
7898 }
7899
Hall Liuf19c44f2018-11-27 14:38:17 -08007900 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7901 LocationAccessPolicy.checkLocationPermission(mApp,
7902 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7903 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007904 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007905 .setCallingPid(Binder.getCallingPid())
7906 .setCallingUid(Binder.getCallingUid())
7907 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007908 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007909 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007910 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7911 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007912 .build());
7913
7914 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7915 LocationAccessPolicy.checkLocationPermission(mApp,
7916 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7917 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007918 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007919 .setCallingPid(Binder.getCallingPid())
7920 .setCallingUid(Binder.getCallingUid())
7921 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007922 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007923 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007924 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7925 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007926 .build());
7927 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7928 boolean hasFinePermission =
7929 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7930 boolean hasCoarsePermission =
7931 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7932
Jack Yu479f40e2020-10-27 21:29:25 -07007933 final Phone phone = getPhone(subId);
7934 if (phone == null) {
7935 return null;
7936 }
7937
Jordan Liu0f2bc442020-11-18 16:47:37 -08007938 final long identity = Binder.clearCallingIdentity();
7939
Jack Yu479f40e2020-10-27 21:29:25 -07007940 boolean isCallingPackageDataService = phone.getDataServicePackages()
7941 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007942 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007943 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7944 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7945 Rlog.d(LOG_TAG,
7946 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7947 return null;
7948 }
7949
Hall Liuf19c44f2018-11-27 14:38:17 -08007950 ServiceState ss = phone.getServiceState();
7951
7952 // Scrub out the location info in ServiceState depending on what level of access
7953 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007954 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007955 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7956 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 } finally {
7958 Binder.restoreCallingIdentity(identity);
7959 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007960 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007961
7962 /**
7963 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7964 *
7965 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7966 * voicemail ringtone.
7967 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7968 * PhoneAccount.
7969 */
7970 @Override
7971 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007972 final long identity = Binder.clearCallingIdentity();
7973 try {
7974 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7975 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007976 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007977 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007979 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7980 } finally {
7981 Binder.restoreCallingIdentity(identity);
7982 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007983 }
7984
7985 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007986 * Sets the per-account voicemail ringtone.
7987 *
7988 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7989 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7990 *
7991 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7992 * voicemail ringtone.
7993 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7994 * PhoneAccount.
7995 */
7996 @Override
7997 public void setVoicemailRingtoneUri(String callingPackage,
7998 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007999 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008000 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008001 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8002 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8004 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8005 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008007
8008 final long identity = Binder.clearCallingIdentity();
8009 try {
8010 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8011 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008012 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008013 }
8014 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8015 } finally {
8016 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008017 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008018 }
8019
8020 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008021 * Returns whether vibration is set for voicemail notification in Phone settings.
8022 *
8023 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8024 * voicemail vibration setting.
8025 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8026 */
8027 @Override
8028 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008029 final long identity = Binder.clearCallingIdentity();
8030 try {
8031 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8032 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008033 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008034 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008035
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008036 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8037 } finally {
8038 Binder.restoreCallingIdentity(identity);
8039 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008040 }
8041
Youhan Wange64578a2016-05-02 15:32:42 -07008042 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008043 * Sets the per-account voicemail vibration.
8044 *
8045 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8046 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8047 *
8048 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8049 * voicemail vibration setting.
8050 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8051 * specific PhoneAccount.
8052 */
8053 @Override
8054 public void setVoicemailVibrationEnabled(String callingPackage,
8055 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008056 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008057 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008058 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8059 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8061 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8062 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008063 }
8064
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008065 final long identity = Binder.clearCallingIdentity();
8066 try {
8067 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8068 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008069 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070 }
8071 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8072 } finally {
8073 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008074 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008075 }
8076
8077 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008078 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8079 *
8080 * @throws SecurityException if the caller does not have the required permission
8081 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008082 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008083 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008084 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008085 }
8086
8087 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008088 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8089 * permission.
8090 *
8091 * @throws SecurityException if the caller does not have the required permission
8092 */
8093 private void enforceSendSmsPermission() {
8094 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8095 }
8096
8097 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008098 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008099 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008100 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008101 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008102 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008103 final long identity = Binder.clearCallingIdentity();
8104 try {
8105 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008106 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008107 if (componentName == null) {
8108 throw new SecurityException(
8109 "Caller not current active visual voicemail package[null]");
8110 }
8111 String vvmPackage = componentName.getPackageName();
8112 if (!callingPackage.equals(vvmPackage)) {
8113 throw new SecurityException("Caller not current active visual voicemail package["
8114 + vvmPackage + "]");
8115 }
8116 } finally {
8117 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008118 }
8119 }
8120
8121 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008122 * Return the application ID for the app type.
8123 *
8124 * @param subId the subscription ID that this request applies to.
8125 * @param appType the uicc app type.
8126 * @return Application ID for specificied app type, or null if no uicc.
8127 */
8128 @Override
8129 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008130 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008131 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008132
8133 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008134 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008135 if (phone == null) {
8136 return null;
8137 }
8138 String aid = null;
8139 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008140 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008141 .getApplicationByType(appType).getAid();
8142 } catch (Exception e) {
8143 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8144 }
8145 return aid;
8146 } finally {
8147 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008148 }
Youhan Wange64578a2016-05-02 15:32:42 -07008149 }
8150
Youhan Wang4001d252016-05-11 10:29:41 -07008151 /**
8152 * Return the Electronic Serial Number.
8153 *
8154 * @param subId the subscription ID that this request applies to.
8155 * @return ESN or null if error.
8156 */
8157 @Override
8158 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008159 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008160 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008161
8162 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008163 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008164 if (phone == null) {
8165 return null;
8166 }
8167 String esn = null;
8168 try {
8169 esn = phone.getEsn();
8170 } catch (Exception e) {
8171 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8172 }
8173 return esn;
8174 } finally {
8175 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008176 }
Youhan Wang4001d252016-05-11 10:29:41 -07008177 }
8178
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008179 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008180 * Return the Preferred Roaming List Version.
8181 *
8182 * @param subId the subscription ID that this request applies to.
8183 * @return PRLVersion or null if error.
8184 */
8185 @Override
8186 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008187 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008188 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189
8190 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008191 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008192 if (phone == null) {
8193 return null;
8194 }
8195 String cdmaPrlVersion = null;
8196 try {
8197 cdmaPrlVersion = phone.getCdmaPrlVersion();
8198 } catch (Exception e) {
8199 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8200 }
8201 return cdmaPrlVersion;
8202 } finally {
8203 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008204 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008205 }
8206
8207 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008208 * Get snapshot of Telephony histograms
8209 * @return List of Telephony histograms
8210 * @hide
8211 */
8212 @Override
8213 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8215 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008216
8217 final long identity = Binder.clearCallingIdentity();
8218 try {
8219 return RIL.getTelephonyRILTimingHistograms();
8220 } finally {
8221 Binder.restoreCallingIdentity(identity);
8222 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008223 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008224
8225 /**
8226 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008227 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8228 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008229 * Require system privileges. In the future we may add this to carrier APIs.
8230 *
Michele Berionne482f8202018-11-27 18:57:59 -08008231 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008232 */
8233 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008234 @TelephonyManager.SetCarrierRestrictionResult
8235 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008236 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008237 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008238
Michele Berionne482f8202018-11-27 18:57:59 -08008239 if (carrierRestrictionRules == null) {
8240 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008241 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008243 final long identity = Binder.clearCallingIdentity();
8244 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008245 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008246 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008247 } finally {
8248 Binder.restoreCallingIdentity(identity);
8249 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008250 }
8251
8252 /**
8253 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008254 * Get the allowed carrier list and the excluded carrier list, including the priority between
8255 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008256 * Require system privileges. In the future we may add this to carrier APIs.
8257 *
Michele Berionne482f8202018-11-27 18:57:59 -08008258 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008259 */
8260 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008261 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008262 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008264
8265 final long identity = Binder.clearCallingIdentity();
8266 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008267 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8268 if (response instanceof CarrierRestrictionRules) {
8269 return (CarrierRestrictionRules) response;
8270 }
8271 // Response is an Exception of some kind,
8272 // which is signalled to the user as a NULL retval
8273 return null;
8274 } catch (Exception e) {
8275 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8276 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008277 } finally {
8278 Binder.restoreCallingIdentity(identity);
8279 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008280 }
8281
fionaxu59545b42016-05-25 15:53:37 -07008282 /**
fionaxu59545b42016-05-25 15:53:37 -07008283 * Action set from carrier signalling broadcast receivers to enable/disable radio
8284 * @param subId the subscription ID that this action applies to.
8285 * @param enabled control enable or disable radio.
8286 * {@hide}
8287 */
8288 @Override
8289 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8290 enforceModifyPermission();
8291 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008292
8293 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008294 if (phone == null) {
8295 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8296 return;
8297 }
8298 try {
8299 phone.carrierActionSetRadioEnabled(enabled);
8300 } catch (Exception e) {
8301 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302 } finally {
8303 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008304 }
8305 }
8306
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008307 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008308 * Enable or disable Voice over NR (VoNR)
8309 * @param subId the subscription ID that this action applies to.
8310 * @param enabled enable or disable VoNR.
8311 * @return operation result.
8312 */
8313 @Override
8314 public int setVoNrEnabled(int subId, boolean enabled) {
8315 enforceModifyPermission();
8316 final Phone phone = getPhone(subId);
8317
8318 final long identity = Binder.clearCallingIdentity();
8319 if (phone == null) {
8320 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8321 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8322 }
8323
8324 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8325 try {
8326 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8327 workSource);
8328 if (DBG) log("setVoNrEnabled result: " + result);
8329 return result;
8330 } finally {
8331 Binder.restoreCallingIdentity(identity);
8332 }
8333 }
8334
8335 /**
8336 * Is voice over NR enabled
8337 * @return true if VoNR is enabled else false
8338 */
8339 @Override
8340 public boolean isVoNrEnabled(int subId) {
8341 enforceReadPrivilegedPermission("isVoNrEnabled");
8342 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8343 final long identity = Binder.clearCallingIdentity();
8344 try {
8345 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8346 null, subId, workSource);
8347 if (DBG) log("isVoNrEnabled: " + isEnabled);
8348 return isEnabled;
8349 } finally {
8350 Binder.restoreCallingIdentity(identity);
8351 }
8352 }
8353
8354 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008355 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8356 * network status based on which carrier apps could apply actions accordingly,
8357 * enable/disable default url handler for example.
8358 *
8359 * @param subId the subscription ID that this action applies to.
8360 * @param report control start/stop reporting the default network status.
8361 * {@hide}
8362 */
8363 @Override
8364 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8365 enforceModifyPermission();
8366 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367
8368 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008369 if (phone == null) {
8370 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8371 return;
8372 }
8373 try {
8374 phone.carrierActionReportDefaultNetworkStatus(report);
8375 } catch (Exception e) {
8376 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008377 } finally {
8378 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008379 }
8380 }
8381
8382 /**
fionaxud9622282017-07-17 17:51:30 -07008383 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8384 * @param subId the subscription ID that this action applies to.
8385 * {@hide}
8386 */
8387 @Override
8388 public void carrierActionResetAll(int subId) {
8389 enforceModifyPermission();
8390 final Phone phone = getPhone(subId);
8391 if (phone == null) {
8392 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8393 return;
8394 }
8395 try {
8396 phone.carrierActionResetAll();
8397 } catch (Exception e) {
8398 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8399 }
8400 }
8401
8402 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008403 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8404 * bug report is being generated.
8405 */
8406 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008407 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008408 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8409 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008410 writer.println("Permission Denial: can't dump Phone from pid="
8411 + Binder.getCallingPid()
8412 + ", uid=" + Binder.getCallingUid()
8413 + "without permission "
8414 + android.Manifest.permission.DUMP);
8415 return;
8416 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008417 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008418 }
Jack Yueb89b242016-06-22 13:27:47 -07008419
Brad Ebingerdac2f002018-04-03 15:17:52 -07008420 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008421 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8422 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8423 @NonNull String[] args) {
8424 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8425 this, in.getFileDescriptor(), out.getFileDescriptor(),
8426 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008427 }
8428
Jack Yueb89b242016-06-22 13:27:47 -07008429 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008430 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008431 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008432 * @param reason the reason the data enable change is taking place
8433 * @param enabled True if enabling the data, otherwise disabling.
8434 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008435 */
8436 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008437 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008438 boolean enabled) {
8439 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8440 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8441 try {
8442 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008443 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008444 } catch (SecurityException se) {
8445 enforceModifyPermission();
8446 }
8447 } else {
8448 enforceModifyPermission();
8449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008450
8451 final long identity = Binder.clearCallingIdentity();
8452 try {
8453 Phone phone = getPhone(subId);
8454 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008455 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8456 phone.carrierActionSetMeteredApnsEnabled(enabled);
8457 } else {
8458 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008460 }
8461 } finally {
8462 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008463 }
8464 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008465
8466 /**
8467 * Get Client request stats
8468 * @return List of Client Request Stats
8469 * @hide
8470 */
8471 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008472 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8473 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008475 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008476 return null;
8477 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008478 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008480 final long identity = Binder.clearCallingIdentity();
8481 try {
8482 if (phone != null) {
8483 return phone.getClientRequestStats();
8484 }
8485
8486 return null;
8487 } finally {
8488 Binder.restoreCallingIdentity(identity);
8489 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008490 }
8491
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008492 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008493 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008494 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008495 }
Jack Yueb4124c2017-02-16 15:32:43 -08008496
8497 /**
Grace Chen70990072017-03-24 17:21:30 -07008498 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008499 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008500 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008501 * @param state State of SIM (power down, power up, pass through)
8502 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8503 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8504 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008505 *
8506 **/
8507 @Override
Grace Chen70990072017-03-24 17:21:30 -07008508 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008509 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008510 Phone phone = PhoneFactory.getPhone(slotIndex);
8511
vagdeviaf9a5b92018-08-15 16:01:53 -07008512 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8513
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008514 final long identity = Binder.clearCallingIdentity();
8515 try {
8516 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008517 phone.setSimPowerState(state, null, workSource);
8518 }
8519 } finally {
8520 Binder.restoreCallingIdentity(identity);
8521 }
8522 }
8523
8524 /**
8525 * Set SIM card power state.
8526 *
8527 * @param slotIndex SIM slot id.
8528 * @param state State of SIM (power down, power up, pass through)
8529 * @param callback callback to trigger after success or failure
8530 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8531 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8532 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8533 *
8534 **/
8535 @Override
8536 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8537 IIntegerConsumer callback) {
8538 enforceModifyPermission();
8539 Phone phone = PhoneFactory.getPhone(slotIndex);
8540
8541 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8542
8543 final long identity = Binder.clearCallingIdentity();
8544 try {
8545 if (phone != null) {
8546 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8547 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008548 }
8549 } finally {
8550 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008551 }
8552 }
Shuo Qiandd210312017-04-12 22:11:33 +00008553
Tyler Gunn65d45c22017-06-05 11:22:26 -07008554 private boolean isUssdApiAllowed(int subId) {
8555 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008556 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008557 if (configManager == null) {
8558 return false;
8559 }
8560 PersistableBundle pb = configManager.getConfigForSubId(subId);
8561 if (pb == null) {
8562 return false;
8563 }
8564 return pb.getBoolean(
8565 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8566 }
8567
Shuo Qiandd210312017-04-12 22:11:33 +00008568 /**
8569 * Check if phone is in emergency callback mode
8570 * @return true if phone is in emergency callback mode
8571 * @param subId sub id
8572 */
goneil9c5f4872017-12-05 14:07:56 -08008573 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008574 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008575 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008576 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008577
8578 final long identity = Binder.clearCallingIdentity();
8579 try {
8580 if (phone != null) {
8581 return phone.isInEcm();
8582 } else {
8583 return false;
8584 }
8585 } finally {
8586 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008587 }
8588 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008589
8590 /**
8591 * Get the current signal strength information for the given subscription.
8592 * Because this information is not updated when the device is in a low power state
8593 * it should not be relied-upon to be current.
8594 * @param subId Subscription index
8595 * @return the most recent cached signal strength info from the modem
8596 */
8597 @Override
8598 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008599 final long identity = Binder.clearCallingIdentity();
8600 try {
8601 Phone p = getPhone(subId);
8602 if (p == null) {
8603 return null;
8604 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008605
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008606 return p.getSignalStrength();
8607 } finally {
8608 Binder.restoreCallingIdentity(identity);
8609 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008610 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008611
Pengquan Meng77b7f132018-08-22 14:49:57 -07008612 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008613 * Get the current modem radio state for the given slot.
8614 * @param slotIndex slot index.
8615 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008616 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008617 * @return the current radio power state from the modem
8618 */
8619 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008620 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008621 Phone phone = PhoneFactory.getPhone(slotIndex);
8622 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8624 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008625 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8626 }
8627
8628 final long identity = Binder.clearCallingIdentity();
8629 try {
8630 return phone.getRadioPowerState();
8631 } finally {
8632 Binder.restoreCallingIdentity(identity);
8633 }
8634 }
8635 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8636 }
8637
8638 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008639 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8640 *
8641 * <p>Requires one of the following permissions:
8642 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8643 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8644 * privileges.
8645 *
8646 * @param subId subscription id
8647 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8648 * {@code false}.
8649 */
8650 @Override
8651 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008652 try {
8653 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8654 null);
8655 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008656 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008657 mApp, subId, "isDataRoamingEnabled");
8658 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008659
Pengquan Menga1bb6272018-09-06 09:59:22 -07008660 boolean isEnabled = false;
8661 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008662 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008663 Phone phone = getPhone(subId);
8664 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008665 } finally {
8666 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008667 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008668 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008669 }
8670
8671
8672 /**
8673 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8674 *
8675 * <p> Requires permission:
8676 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8677 * privileges.
8678 *
8679 * @param subId subscription id
8680 * @param isEnabled {@code true} means enable, {@code false} means disable.
8681 */
8682 @Override
8683 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8685 mApp, subId, "setDataRoamingEnabled");
8686
Pengquan Menga1bb6272018-09-06 09:59:22 -07008687 final long identity = Binder.clearCallingIdentity();
8688 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008689 Phone phone = getPhone(subId);
8690 if (phone != null) {
8691 phone.setDataRoamingEnabled(isEnabled);
8692 }
8693 } finally {
8694 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008695 }
8696 }
8697
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008698 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008699 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008700 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008701 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008702 mApp, subId, "isManualNetworkSelectionAllowed");
8703
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008704 boolean isAllowed = true;
8705 final long identity = Binder.clearCallingIdentity();
8706 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008707 Phone phone = getPhone(subId);
8708 if (phone != null) {
8709 isAllowed = phone.isCspPlmnEnabled();
8710 }
8711 } finally {
8712 Binder.restoreCallingIdentity(identity);
8713 }
8714 return isAllowed;
8715 }
8716
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008717 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8718 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8719 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8720 // Update each UiccPort object based on privilege access
8721 UiccPort[] uiccPorts = card.getUiccPortList();
8722 for (UiccPort port : uiccPorts) {
8723 UiccProfile profile = port.getUiccProfile();
8724 if (profile == null ||
8725 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8726 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8727 return false;
8728 }
8729 }
8730 return true;
8731 }
8732
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008733 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008734 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008735 // Verify that tha callingPackage belongs to the calling UID
8736 mApp.getSystemService(AppOpsManager.class)
8737 .checkPackage(Binder.getCallingUid(), callingPackage);
8738
Jordan Liu1e142fc2019-04-22 15:10:43 -07008739 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008740 try {
8741 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008742 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008743 } catch (SecurityException e) {
8744 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8745 // has carrier privileges on an active UICC
8746 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8747 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008748 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008749 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008750 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008751
8752 final long identity = Binder.clearCallingIdentity();
8753 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008754 UiccController uiccController = UiccController.getInstance();
8755 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008756 if (hasReadPermission) {
8757 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008758 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008759
8760 // Remove private info if the caller doesn't have access
8761 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8762 for (UiccCardInfo cardInfo : cardInfos) {
8763 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8764 // is available
8765 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008766 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8767 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8768 if (card == null || card.getUiccPortList().length == 0) {
8769 // assume no access if the card or ports are unavailable
Jordan Liu1e142fc2019-04-22 15:10:43 -07008770 filteredInfos.add(cardInfo.getUnprivileged());
8771 continue;
8772 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008773
8774 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008775 filteredInfos.add(cardInfo);
8776 } else {
8777 filteredInfos.add(cardInfo.getUnprivileged());
8778 }
8779 }
8780 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008781 } finally {
8782 Binder.restoreCallingIdentity(identity);
8783 }
8784 }
8785
8786 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008787 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008788 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008790 final long identity = Binder.clearCallingIdentity();
8791 try {
8792 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8793 if (slots == null) {
8794 Rlog.i(LOG_TAG, "slots is null.");
8795 return null;
8796 }
8797
8798 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8799 for (int i = 0; i < slots.length; i++) {
8800 UiccSlot slot = slots[i];
8801 if (slot == null) {
8802 continue;
8803 }
8804
Jordan Liu7be7e652019-05-06 18:55:02 +00008805 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008806 UiccCard card = slot.getUiccCard();
8807 if (card != null) {
8808 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008809 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008810 cardId = slot.getEid();
8811 if (TextUtils.isEmpty(cardId)) {
8812 cardId = slot.getIccId();
8813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008814 }
8815
Jordan Liu857451f2019-05-09 16:35:35 -07008816 if (cardId != null) {
8817 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8818 // if cardId is an EID, it's all digits so this is fine
8819 cardId = IccUtils.stripTrailingFs(cardId);
8820 }
8821
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008822 int cardState = 0;
8823 switch (slot.getCardState()) {
8824 case CARDSTATE_ABSENT:
8825 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8826 break;
8827 case CARDSTATE_PRESENT:
8828 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8829 break;
8830 case CARDSTATE_ERROR:
8831 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8832 break;
8833 case CARDSTATE_RESTRICTED:
8834 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8835 break;
8836 default:
8837 break;
8838
8839 }
8840
8841 infos[i] = new UiccSlotInfo(
8842 slot.isActive(),
8843 slot.isEuicc(),
8844 cardId,
8845 cardState,
8846 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008847 slot.isExtendedApduSupported(),
8848 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008849 }
8850 return infos;
8851 } finally {
8852 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008853 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008854 }
8855
8856 @Override
8857 public boolean switchSlots(int[] physicalSlots) {
8858 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008859
8860 final long identity = Binder.clearCallingIdentity();
8861 try {
8862 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8863 } finally {
8864 Binder.restoreCallingIdentity(identity);
8865 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008866 }
Jack Yu4c988042018-02-27 15:30:01 -08008867
8868 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008869 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008870 final long identity = Binder.clearCallingIdentity();
8871 try {
8872 return UiccController.getInstance().getCardIdForDefaultEuicc();
8873 } finally {
8874 Binder.restoreCallingIdentity(identity);
8875 }
8876 }
8877
Pengquan Meng85728fb2018-03-12 16:31:21 -07008878 /**
goneil47ffb6e2018-04-06 15:40:58 -07008879 * A test API to reload the UICC profile.
8880 *
8881 * <p>Requires that the calling app has permission
8882 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8883 * @hide
8884 */
8885 @Override
8886 public void refreshUiccProfile(int subId) {
8887 enforceModifyPermission();
8888
8889 final long identity = Binder.clearCallingIdentity();
8890 try {
8891 Phone phone = getPhone(subId);
8892 if (phone == null) {
8893 return;
8894 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008895 UiccPort uiccPort = phone.getUiccPort();
8896 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008897 return;
8898 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008899 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008900 if (uiccProfile == null) {
8901 return;
8902 }
8903 uiccProfile.refresh();
8904 } finally {
8905 Binder.restoreCallingIdentity(identity);
8906 }
8907 }
8908
8909 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008910 * Returns false if the mobile data is disabled by default, otherwise return true.
8911 */
8912 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008913 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008914 }
8915
8916 /**
8917 * Returns true if the data roaming is enabled by default, i.e the system property
8918 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8919 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8920 */
8921 private boolean getDefaultDataRoamingEnabled(int subId) {
8922 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008923 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008924 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008925 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8926 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8927 return isDataRoamingEnabled;
8928 }
8929
8930 /**
8931 * Returns the default network type for the given {@code subId}, if the default network type is
8932 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8933 */
8934 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008935 List<Integer> list = TelephonyProperties.default_network();
8936 int phoneId = mSubscriptionController.getPhoneId(subId);
8937 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8938 return list.get(phoneId);
8939 }
8940 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008941 }
fionaxua13278b2018-03-21 00:08:13 -07008942
8943 @Override
8944 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008945 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008946 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008947
8948 final long identity = Binder.clearCallingIdentity();
8949 try {
8950 final Phone phone = getPhone(subId);
8951 if (phone == null) {
8952 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8953 return;
8954 }
chen xueaba88a2019-03-15 13:15:10 -07008955 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8956 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008957 if (carrierPrivilegeRules == null) {
8958 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8959 } else {
8960 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008962 } finally {
8963 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008964 }
fionaxua13278b2018-03-21 00:08:13 -07008965 }
8966
8967 @Override
8968 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008969 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008970
8971 final long identity = Binder.clearCallingIdentity();
8972 try {
8973 final Phone phone = getPhone(subId);
8974 if (phone == null) {
8975 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8976 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8977 }
8978 return phone.getCarrierIdListVersion();
8979 } finally {
8980 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008981 }
fionaxua13278b2018-03-21 00:08:13 -07008982 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008983
8984 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008985 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8986 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008988 mApp, subId, callingPackage, callingFeatureId,
8989 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008990 return -1;
8991 }
8992
8993 final long identity = Binder.clearCallingIdentity();
8994 try {
8995 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
8998 }
8999 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009000
9001 @Override
9002 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009003 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009004 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009005 mApp, subId, "getCdmaRoamingMode");
9006
9007 final long identity = Binder.clearCallingIdentity();
9008 try {
9009 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9010 } finally {
9011 Binder.restoreCallingIdentity(identity);
9012 }
9013 }
9014
9015 @Override
9016 public boolean setCdmaRoamingMode(int subId, int mode) {
9017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9018 mApp, subId, "setCdmaRoamingMode");
9019
9020 final long identity = Binder.clearCallingIdentity();
9021 try {
9022 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9023 } finally {
9024 Binder.restoreCallingIdentity(identity);
9025 }
9026 }
9027
9028 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009029 public int getCdmaSubscriptionMode(int subId) {
9030 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009031 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009032 mApp, subId, "getCdmaSubscriptionMode");
9033
9034 final long identity = Binder.clearCallingIdentity();
9035 try {
9036 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9037 } finally {
9038 Binder.restoreCallingIdentity(identity);
9039 }
9040 }
9041
9042 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009043 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9045 mApp, subId, "setCdmaSubscriptionMode");
9046
9047 final long identity = Binder.clearCallingIdentity();
9048 try {
9049 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9050 } finally {
9051 Binder.restoreCallingIdentity(identity);
9052 }
9053 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009054
sqianc5eccab2018-10-19 18:46:41 -07009055 @Override
sqian8c685422019-02-22 15:55:18 -08009056 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009057 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009058 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009059 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9060 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009061 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9062 }
9063 final long identity = Binder.clearCallingIdentity();
9064 try {
sqian854d44b2018-12-12 16:48:18 -08009065 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9066 for (Phone phone: PhoneFactory.getPhones()) {
9067 if (phone.getEmergencyNumberTracker() != null
9068 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9069 emergencyNumberListInternal.put(
9070 phone.getSubId(),
9071 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9072 }
sqian11b7a0e2018-12-05 18:48:28 -08009073 }
sqian854d44b2018-12-12 16:48:18 -08009074 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009075 } finally {
9076 Binder.restoreCallingIdentity(identity);
9077 }
sqianc5eccab2018-10-19 18:46:41 -07009078 }
9079
9080 @Override
sqian8c685422019-02-22 15:55:18 -08009081 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009082 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009083 if (!exactMatch) {
9084 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009085 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009086 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009087 }
9088 final long identity = Binder.clearCallingIdentity();
9089 try {
sqian854d44b2018-12-12 16:48:18 -08009090 for (Phone phone: PhoneFactory.getPhones()) {
9091 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009092 && phone.getEmergencyNumberTracker()
9093 .isEmergencyNumber(number, exactMatch)) {
9094 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009095 }
sqian11b7a0e2018-12-05 18:48:28 -08009096 }
9097 return false;
9098 } finally {
9099 Binder.restoreCallingIdentity(identity);
9100 }
9101 }
9102
sqianf4ca7ed2019-01-15 18:32:07 -08009103 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009104 * Start emergency callback mode for GsmCdmaPhone for testing.
9105 */
9106 @Override
9107 public void startEmergencyCallbackMode() {
9108 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9109 "startEmergencyCallbackMode");
9110 enforceModifyPermission();
9111 final long identity = Binder.clearCallingIdentity();
9112 try {
9113 for (Phone phone : PhoneFactory.getPhones()) {
9114 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9115 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9116 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9117 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9118 gsmCdmaPhone.obtainMessage(
9119 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9120 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9121 }
9122 }
9123 } finally {
9124 Binder.restoreCallingIdentity(identity);
9125 }
9126 }
9127
9128 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009129 * Update emergency number list for test mode.
9130 */
9131 @Override
9132 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9133 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9134 "updateEmergencyNumberListTestMode");
9135
9136 final long identity = Binder.clearCallingIdentity();
9137 try {
9138 for (Phone phone: PhoneFactory.getPhones()) {
9139 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9140 if (tracker != null) {
9141 tracker.executeEmergencyNumberTestModeCommand(action, num);
9142 }
9143 }
9144 } finally {
9145 Binder.restoreCallingIdentity(identity);
9146 }
9147 }
9148
9149 /**
9150 * Get the full emergency number list for test mode.
9151 */
9152 @Override
9153 public List<String> getEmergencyNumberListTestMode() {
9154 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9155 "getEmergencyNumberListTestMode");
9156
9157 final long identity = Binder.clearCallingIdentity();
9158 try {
9159 Set<String> emergencyNumbers = new HashSet<>();
9160 for (Phone phone: PhoneFactory.getPhones()) {
9161 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9162 if (tracker != null) {
9163 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9164 emergencyNumbers.add(num.getNumber());
9165 }
9166 }
9167 }
9168 return new ArrayList<>(emergencyNumbers);
9169 } finally {
9170 Binder.restoreCallingIdentity(identity);
9171 }
9172 }
9173
chen xud6b45bd2018-10-30 22:27:10 -07009174 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009175 public int getEmergencyNumberDbVersion(int subId) {
9176 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9177
9178 final long identity = Binder.clearCallingIdentity();
9179 try {
9180 final Phone phone = getPhone(subId);
9181 if (phone == null) {
9182 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9183 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9184 }
9185 return phone.getEmergencyNumberDbVersion();
9186 } finally {
9187 Binder.restoreCallingIdentity(identity);
9188 }
9189 }
9190
9191 @Override
9192 public void notifyOtaEmergencyNumberDbInstalled() {
9193 enforceModifyPermission();
9194
9195 final long identity = Binder.clearCallingIdentity();
9196 try {
9197 for (Phone phone: PhoneFactory.getPhones()) {
9198 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9199 if (tracker != null) {
9200 tracker.updateOtaEmergencyNumberDatabase();
9201 }
9202 }
9203 } finally {
9204 Binder.restoreCallingIdentity(identity);
9205 }
9206 }
9207
9208 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009209 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009210 enforceActiveEmergencySessionPermission();
9211
9212 final long identity = Binder.clearCallingIdentity();
9213 try {
9214 for (Phone phone: PhoneFactory.getPhones()) {
9215 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9216 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009217 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9218 }
9219 }
9220 } finally {
9221 Binder.restoreCallingIdentity(identity);
9222 }
9223 }
9224
9225 @Override
9226 public void resetOtaEmergencyNumberDbFilePath() {
9227 enforceActiveEmergencySessionPermission();
9228
9229 final long identity = Binder.clearCallingIdentity();
9230 try {
9231 for (Phone phone: PhoneFactory.getPhones()) {
9232 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9233 if (tracker != null) {
9234 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009235 }
9236 }
9237 } finally {
9238 Binder.restoreCallingIdentity(identity);
9239 }
9240 }
9241
9242 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009243 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9244 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9245 Phone phone = getPhone(subId);
9246 if (phone == null) {
9247 return null;
9248 }
9249 final long identity = Binder.clearCallingIdentity();
9250 try {
9251 UiccProfile profile = UiccController.getInstance()
9252 .getUiccProfileForPhone(phone.getPhoneId());
9253 if (profile != null) {
9254 return profile.getCertsFromCarrierPrivilegeAccessRules();
9255 }
9256 } finally {
9257 Binder.restoreCallingIdentity(identity);
9258 }
9259 return null;
9260 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009261
9262 /**
9263 * Enable or disable a modem stack.
9264 */
9265 @Override
9266 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9267 enforceModifyPermission();
9268
9269 final long identity = Binder.clearCallingIdentity();
9270 try {
9271 Phone phone = PhoneFactory.getPhone(slotIndex);
9272 if (phone == null) {
9273 return false;
9274 } else {
9275 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9276 }
9277 } finally {
9278 Binder.restoreCallingIdentity(identity);
9279 }
9280 }
Michelecea4cf22018-12-21 15:00:11 -08009281
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009282 /**
9283 * Whether a modem stack is enabled or not.
9284 */
9285 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009286 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9287 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009288 Phone phone = PhoneFactory.getPhone(slotIndex);
9289 if (phone == null) return false;
9290
9291 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009292 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9293 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009294 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9295 }
9296
9297 final long identity = Binder.clearCallingIdentity();
9298 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009299 try {
9300 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9301 } catch (NoSuchElementException ex) {
9302 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9303 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009304 } finally {
9305 Binder.restoreCallingIdentity(identity);
9306 }
9307 }
9308
Michelecea4cf22018-12-21 15:00:11 -08009309 @Override
Michele0ea7d782019-03-19 14:58:42 -07009310 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009311 enforceModifyPermission();
9312
9313 final long identity = Binder.clearCallingIdentity();
9314 try {
9315 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009316 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009317 .commit();
9318 } finally {
9319 Binder.restoreCallingIdentity(identity);
9320 }
9321 }
9322
9323 @Override
Michele0ea7d782019-03-19 14:58:42 -07009324 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009325 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009327 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9328 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009329 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009330 }
Michelecea4cf22018-12-21 15:00:11 -08009331
9332 final long identity = Binder.clearCallingIdentity();
9333 try {
Michele0ea7d782019-03-19 14:58:42 -07009334 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009335 } finally {
9336 Binder.restoreCallingIdentity(identity);
9337 }
9338 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009339
Michele0ea7d782019-03-19 14:58:42 -07009340 @TelephonyManager.IsMultiSimSupportedResult
9341 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009342 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9343 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9344 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009345 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9346 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009347 }
9348 // Check if the hardware supports multisim functionality. If usage of multisim is not
9349 // supported by the modem, indicate that it is restricted.
9350 PhoneCapability staticCapability =
9351 mPhoneConfigurationManager.getStaticPhoneCapability();
9352 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009353 loge("isMultiSimSupportedInternal: no static configuration available");
9354 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009355 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009356 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009357 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9358 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009359 }
9360 // Check if support of multiple SIMs is restricted by carrier
9361 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009362 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009363 }
9364
Michele0ea7d782019-03-19 14:58:42 -07009365 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009366 }
9367
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009368 /**
9369 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009370 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9371 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9372 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009373 * @param numOfSims number of active sims we want to switch to
9374 */
9375 @Override
9376 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009377 if (numOfSims == 1) {
9378 enforceModifyPermission();
9379 } else {
9380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9381 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9382 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009383 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009384
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009385 try {
Michele30b57b22019-03-01 12:01:14 -08009386 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009387 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009388 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9389 return;
9390 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009391 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9392 } finally {
9393 Binder.restoreCallingIdentity(identity);
9394 }
9395 }
9396
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009397 @Override
9398 public boolean isApplicationOnUicc(int subId, int appType) {
9399 enforceReadPrivilegedPermission("isApplicationOnUicc");
9400 Phone phone = getPhone(subId);
9401 if (phone == null) {
9402 return false;
9403 }
9404 final long identity = Binder.clearCallingIdentity();
9405 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009406 UiccPort uiccPort = phone.getUiccPort();
9407 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009408 return false;
9409 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009410 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009411 if (uiccProfile == null) {
9412 return false;
9413 }
9414 if (TelephonyManager.APPTYPE_SIM <= appType
9415 && appType <= TelephonyManager.APPTYPE_ISIM) {
9416 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9417 }
9418 return false;
9419 } finally {
9420 Binder.restoreCallingIdentity(identity);
9421 }
9422 }
9423
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009424 /**
chen xub4baa772019-04-03 10:23:41 -07009425 * Get whether making changes to modem configurations will trigger reboot.
9426 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009427 */
9428 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009429 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9430 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009431 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009432 mApp, subId, callingPackage, callingFeatureId,
9433 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009434 return false;
9435 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009436 final long identity = Binder.clearCallingIdentity();
9437 try {
9438 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9439 } finally {
9440 Binder.restoreCallingIdentity(identity);
9441 }
9442 }
9443
Nathan Harold29f5f052019-02-15 13:41:57 -08009444 private void updateModemStateMetrics() {
9445 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9446 // TODO: check the state for each modem if the api is ready.
9447 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9448 }
9449
Pengquan Meng3889a572019-01-23 11:16:29 -08009450 @Override
9451 public int[] getSlotsMapping() {
9452 enforceReadPrivilegedPermission("getSlotsMapping");
9453
9454 final long identity = Binder.clearCallingIdentity();
9455 try {
9456 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9457 // All logical slots should have a mapping to a physical slot.
9458 int[] logicalSlotsMapping = new int[phoneCount];
9459 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9460 for (int i = 0; i < slotInfos.length; i++) {
9461 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9462 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9463 }
9464 }
9465 return logicalSlotsMapping;
9466 } finally {
9467 Binder.restoreCallingIdentity(identity);
9468 }
9469 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009470
9471 /**
9472 * Get the IRadio HAL Version
9473 */
9474 @Override
9475 public int getRadioHalVersion() {
9476 Phone phone = getDefaultPhone();
9477 if (phone == null) return -1;
9478 HalVersion hv = phone.getHalVersion();
9479 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9480 return hv.major * 100 + hv.minor;
9481 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009482
9483 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009484 * Get the current calling package name.
9485 * @return the current calling package name
9486 */
9487 @Override
9488 public String getCurrentPackageName() {
9489 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9490 }
9491
9492 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009493 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9494 * corresponding network requests on a subId.
9495 *
9496 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009497 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009498 * 2) APN is un-metered for this subscription, or
9499 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009500 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009501 *
9502 * @return whether data is allowed for a apn type.
9503 *
9504 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009505 */
9506 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009507 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009508 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9509 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009510
9511 // Now that all security checks passes, perform the operation as ourselves.
9512 final long identity = Binder.clearCallingIdentity();
9513 try {
9514 Phone phone = getPhone(subId);
9515 if (phone == null) return false;
9516
Jack Yu41407ee2019-05-13 16:54:09 -07009517 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009518 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9519 } finally {
9520 Binder.restoreCallingIdentity(identity);
9521 }
9522 }
9523
9524 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009525 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009526 enforceReadPrivilegedPermission("isApnMetered");
9527
9528 // Now that all security checks passes, perform the operation as ourselves.
9529 final long identity = Binder.clearCallingIdentity();
9530 try {
9531 Phone phone = getPhone(subId);
9532 if (phone == null) return true; // By default return true.
9533
Jack Yu41407ee2019-05-13 16:54:09 -07009534 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009535 } finally {
9536 Binder.restoreCallingIdentity(identity);
9537 }
9538 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009539
9540 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009541 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9542 int subscriptionId, IBooleanConsumer resultCallback) {
9543 enforceModifyPermission();
9544 long token = Binder.clearCallingIdentity();
9545 try {
9546 Phone phone = getPhone(subscriptionId);
9547 if (phone == null) {
9548 try {
9549 if (resultCallback != null) {
9550 resultCallback.accept(false);
9551 }
9552 } catch (RemoteException e) {
9553 // ignore
9554 }
9555 return;
9556 }
9557 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9558 Pair.create(specifiers, (x) -> {
9559 try {
9560 if (resultCallback != null) {
9561 resultCallback.accept(x);
9562 }
9563 } catch (RemoteException e) {
9564 // ignore
9565 }
9566 });
9567 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9568 } finally {
9569 Binder.restoreCallingIdentity(token);
9570 }
9571 }
9572
9573 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009574 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9575 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009576 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009577 mApp, subId, "getSystemSelectionChannels");
9578 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9579 final long identity = Binder.clearCallingIdentity();
9580 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009581 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9582 if (result instanceof IllegalStateException) {
9583 throw (IllegalStateException) result;
9584 }
9585 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009586 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9587 return specifiers;
9588 } finally {
9589 Binder.restoreCallingIdentity(identity);
9590 }
9591 }
9592
9593 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009594 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009595 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009596 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9597 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9598 if (iccRecords == null) {
9599 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9600 return false;
9601 }
9602 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9603 }
9604
9605 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009606 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9607 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009608 if (callingPackage == null) {
9609 callingPackage = getCurrentPackageName();
9610 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009611 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9612 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009613 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9614 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009615 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9616 }
9617 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9618 Intent intent = new Intent();
9619 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9620 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9621 // Bring up choose default SMS subscription dialog right now
9622 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9623 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9624 mApp.startActivity(intent);
9625 }
chen xud5ca2d52019-05-28 15:20:57 -07009626
9627 @Override
9628 public String getMmsUAProfUrl(int subId) {
9629 //TODO investigate if this API should require proper permission check in R b/133791609
9630 final long identity = Binder.clearCallingIdentity();
9631 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009632 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9633 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9634 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9635 return carrierUAProfUrl;
9636 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009637 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9638 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009639 } finally {
9640 Binder.restoreCallingIdentity(identity);
9641 }
9642 }
9643
9644 @Override
9645 public String getMmsUserAgent(int subId) {
9646 //TODO investigate if this API should require proper permission check in R b/133791609
9647 final long identity = Binder.clearCallingIdentity();
9648 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009649 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9650 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9651 if (!TextUtils.isEmpty(carrierUserAgent)) {
9652 return carrierUserAgent;
9653 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009654 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9655 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009656 } finally {
9657 Binder.restoreCallingIdentity(identity);
9658 }
9659 }
Jack Yub07d4972019-05-28 16:12:25 -07009660
9661 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009662 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9663 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009664
Jack Yub07d4972019-05-28 16:12:25 -07009665 final long identity = Binder.clearCallingIdentity();
9666 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009667 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009668 if (phone == null) return false;
9669
Hall Liua62f5da2020-09-25 10:42:19 -07009670 switch (policy) {
9671 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9672 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9673 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9674 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9675 default:
9676 throw new IllegalArgumentException(policy + " is not a valid policy");
9677 }
Jack Yub07d4972019-05-28 16:12:25 -07009678 } finally {
9679 Binder.restoreCallingIdentity(identity);
9680 }
9681 }
9682
9683 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009684 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009685 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009686 enforceModifyPermission();
9687
changbettyd5c246e2019-12-24 15:40:37 +08009688 final long identity = Binder.clearCallingIdentity();
9689 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009690 Phone phone = getPhone(subscriptionId);
9691 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009692
Hall Liua62f5da2020-09-25 10:42:19 -07009693 switch (policy) {
9694 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9695 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9696 break;
9697 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9698 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9699 break;
9700 default:
9701 throw new IllegalArgumentException(policy + " is not a valid policy");
9702 }
changbettyd5c246e2019-12-24 15:40:37 +08009703 } finally {
9704 Binder.restoreCallingIdentity(identity);
9705 }
9706 }
9707
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009708 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009709 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009710 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9711 * otherwise.
9712 */
9713 @Override
9714 public void setCepEnabled(boolean isCepEnabled) {
9715 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9716
9717 final long identity = Binder.clearCallingIdentity();
9718 try {
9719 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9720 for (Phone phone : PhoneFactory.getPhones()) {
9721 Phone defaultPhone = phone.getImsPhone();
9722 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9723 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9724 ImsPhoneCallTracker imsPhoneCallTracker =
9725 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9726 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9727 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9728 + imsPhone.getMsisdn());
9729 }
9730 }
9731 } finally {
9732 Binder.restoreCallingIdentity(identity);
9733 }
9734 }
allenwtsu46dcc572020-01-08 18:24:03 +08009735
9736 /**
9737 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9738 *
9739 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9740 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9741 * before being read.
9742 */
9743 @Override
9744 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9745 isCompressed) {
9746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9747 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009748 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9749 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9750 }
9751 if (!isImsAvailableOnDevice()) {
9752 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9753 "IMS not available on device.");
9754 }
9755
9756 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009757 try {
Hui Wang761a6682020-10-31 05:12:53 +00009758 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9759 } finally {
9760 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009761 }
9762 }
zoey chene02881a2019-12-30 16:11:23 +08009763
9764 @Override
9765 public boolean isIccLockEnabled(int subId) {
9766 enforceReadPrivilegedPermission("isIccLockEnabled");
9767
9768 // Now that all security checks passes, perform the operation as ourselves.
9769 final long identity = Binder.clearCallingIdentity();
9770 try {
9771 Phone phone = getPhone(subId);
9772 if (phone != null && phone.getIccCard() != null) {
9773 return phone.getIccCard().getIccLockEnabled();
9774 } else {
9775 return false;
9776 }
9777 } finally {
9778 Binder.restoreCallingIdentity(identity);
9779 }
9780 }
9781
9782 /**
9783 * Set the ICC pin lock enabled or disabled.
9784 *
9785 * @return an integer representing the status of IccLock enabled or disabled in the following
9786 * three cases:
9787 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9788 * successfully.
9789 * - Positive number and zero for remaining password attempts.
9790 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9791 *
9792 */
9793 @Override
9794 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9795 enforceModifyPermission();
9796
9797 Phone phone = getPhone(subId);
9798 if (phone == null) {
9799 return 0;
9800 }
9801 // Now that all security checks passes, perform the operation as ourselves.
9802 final long identity = Binder.clearCallingIdentity();
9803 try {
9804 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9805 new Pair<Boolean, String>(enabled, password), phone, null);
9806 return attemptsRemaining;
9807
9808 } catch (Exception e) {
9809 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9810 } finally {
9811 Binder.restoreCallingIdentity(identity);
9812 }
9813 return 0;
9814 }
9815
9816 /**
9817 * Change the ICC password used in ICC pin lock.
9818 *
9819 * @return an integer representing the status of IccLock changed in the following three cases:
9820 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9821 * - Positive number and zero for remaining password attempts.
9822 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9823 *
9824 */
9825 @Override
9826 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9827 enforceModifyPermission();
9828
9829 Phone phone = getPhone(subId);
9830 if (phone == null) {
9831 return 0;
9832 }
9833 // Now that all security checks passes, perform the operation as ourselves.
9834 final long identity = Binder.clearCallingIdentity();
9835 try {
9836 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9837 new Pair<String, String>(oldPassword, newPassword), phone, null);
9838 return attemptsRemaining;
9839
9840 } catch (Exception e) {
9841 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9842 } finally {
9843 Binder.restoreCallingIdentity(identity);
9844 }
9845 return 0;
9846 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009847
9848 /**
9849 * Request for receiving user activity notification
9850 */
9851 @Override
9852 public void requestUserActivityNotification() {
9853 if (!mNotifyUserActivity.get()
9854 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9855 mNotifyUserActivity.set(true);
9856 }
9857 }
9858
9859 /**
9860 * Called when userActivity is signalled in the power manager.
9861 * This is safe to call from any thread, with any window manager locks held or not.
9862 */
9863 @Override
9864 public void userActivity() {
9865 // ***************************************
9866 // * Inherited from PhoneWindowManager *
9867 // ***************************************
9868 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9869 // WITH ITS LOCKS HELD.
9870 //
9871 // This code must be VERY careful about the locks
9872 // it acquires.
9873 // In fact, the current code acquires way too many,
9874 // and probably has lurking deadlocks.
9875
9876 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9877 throw new SecurityException("Only the OS may call notifyUserActivity()");
9878 }
9879
9880 if (mNotifyUserActivity.getAndSet(false)) {
9881 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9882 USER_ACTIVITY_NOTIFICATION_DELAY);
9883 }
9884 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009885
9886 @Override
9887 public boolean canConnectTo5GInDsdsMode() {
9888 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9889 }
Jack Yud10cdd42020-09-28 20:28:01 -07009890
9891 @Override
9892 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9893 String callingFeatureId) {
9894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9895 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9896 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9897 }
9898
9899 Phone phone = getPhone(subId);
9900 if (phone == null) {
9901 throw new RuntimeException("phone is not available");
9902 }
9903 // Now that all security checks passes, perform the operation as ourselves.
9904 final long identity = Binder.clearCallingIdentity();
9905 try {
9906 return phone.getEquivalentHomePlmns();
9907 } finally {
9908 Binder.restoreCallingIdentity(identity);
9909 }
9910 }
Daniel Bright59e67312020-11-13 11:49:37 -08009911
9912 @Override
9913 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009914 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9915 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009916 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009917 if (radioInterfaceCapabilities == null) {
9918 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009919 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009920 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009921 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009922
Hui Wang641e81c2020-10-12 12:14:23 -07009923 @Override
9924 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9925 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009926 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9927 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9928 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9929 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9930 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009931 if (DBG) {
9932 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9933 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9934 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9935 }
9936
9937 if (!SubscriptionManager.isValidSubscriptionId(subId)
9938 || appType < TelephonyManager.APPTYPE_UNKNOWN
9939 || appType > TelephonyManager.APPTYPE_ISIM
9940 || nafUrl == null || securityProtocol == null || callback == null) {
9941 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9942 if (callback != null) {
9943 try {
9944 callback.onAuthenticationFailure(
9945 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9946 } catch (RemoteException exception) {
9947 log("Fail to notify onAuthenticationFailure due to " + exception);
9948 }
9949 return;
9950 }
9951 }
9952
9953 final long token = Binder.clearCallingIdentity();
9954 try {
9955 getGbaManager(subId).bootstrapAuthenticationRequest(
9956 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9957 forceBootStrapping, callback));
9958 } finally {
9959 Binder.restoreCallingIdentity(token);
9960 }
9961 }
9962
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009963 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009964 * Attempts to set the radio power state for all phones for thermal reason.
9965 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009966 * requested radio power state will actually be set. See {@link
9967 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9968 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009969 * @param enable {@code true} if trying to turn radio on.
9970 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9971 * false}.
9972 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009973 private boolean setRadioPowerForThermal(boolean enable) {
9974 boolean isPhoneAvailable = false;
9975 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9976 Phone phone = PhoneFactory.getPhone(i);
9977 if (phone != null) {
9978 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9979 isPhoneAvailable = true;
9980 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009981 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009982
9983 // return true if successfully informed the phone object about the thermal radio power
9984 // request.
9985 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009986 }
9987
9988 private int handleDataThrottlingRequest(int subId,
9989 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009990 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9991 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9992 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9993 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9994 throw new IllegalArgumentException("modem does not support data throttling");
9995 }
9996
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009997 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9998 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009999 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010000 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10001 }
10002
10003 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10004
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010005 if (isDataThrottlingSupported) {
10006 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010007 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010008 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10009 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10010 } else if (thermalMitigationResult
10011 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010012 log("Modem likely does not support data throttling on secondary carrier. Data " +
10013 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10014 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010015 }
10016 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010017 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010018
10019 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010020 }
10021
Jack Nudelman644b91a2021-03-12 14:09:48 -080010022 private static List<String> getThermalMitigationAllowlist(Context context) {
10023 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10024 for (String pckg : context.getResources()
10025 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10026 sThermalMitigationAllowlistedPackages.add(pckg);
10027 }
10028 }
10029
10030 return sThermalMitigationAllowlistedPackages;
10031 }
10032
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010033 private boolean isAnyPhoneInEmergencyState() {
10034 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10035 if (tm.isInEmergencyCall()) {
10036 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10037 return true;
10038 }
10039 for (Phone phone : PhoneFactory.getPhones()) {
10040 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10041 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10042 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10043 + phone.isInEcm());
10044 return true;
10045 }
10046 }
10047
10048 return false;
10049 }
10050
Jack Nudelman644b91a2021-03-12 14:09:48 -080010051 /**
10052 * Used by shell commands to add an authorized package name for thermal mitigation.
10053 * @param packageName name of package to be allowlisted
10054 * @param context
10055 */
10056 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10057 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10058 sThermalMitigationAllowlistedPackages.add(packageName);
10059 }
10060
10061 /**
10062 * Used by shell commands to remove an authorized package name for thermal mitigation.
10063 * @param packageName name of package to remove from allowlist
10064 * @param context
10065 */
10066 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10067 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10068 sThermalMitigationAllowlistedPackages.remove(packageName);
10069 }
10070
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010071 /**
10072 * Thermal mitigation request to control functionalities at modem.
10073 *
10074 * @param subId the id of the subscription.
10075 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010076 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010077 *
10078 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10079 */
10080 @Override
10081 @ThermalMitigationResult
10082 public int sendThermalMitigationRequest(
10083 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010084 ThermalMitigationRequest thermalMitigationRequest,
10085 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010086 enforceModifyPermission();
10087
Jack Nudelman644b91a2021-03-12 14:09:48 -080010088 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10089 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10090 .contains(callingPackage)) {
10091 throw new SecurityException("Calling package must be configured in the device config. "
10092 + "calling package: " + callingPackage);
10093 }
10094
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010095 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10096 final long identity = Binder.clearCallingIdentity();
10097
10098 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10099 try {
10100 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10101 switch (thermalMitigationAction) {
10102 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10103 thermalMitigationResult =
10104 handleDataThrottlingRequest(subId,
10105 thermalMitigationRequest.getDataThrottlingRequest());
10106 break;
10107 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10108 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10109 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10110 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10111 }
10112
10113 // Ensure that radio is on. If not able to power on due to phone being
10114 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010115 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010116 thermalMitigationResult =
10117 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10118 break;
10119 }
10120
10121 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10122 false);
10123 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10124 break;
10125 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10126 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10127 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10128 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10129 }
10130
10131 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10132 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010133 Phone phone = getPhone(subId);
10134 if (phone == null) {
10135 thermalMitigationResult =
10136 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10137 break;
10138 }
10139
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010140 TelephonyConnectionService service =
10141 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010142 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010143 Log.e(LOG_TAG, "An emergency call is pending");
10144 thermalMitigationResult =
10145 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10146 break;
10147 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010148 thermalMitigationResult =
10149 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10150 break;
10151 }
10152 } else {
10153 thermalMitigationResult =
10154 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10155 break;
10156 }
10157
10158 // Turn radio off. If not able to power off due to phone being unavailable,
10159 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010160 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010161 thermalMitigationResult =
10162 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10163 break;
10164 }
10165 thermalMitigationResult =
10166 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10167 break;
10168 default:
10169 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10170 + "not exist. Requested action: " + thermalMitigationAction);
10171 }
10172 } catch (IllegalArgumentException e) {
10173 throw e;
10174 } catch (Exception e) {
10175 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10176 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10177 } finally {
10178 Binder.restoreCallingIdentity(identity);
10179 }
10180
10181 if (DBG) {
10182 log("thermalMitigationRequest returning with thermalMitigationResult: "
10183 + thermalMitigationResult);
10184 }
10185
10186 return thermalMitigationResult;
10187 }
Hui Wang641e81c2020-10-12 12:14:23 -070010188
10189 /**
10190 * Set the GbaService Package Name that Telephony will bind to.
10191 *
10192 * @param subId The sim that the GbaService is associated with.
10193 * @param packageName The name of the package to be replaced with.
10194 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10195 */
10196 @Override
10197 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10198 enforceModifyPermission();
10199
10200 final long identity = Binder.clearCallingIdentity();
10201 try {
10202 return getGbaManager(subId).overrideServicePackage(packageName);
10203 } finally {
10204 Binder.restoreCallingIdentity(identity);
10205 }
10206 }
10207
10208 /**
10209 * Return the package name of the currently bound GbaService.
10210 *
10211 * @param subId The sim that the GbaService is associated with.
10212 * @return the package name of the GbaService configuration, null if GBA is not supported.
10213 */
10214 @Override
10215 public String getBoundGbaService(int subId) {
10216 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10217
10218 final long identity = Binder.clearCallingIdentity();
10219 try {
10220 return getGbaManager(subId).getServicePackage();
10221 } finally {
10222 Binder.restoreCallingIdentity(identity);
10223 }
10224 }
10225
10226 /**
10227 * Set the release time for telephony to unbind GbaService.
10228 *
10229 * @param subId The sim that the GbaService is associated with.
10230 * @param interval The release time to unbind GbaService by millisecond.
10231 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10232 */
10233 @Override
10234 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10235 enforceModifyPermission();
10236
10237 final long identity = Binder.clearCallingIdentity();
10238 try {
10239 return getGbaManager(subId).overrideReleaseTime(interval);
10240 } finally {
10241 Binder.restoreCallingIdentity(identity);
10242 }
10243 }
10244
10245 /**
10246 * Return the release time for telephony to unbind GbaService.
10247 *
10248 * @param subId The sim that the GbaService is associated with.
10249 * @return The release time to unbind GbaService by millisecond.
10250 */
10251 @Override
10252 public int getGbaReleaseTime(int subId) {
10253 enforceReadPrivilegedPermission("getGbaReleaseTime");
10254
10255 final long identity = Binder.clearCallingIdentity();
10256 try {
10257 return getGbaManager(subId).getReleaseTime();
10258 } finally {
10259 Binder.restoreCallingIdentity(identity);
10260 }
10261 }
10262
10263 private GbaManager getGbaManager(int subId) {
10264 GbaManager instance = GbaManager.getInstance(subId);
10265 if (instance == null) {
10266 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10267 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10268 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10269 }
10270 return instance;
10271 }
Hui Wang761a6682020-10-31 05:12:53 +000010272
10273 /**
10274 * indicate whether the device and the carrier can support
10275 * RCS VoLTE single registration.
10276 */
10277 @Override
10278 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010279 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10280 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10281 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10282 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010283
10284 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10285 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10286 }
10287
10288 final long identity = Binder.clearCallingIdentity();
10289 try {
10290 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10291 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010292 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10293 if (isCapable != null) {
10294 return isCapable;
10295 }
Hui Wang761a6682020-10-31 05:12:53 +000010296 }
Hui Wang67af90e2021-06-04 16:57:15 -070010297 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10298 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010299 } finally {
10300 Binder.restoreCallingIdentity(identity);
10301 }
10302 }
10303
10304 /**
10305 * Register RCS provisioning callback.
10306 */
10307 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010308 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010309 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010310 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010311 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010312 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10313 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010314
10315 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10316 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10317 }
10318 if (!isImsAvailableOnDevice()) {
10319 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10320 "IMS not available on device.");
10321 }
10322
10323 final long identity = Binder.clearCallingIdentity();
10324 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010325 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010326 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010327 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10328 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010329 }
Hui Wang761a6682020-10-31 05:12:53 +000010330 } finally {
10331 Binder.restoreCallingIdentity(identity);
10332 }
10333 }
10334
10335 /**
10336 * Unregister RCS provisioning callback.
10337 */
10338 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010339 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010340 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010341 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010342 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010343 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10344 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010345
10346 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10347 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10348 }
10349 if (!isImsAvailableOnDevice()) {
10350 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10351 "IMS not available on device.");
10352 }
10353
10354 final long identity = Binder.clearCallingIdentity();
10355 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010356 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010357 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010358 } finally {
10359 Binder.restoreCallingIdentity(identity);
10360 }
10361 }
10362
10363 /**
10364 * trigger RCS reconfiguration.
10365 */
10366 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010367 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10368 "triggerRcsReconfiguration",
10369 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010370
10371 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10372 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10373 }
10374 if (!isImsAvailableOnDevice()) {
10375 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10376 "IMS not available on device.");
10377 }
10378
10379 final long identity = Binder.clearCallingIdentity();
10380 try {
10381 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10382 } finally {
10383 Binder.restoreCallingIdentity(identity);
10384 }
10385 }
10386
10387 /**
10388 * Provide the client configuration parameters of the RCS application.
10389 */
10390 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010391 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10392 "setRcsClientConfiguration",
10393 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010394
10395 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10396 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10397 }
10398 if (!isImsAvailableOnDevice()) {
10399 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10400 "IMS not available on device.");
10401 }
10402
10403 final long identity = Binder.clearCallingIdentity();
10404
10405 try {
10406 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10407 if (configBinder == null) {
10408 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010409 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10410 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010411 } else {
10412 configBinder.setRcsClientConfiguration(rcc);
10413 }
10414 } catch (RemoteException e) {
10415 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010416 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10417 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010418 } finally {
10419 Binder.restoreCallingIdentity(identity);
10420 }
10421 }
10422
10423 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010424 * Enables or disables the test mode for RCS VoLTE single registration.
10425 */
10426 @Override
10427 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10428 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10429 "setRcsSingleRegistrationTestModeEnabled");
10430
10431 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10432 }
10433
10434 /**
10435 * Gets the test mode for RCS VoLTE single registration.
10436 */
10437 @Override
10438 public boolean getRcsSingleRegistrationTestModeEnabled() {
10439 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10440 "getRcsSingleRegistrationTestModeEnabled");
10441
10442 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10443 }
10444
10445 /**
Hui Wang761a6682020-10-31 05:12:53 +000010446 * Overrides the config of RCS VoLTE single registration enabled for the device.
10447 */
10448 @Override
10449 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10450 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10451 "setDeviceSingleRegistrationEnabledOverride");
10452 enforceModifyPermission();
10453
10454 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10455 : Boolean.parseBoolean(enabledStr);
10456 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010457 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010458 }
10459
10460 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010461 * Sends a device to device communication message. Only usable via shell.
10462 * @param message message to send.
10463 * @param value message value.
10464 */
10465 @Override
10466 public void sendDeviceToDeviceMessage(int message, int value) {
10467 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010468 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010469 enforceModifyPermission();
10470
10471 final long identity = Binder.clearCallingIdentity();
10472 try {
10473 TelephonyConnectionService service =
10474 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10475 if (service == null) {
10476 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10477 return;
10478 }
10479 service.sendTestDeviceToDeviceMessage(message, value);
10480 } finally {
10481 Binder.restoreCallingIdentity(identity);
10482 }
10483 }
10484
Tyler Gunnbabbda02021-02-10 11:05:02 -080010485 /**
10486 * Sets the specified device to device transport active.
10487 * @param transport The transport to set active.
10488 */
10489 @Override
10490 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10491 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10492 "setActiveDeviceToDeviceTransport");
10493 enforceModifyPermission();
10494
10495 final long identity = Binder.clearCallingIdentity();
10496 try {
10497 TelephonyConnectionService service =
10498 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10499 if (service == null) {
10500 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10501 return;
10502 }
10503 service.setActiveDeviceToDeviceTransport(transport);
10504 } finally {
10505 Binder.restoreCallingIdentity(identity);
10506 }
10507 }
Tyler Gunn92479152021-01-20 16:30:10 -080010508
Tyler Gunnd4339262021-05-03 14:46:49 -070010509 @Override
10510 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10511 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10512 "setDeviceToDeviceForceEnabled");
10513
10514 final long identity = Binder.clearCallingIdentity();
10515 try {
10516 Arrays.stream(PhoneFactory.getPhones()).forEach(
10517 p -> {
10518 Phone thePhone = p.getImsPhone();
10519 if (thePhone != null && thePhone instanceof ImsPhone) {
10520 ImsPhone imsPhone = (ImsPhone) thePhone;
10521 CallTracker tracker = imsPhone.getCallTracker();
10522 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10523 ImsPhoneCallTracker imsPhoneCallTracker =
10524 (ImsPhoneCallTracker) tracker;
10525 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10526 }
10527 }
10528 }
10529 );
10530 } finally {
10531 Binder.restoreCallingIdentity(identity);
10532 }
10533 }
10534
Tyler Gunn92479152021-01-20 16:30:10 -080010535 /**
Hui Wang761a6682020-10-31 05:12:53 +000010536 * Gets the config of RCS VoLTE single registration enabled for the device.
10537 */
10538 @Override
10539 public boolean getDeviceSingleRegistrationEnabled() {
10540 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10541 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10542 }
10543
10544 /**
10545 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10546 */
10547 @Override
10548 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10549 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10550 "setCarrierSingleRegistrationEnabledOverride");
10551 enforceModifyPermission();
10552
10553 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10554 : Boolean.parseBoolean(enabledStr);
10555 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10556 subId, enabled);
10557 }
10558
10559 /**
10560 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10561 */
10562 @Override
10563 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10564 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10565 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10566 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010567
10568 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010569 * Overrides the ims feature validation result
10570 */
10571 @Override
10572 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10573 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10574 "setImsFeatureValidationOverride");
10575
10576 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10577 : Boolean.parseBoolean(enabledStr);
10578 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10579 subId, enabled);
10580 }
10581
10582 /**
10583 * Gets the ims feature validation override value
10584 */
10585 @Override
10586 public boolean getImsFeatureValidationOverride(int subId) {
10587 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10588 "getImsFeatureValidationOverride");
10589 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10590 }
10591
10592 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010593 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10594 * their mobile plan.
10595 */
10596 @Override
10597 public String getMobileProvisioningUrl() {
10598 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10599 final long identity = Binder.clearCallingIdentity();
10600 try {
10601 return getDefaultPhone().getMobileProvisioningUrl();
10602 } finally {
10603 Binder.restoreCallingIdentity(identity);
10604 }
10605 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010606
James.cf Linbcdf8b32021-01-14 16:44:13 +080010607 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010608 * Get the EAB contact from the EAB database.
10609 */
10610 @Override
10611 public String getContactFromEab(String contact) {
10612 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10613 enforceModifyPermission();
10614 final long identity = Binder.clearCallingIdentity();
10615 try {
10616 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10617 } finally {
10618 Binder.restoreCallingIdentity(identity);
10619 }
10620 }
10621
10622 /**
Calvin Pana1434322021-07-01 19:27:01 +080010623 * Get the EAB capability from the EAB database.
10624 */
10625 @Override
10626 public String getCapabilityFromEab(String contact) {
10627 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10628 enforceModifyPermission();
10629 final long identity = Binder.clearCallingIdentity();
10630 try {
10631 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10632 } finally {
10633 Binder.restoreCallingIdentity(identity);
10634 }
10635 }
10636
10637 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010638 * Remove the EAB contacts from the EAB database.
10639 */
10640 @Override
10641 public int removeContactFromEab(int subId, String contacts) {
10642 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10643 enforceModifyPermission();
10644 final long identity = Binder.clearCallingIdentity();
10645 try {
10646 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10647 } finally {
10648 Binder.restoreCallingIdentity(identity);
10649 }
10650 }
10651
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010652 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010653 public boolean getDeviceUceEnabled() {
10654 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10655 final long identity = Binder.clearCallingIdentity();
10656 try {
10657 return mApp.getDeviceUceEnabled();
10658 } finally {
10659 Binder.restoreCallingIdentity(identity);
10660 }
10661 }
10662
10663 @Override
10664 public void setDeviceUceEnabled(boolean isEnabled) {
10665 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10666 final long identity = Binder.clearCallingIdentity();
10667 try {
10668 mApp.setDeviceUceEnabled(isEnabled);
10669 } finally {
10670 Binder.restoreCallingIdentity(identity);
10671 }
10672 }
10673
Brad Ebinger14d467f2021-02-12 06:18:28 +000010674 /**
10675 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10676 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10677 */
10678 // Used for SHELL command only right now.
10679 @Override
10680 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10681 List<String> featureTags) {
10682 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10683 "addUceRegistrationOverrideShell");
10684 final long identity = Binder.clearCallingIdentity();
10685 try {
10686 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10687 new ArraySet<>(featureTags));
10688 } catch (ImsException e) {
10689 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10690 } finally {
10691 Binder.restoreCallingIdentity(identity);
10692 }
10693 }
10694
10695 /**
10696 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10697 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10698 */
10699 // Used for SHELL command only right now.
10700 @Override
10701 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10702 List<String> featureTags) {
10703 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10704 "removeUceRegistrationOverrideShell");
10705 final long identity = Binder.clearCallingIdentity();
10706 try {
10707 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10708 new ArraySet<>(featureTags));
10709 } catch (ImsException e) {
10710 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10711 } finally {
10712 Binder.restoreCallingIdentity(identity);
10713 }
10714 }
10715
10716 /**
10717 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10718 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10719 */
10720 // Used for SHELL command only right now.
10721 @Override
10722 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10723 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10724 "clearUceRegistrationOverrideShell");
10725 final long identity = Binder.clearCallingIdentity();
10726 try {
10727 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10728 } catch (ImsException e) {
10729 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10730 } finally {
10731 Binder.restoreCallingIdentity(identity);
10732 }
10733 }
10734
10735 /**
10736 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10737 */
10738 // Used for SHELL command only right now.
10739 @Override
10740 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10741 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10742 "getLatestRcsContactUceCapabilityShell");
10743 final long identity = Binder.clearCallingIdentity();
10744 try {
10745 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10746 } catch (ImsException e) {
10747 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10748 } finally {
10749 Binder.restoreCallingIdentity(identity);
10750 }
10751 }
10752
10753 /**
10754 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10755 * device does not have an active PUBLISH.
10756 */
10757 // Used for SHELL command only right now.
10758 @Override
10759 public String getLastUcePidfXmlShell(int subId) {
10760 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10761 final long identity = Binder.clearCallingIdentity();
10762 try {
10763 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10764 } catch (ImsException e) {
10765 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10766 } finally {
10767 Binder.restoreCallingIdentity(identity);
10768 }
10769 }
10770
James.cf Line8713a42021-04-29 16:04:26 +080010771 /**
10772 * Remove UCE requests cannot be sent to the network status.
10773 */
10774 // Used for SHELL command only right now.
10775 @Override
10776 public boolean removeUceRequestDisallowedStatus(int subId) {
10777 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10778 final long identity = Binder.clearCallingIdentity();
10779 try {
10780 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10781 } catch (ImsException e) {
10782 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10783 } finally {
10784 Binder.restoreCallingIdentity(identity);
10785 }
10786 }
10787
James.cf Lin18bb9002021-05-25 01:37:38 +080010788 /**
10789 * Remove UCE requests cannot be sent to the network status.
10790 */
10791 // Used for SHELL command only.
10792 @Override
10793 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10794 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10795 final long identity = Binder.clearCallingIdentity();
10796 try {
10797 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10798 } catch (ImsException e) {
10799 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10800 } finally {
10801 Binder.restoreCallingIdentity(identity);
10802 }
10803 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010804
James.cf Lin4b784aa2021-01-31 03:25:15 +080010805 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010806 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10807 String callingPackage) {
10808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10809 mApp, subId, "setSignalStrengthUpdateRequest");
10810
10811 final int callingUid = Binder.getCallingUid();
10812 // Verify that tha callingPackage belongs to the calling UID
10813 mApp.getSystemService(AppOpsManager.class)
10814 .checkPackage(callingUid, callingPackage);
10815
10816 validateSignalStrengthUpdateRequest(request, callingUid);
10817
10818 final long identity = Binder.clearCallingIdentity();
10819 try {
10820 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10821 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10822
10823 if (result instanceof IllegalStateException) {
10824 throw (IllegalStateException) result;
10825 }
10826 } finally {
10827 Binder.restoreCallingIdentity(identity);
10828 }
10829 }
10830
10831 @Override
10832 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10833 String callingPackage) {
10834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10835 mApp, subId, "clearSignalStrengthUpdateRequest");
10836
10837 final int callingUid = Binder.getCallingUid();
10838 // Verify that tha callingPackage belongs to the calling UID
10839 mApp.getSystemService(AppOpsManager.class)
10840 .checkPackage(callingUid, callingPackage);
10841
10842 final long identity = Binder.clearCallingIdentity();
10843 try {
10844 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10845 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10846
10847 if (result instanceof IllegalStateException) {
10848 throw (IllegalStateException) result;
10849 }
10850 } finally {
10851 Binder.restoreCallingIdentity(identity);
10852 }
10853 }
10854
10855 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10856 int callingUid) {
10857 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10858 // phone/system process do not have further restriction on request
10859 return;
10860 }
10861
10862 // Applications has restrictions on how to use the request:
10863 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10864 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10865 // This is not system caller which has been checked above
10866 throw new IllegalArgumentException(
10867 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10868 }
10869
10870 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10871 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10872 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10873 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10874 || info.isEnabled()) {
10875 throw new IllegalArgumentException(
10876 "Only system can set hide fields in SignalThresholdInfo");
10877 }
10878
10879 // Thresholds length for each RAN need in range. This has been validated in
10880 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10881 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10882 final int[] thresholds = info.getThresholds();
10883 Objects.requireNonNull(thresholds);
10884 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10885 || thresholds.length
10886 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10887 throw new IllegalArgumentException(
10888 "thresholds length is out of range: " + thresholds.length);
10889 }
10890 }
10891 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010892
10893 /**
10894 * Gets the current phone capability.
10895 *
10896 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10897 * @return the PhoneCapability which describes the data connection capability of modem.
10898 * It's used to evaluate possible phone config change, for example from single
10899 * SIM device to multi-SIM device.
10900 */
10901 @Override
10902 public PhoneCapability getPhoneCapability() {
10903 enforceReadPrivilegedPermission("getPhoneCapability");
10904 final long identity = Binder.clearCallingIdentity();
10905 try {
10906 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10907 } finally {
10908 Binder.restoreCallingIdentity(identity);
10909 }
10910 }
Michele Berionne5e411512020-11-13 02:36:59 +000010911
10912 /**
10913 * Prepare TelephonyManager for an unattended reboot. The reboot is
10914 * required to be done shortly after the API is invoked.
10915 */
10916 @Override
10917 @TelephonyManager.PrepareUnattendedRebootResult
10918 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010919 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000010920 enforceRebootPermission();
10921
10922 final long identity = Binder.clearCallingIdentity();
10923 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010924 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000010925 } finally {
10926 Binder.restoreCallingIdentity(identity);
10927 }
10928 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010929
10930 /**
10931 * Request to get the current slicing configuration including URSP rules and
10932 * NSSAIs (configured, allowed and rejected).
10933 *
10934 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10935 */
10936 @Override
10937 public void getSlicingConfig(ResultReceiver callback) {
10938 enforceReadPrivilegedPermission("getSlicingConfig");
10939
10940 final long identity = Binder.clearCallingIdentity();
10941 try {
10942 Phone phone = getDefaultPhone();
10943 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10944 } finally {
10945 Binder.restoreCallingIdentity(identity);
10946 }
10947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010948}