blob: 3c6a1c32792bc14e240a12a4683b40cd919ab2f5 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
25
Brad Ebinger34c09a52021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000032import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080033import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070034import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070035import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.content.Context;
37import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070038import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070039import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080040import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070041import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.net.Uri;
43import android.os.AsyncResult;
44import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080045import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Bundle;
47import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Looper;
50import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080052import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070053import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070054import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080055import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080056import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070057import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070058import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080059import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070061import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070063import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070064import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080065import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070066import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090067import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080068import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080069import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070070import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070071import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080072import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080073import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070074import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080075import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070076import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080077import android.telephony.CellIdentityCdma;
78import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070080import android.telephony.CellInfoGsm;
81import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080083import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070084import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070085import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070086import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080087import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070088import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070090import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080091import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080092import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070093import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080096import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080097import android.telephony.SignalStrengthUpdateRequest;
98import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080099import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800101import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800105import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800106import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000107import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700108import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700109import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800111import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800112import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700113import android.telephony.gba.GbaAuthRequest;
114import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700115import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800116import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000117import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000118import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700119import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700120import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700122import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800123import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700124import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000125import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700126import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800128import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800129import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800130import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700133import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800135import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800136
Andrew Lee312e8172014-10-23 17:01:36 -0700137import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800138import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800139import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800140import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800141import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700143import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700144import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800145import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700146import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700150import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800151import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800152import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800153import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700154import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700155import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800156import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800158import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700159import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700160import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700161import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700163import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800164import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700165import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700166import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700167import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700168import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800169import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800170import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700172import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800174import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800175import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800176import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700177import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800178import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700179import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800180import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700181import com.android.internal.telephony.imsphone.ImsPhone;
182import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800183import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700184import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800186import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187import com.android.internal.telephony.uicc.IccUtils;
Grace Jia59437e82021-09-21 15:47:32 -0700188import com.android.internal.telephony.uicc.PinStorage;
Nathan Haroldb3014052017-01-25 15:57:32 -0800189import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700190import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800191import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700192import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000193import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800194import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000195import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800196import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700197import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700198import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800199import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800200import com.android.phone.callcomposer.CallComposerPictureManager;
201import com.android.phone.callcomposer.CallComposerPictureTransfer;
202import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700203import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700204import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800205import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700206import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700207import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800208import com.android.services.telephony.TelecomAccountRegistry;
209import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800210import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800211
Hall Liu82694d52020-12-11 18:22:04 -0800212import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700213import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800214import java.io.IOException;
215import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700216import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800218import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800219import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800220import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800221import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100222import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800223import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700224import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800226import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800227import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800228import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800229import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700230
231/**
232 * Implementation of the ITelephony interface.
233 */
Santos Cordon117fee72014-05-16 17:56:12 -0700234public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235 private static final String LOG_TAG = "PhoneInterfaceManager";
236 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
237 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800238 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239
240 // Message codes used with mMainThreadHandler
241 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700242 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
243 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700244 private static final int CMD_OPEN_CHANNEL = 9;
245 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
246 private static final int CMD_CLOSE_CHANNEL = 11;
247 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800248 private static final int CMD_NV_READ_ITEM = 13;
249 private static final int EVENT_NV_READ_ITEM_DONE = 14;
250 private static final int CMD_NV_WRITE_ITEM = 15;
251 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
252 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
253 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700254 private static final int CMD_RESET_MODEM_CONFIG = 19;
255 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800256 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
257 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800258 private static final int CMD_SEND_ENVELOPE = 25;
259 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000260 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
261 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700262 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
263 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
264 private static final int CMD_EXCHANGE_SIM_IO = 31;
265 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800266 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
267 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700268 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
269 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700270 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
271 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700272 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
273 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
274 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
275 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700276 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
277 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
278 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
279 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700280 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800281 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
282 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000283 private static final int CMD_SWITCH_SLOTS = 50;
284 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700285 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
286 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
287 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
288 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
289 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
290 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
291 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
292 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700293 private static final int CMD_GET_ALL_CELL_INFO = 60;
294 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
295 private static final int CMD_GET_CELL_LOCATION = 62;
296 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700297 private static final int CMD_MODEM_REBOOT = 64;
298 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700299 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
300 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800301 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
302 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700303 private static final int CMD_GET_MODEM_STATUS = 70;
304 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700305 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
306 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700307 private static final int CMD_ERASE_MODEM_CONFIG = 74;
308 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800309 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
310 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
311 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
312 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800313 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
314 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800315 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800316 private static final int CMD_GET_CALL_FORWARDING = 83;
317 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
318 private static final int CMD_SET_CALL_FORWARDING = 85;
319 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
320 private static final int CMD_GET_CALL_WAITING = 87;
321 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
322 private static final int CMD_SET_CALL_WAITING = 89;
323 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700324 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
325 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
326 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
327 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700328 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
329 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800330 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
331 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800332 private static final int CMD_SET_DATA_THROTTLING = 99;
333 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800334 private static final int CMD_SET_SIM_POWER = 101;
335 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800336 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
337 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
338 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
339 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800340 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
341 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000342 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800343 private static final int CMD_GET_SLICING_CONFIG = 110;
344 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800345 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700346 private static final int CMD_ENABLE_VONR = 113;
347 private static final int EVENT_ENABLE_VONR_DONE = 114;
348 private static final int CMD_IS_VONR_ENABLED = 115;
349 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800351 // Parameters of select command.
352 private static final int SELECT_COMMAND = 0xA4;
353 private static final int SELECT_P1 = 0x04;
354 private static final int SELECT_P2 = 0;
355 private static final int SELECT_P3 = 0x10;
356
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357 /** The singleton instance. */
358 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800359 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
Wink Saville3ab207e2014-11-20 13:07:20 -0800361 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800362 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800363 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700364 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800365 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700366 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800367 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800368 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800369 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700370 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800371 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
Peter Wangdafb9ac2020-01-15 14:13:38 -0800373 /** User Activity */
374 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800375 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
376
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700377 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
378
Derek Tan97ebb422014-09-05 16:55:38 -0700379 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
380 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800381 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800382 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700383
Michelecea4cf22018-12-21 15:00:11 -0800384 // String to store multi SIM allowed
385 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
386
Derek Tan740e1672017-06-27 14:56:27 -0700387 // The AID of ISD-R.
388 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
389
yinxub1bed742017-04-17 11:45:04 -0700390 private NetworkScanRequestTracker mNetworkScanRequestTracker;
391
David Kelly5e06a7f2018-03-12 14:10:59 +0000392 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
393 private static final int MANUFACTURER_CODE_LENGTH = 8;
394
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800395 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800396 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800397
Derek Tan89e89d42014-07-08 17:00:10 -0700398 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700399 * Experiment flag to enable erase modem config on reset network, default value is false
400 */
401 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
402 "reset_network_erase_modem_config_enabled";
403
Rambo Wang0f050d82021-02-12 11:43:36 -0800404 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
405
Naina Nallurid63128d2019-09-17 14:10:30 -0700406 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700407 * A request object to use for transmitting data to an ICC.
408 */
409 private static final class IccAPDUArgument {
410 public int channel, cla, command, p1, p2, p3;
411 public String data;
412
413 public IccAPDUArgument(int channel, int cla, int command,
414 int p1, int p2, int p3, String data) {
415 this.channel = channel;
416 this.cla = cla;
417 this.command = command;
418 this.p1 = p1;
419 this.p2 = p2;
420 this.p3 = p3;
421 this.data = data;
422 }
423 }
424
425 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700426 * A request object to use for transmitting data to an ICC.
427 */
428 private static final class ManualNetworkSelectionArgument {
429 public OperatorInfo operatorInfo;
430 public boolean persistSelection;
431
432 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
433 this.operatorInfo = operatorInfo;
434 this.persistSelection = persistSelection;
435 }
436 }
437
438 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
440 * request after sending. The main thread will notify the request when it is complete.
441 */
442 private static final class MainThreadRequest {
443 /** The argument to use for the request */
444 public Object argument;
445 /** The result of the request that is run on the main thread */
446 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800447 // The subscriber id that this request applies to. Defaults to
448 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
449 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450
Nathan Harold92bed182018-10-12 18:16:49 -0700451 // In cases where subId is unavailable, the caller needs to specify the phone.
452 public Phone phone;
453
vagdeviaf9a5b92018-08-15 16:01:53 -0700454 public WorkSource workSource;
455
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 public MainThreadRequest(Object argument) {
457 this.argument = argument;
458 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800459
Nathan Harold92bed182018-10-12 18:16:49 -0700460 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
461 this.argument = argument;
462 if (phone != null) {
463 this.phone = phone;
464 }
465 this.workSource = workSource;
466 }
467
vagdeviaf9a5b92018-08-15 16:01:53 -0700468 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800469 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800470 if (subId != null) {
471 this.subId = subId;
472 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700473 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800474 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 }
476
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800477 private static final class IncomingThirdPartyCallArgs {
478 public final ComponentName component;
479 public final String callId;
480 public final String callerDisplayName;
481
482 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
483 String callerDisplayName) {
484 this.component = component;
485 this.callId = callId;
486 this.callerDisplayName = callerDisplayName;
487 }
488 }
489
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490 /**
491 * A handler that processes messages on the main thread in the phone process. Since many
492 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
493 * inbound binder threads to the main thread in the phone process. The Binder thread
494 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
495 * on, which will be notified when the operation completes and will contain the result of the
496 * request.
497 *
498 * <p>If a MainThreadRequest object is provided in the msg.obj field,
499 * note that request.result must be set to something non-null for the calling thread to
500 * unblock.
501 */
502 private final class MainThreadHandler extends Handler {
503 @Override
504 public void handleMessage(Message msg) {
505 MainThreadRequest request;
506 Message onCompleted;
507 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000508 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800510 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511
512 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700513 case CMD_HANDLE_USSD_REQUEST: {
514 request = (MainThreadRequest) msg.obj;
515 final Phone phone = getPhoneFromRequest(request);
516 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
517 String ussdRequest = ussdObject.first;
518 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700519
Pengquan Menga1bb6272018-09-06 09:59:22 -0700520 if (!isUssdApiAllowed(request.subId)) {
521 // Carrier does not support use of this API, return failure.
522 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
523 UssdResponse response = new UssdResponse(ussdRequest, null);
524 Bundle returnData = new Bundle();
525 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
526 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700527
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 request.result = true;
529 notifyRequester(request);
530 return;
531 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700532
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 try {
534 request.result = phone != null
535 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
536 } catch (CallStateException cse) {
537 request.result = false;
538 }
539 // Wake up the requesting thread
540 notifyRequester(request);
541 break;
pkanwar32d516d2016-10-14 19:37:38 -0700542 }
543
Yorke Lee716f67e2015-06-17 15:39:16 -0700544 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700546 final Phone phone = getPhoneFromRequest(request);
547 request.result = phone != null ?
548 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
549 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700554
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000558 uiccPort = getUiccPortFromRequest(request);
559 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 loge("iccTransmitApduLogicalChannel: No UICC");
561 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700562 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
565 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000566 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 iccArgument.channel, iccArgument.cla, iccArgument.command,
568 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 break;
572
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 ar = (AsyncResult) msg.obj;
575 request = (MainThreadRequest) ar.userObj;
576 if (ar.exception == null && ar.result != null) {
577 request.result = ar.result;
578 } else {
579 request.result = new IccIoResult(0x6F, 0, (byte[])null);
580 if (ar.result == null) {
581 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800582 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800584 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 } else {
586 loge("iccTransmitApduLogicalChannel: Unknown exception");
587 }
588 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 break;
591
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
593 request = (MainThreadRequest) msg.obj;
594 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000595 uiccPort = getUiccPortFromRequest(request);
596 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 loge("iccTransmitApduBasicChannel: No UICC");
598 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 } else {
601 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
602 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000603 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
605 iccArgument.p3, iccArgument.data, onCompleted);
606 }
607 break;
608
609 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
610 ar = (AsyncResult) msg.obj;
611 request = (MainThreadRequest) ar.userObj;
612 if (ar.exception == null && ar.result != null) {
613 request.result = ar.result;
614 } else {
615 request.result = new IccIoResult(0x6F, 0, (byte[])null);
616 if (ar.result == null) {
617 loge("iccTransmitApduBasicChannel: Empty response");
618 } else if (ar.exception instanceof CommandException) {
619 loge("iccTransmitApduBasicChannel: CommandException: " +
620 ar.exception);
621 } else {
622 loge("iccTransmitApduBasicChannel: Unknown exception");
623 }
624 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700625 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 break;
627
628 case CMD_EXCHANGE_SIM_IO:
629 request = (MainThreadRequest) msg.obj;
630 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000631 uiccPort = getUiccPortFromRequest(request);
632 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 loge("iccExchangeSimIO: No UICC");
634 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700636 } else {
637 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
638 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000639 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
641 iccArgument.data, onCompleted);
642 }
643 break;
644
645 case EVENT_EXCHANGE_SIM_IO_DONE:
646 ar = (AsyncResult) msg.obj;
647 request = (MainThreadRequest) ar.userObj;
648 if (ar.exception == null && ar.result != null) {
649 request.result = ar.result;
650 } else {
651 request.result = new IccIoResult(0x6f, 0, (byte[])null);
652 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700653 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 break;
655
Derek Tan4d5e5c12014-02-04 11:54:58 -0800656 case CMD_SEND_ENVELOPE:
657 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000658 uiccPort = getUiccPortFromRequest(request);
659 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700660 loge("sendEnvelopeWithStatus: No UICC");
661 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700662 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700663 } else {
664 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000665 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700666 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800667 break;
668
669 case EVENT_SEND_ENVELOPE_DONE:
670 ar = (AsyncResult) msg.obj;
671 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700672 if (ar.exception == null && ar.result != null) {
673 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800674 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700675 request.result = new IccIoResult(0x6F, 0, (byte[])null);
676 if (ar.result == null) {
677 loge("sendEnvelopeWithStatus: Empty response");
678 } else if (ar.exception instanceof CommandException) {
679 loge("sendEnvelopeWithStatus: CommandException: " +
680 ar.exception);
681 } else {
682 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
683 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800684 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800686 break;
687
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 case CMD_OPEN_CHANNEL:
689 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000690 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800691 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000692 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700693 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800694 request.result = new IccOpenLogicalChannelResponse(-1,
695 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 } else {
698 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000699 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800700 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700701 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 break;
703
704 case EVENT_OPEN_CHANNEL_DONE:
705 ar = (AsyncResult) msg.obj;
706 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 int[] result = (int[]) ar.result;
710 int channelId = result[0];
711 byte[] selectResponse = null;
712 if (result.length > 1) {
713 selectResponse = new byte[result.length - 1];
714 for (int i = 1; i < result.length; ++i) {
715 selectResponse[i - 1] = (byte) result[i];
716 }
717 }
718 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700719 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 if (ar.result == null) {
722 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700723 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700724 if (ar.exception != null) {
725 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
726 }
727
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700728 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700729 if (ar.exception instanceof CommandException) {
730 CommandException.Error error =
731 ((CommandException) (ar.exception)).getCommandError();
732 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700733 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700734 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700735 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700736 }
737 }
738 openChannelResp = new IccOpenLogicalChannelResponse(
739 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700741 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 break;
744
745 case CMD_CLOSE_CHANNEL:
746 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000747 uiccPort = getUiccPortFromRequest(request);
748 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700749 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900750 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700751 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700752 } else {
753 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000754 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700755 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 break;
757
758 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800759 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
760 break;
761
762 case CMD_NV_READ_ITEM:
763 request = (MainThreadRequest) msg.obj;
764 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800765 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
766 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800767 break;
768
769 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 ar = (AsyncResult) msg.obj;
771 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800772 if (ar.exception == null && ar.result != null) {
773 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700774 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800775 request.result = "";
776 if (ar.result == null) {
777 loge("nvReadItem: Empty response");
778 } else if (ar.exception instanceof CommandException) {
779 loge("nvReadItem: CommandException: " +
780 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800782 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700783 }
784 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700785 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700786 break;
787
Jake Hambye994d462014-02-03 13:10:13 -0800788 case CMD_NV_WRITE_ITEM:
789 request = (MainThreadRequest) msg.obj;
790 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
791 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800792 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700793 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800794 break;
795
796 case EVENT_NV_WRITE_ITEM_DONE:
797 handleNullReturnEvent(msg, "nvWriteItem");
798 break;
799
800 case CMD_NV_WRITE_CDMA_PRL:
801 request = (MainThreadRequest) msg.obj;
802 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800803 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800804 break;
805
806 case EVENT_NV_WRITE_CDMA_PRL_DONE:
807 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
808 break;
809
chen xu6dac5ab2018-10-26 17:39:23 -0700810 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800811 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700812 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800813 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800814 break;
815
chen xu6dac5ab2018-10-26 17:39:23 -0700816 case EVENT_RESET_MODEM_CONFIG_DONE:
817 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800818 break;
819
Sooraj Sasindran37444802020-08-11 10:40:43 -0700820 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
821 request = (MainThreadRequest) msg.obj;
822 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
823 request);
824 Phone phone = getPhoneFromRequest(request);
825 if (phone != null) {
826 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
827 } else {
828 loge("isNRDualConnectivityEnabled: No phone object");
829 request.result = false;
830 notifyRequester(request);
831 }
832 break;
833 }
834
835 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
836 ar = (AsyncResult) msg.obj;
837 request = (MainThreadRequest) ar.userObj;
838 if (ar.exception == null && ar.result != null) {
839 request.result = ar.result;
840 } else {
841 // request.result must be set to something non-null
842 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700843 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700844 request.result = ar.result;
845 } else {
846 request.result = false;
847 }
848 if (ar.result == null) {
849 loge("isNRDualConnectivityEnabled: Empty response");
850 } else if (ar.exception instanceof CommandException) {
851 loge("isNRDualConnectivityEnabled: CommandException: "
852 + ar.exception);
853 } else {
854 loge("isNRDualConnectivityEnabled: Unknown exception");
855 }
856 }
857 notifyRequester(request);
858 break;
859
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700860 case CMD_IS_VONR_ENABLED: {
861 request = (MainThreadRequest) msg.obj;
862 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
863 request);
864 Phone phone = getPhoneFromRequest(request);
865 if (phone != null) {
866 phone.isVoNrEnabled(onCompleted, request.workSource);
867 } else {
868 loge("isVoNrEnabled: No phone object");
869 request.result = false;
870 notifyRequester(request);
871 }
872 break;
873 }
874
875 case EVENT_IS_VONR_ENABLED_DONE:
876 ar = (AsyncResult) msg.obj;
877 request = (MainThreadRequest) ar.userObj;
878 if (ar.exception == null && ar.result != null) {
879 request.result = ar.result;
880 } else {
881 // request.result must be set to something non-null
882 // for the calling thread to unblock
883 if (ar.result != null) {
884 request.result = ar.result;
885 } else {
886 request.result = false;
887 }
888 if (ar.result == null) {
889 loge("isVoNrEnabled: Empty response");
890 } else if (ar.exception instanceof CommandException) {
891 loge("isVoNrEnabled: CommandException: "
892 + ar.exception);
893 } else {
894 loge("isVoNrEnabled: Unknown exception");
895 }
896 }
897 notifyRequester(request);
898 break;
899
Sooraj Sasindran37444802020-08-11 10:40:43 -0700900 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
901 request = (MainThreadRequest) msg.obj;
902 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
903 Phone phone = getPhoneFromRequest(request);
904 if (phone != null) {
905 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
906 request.workSource);
907 } else {
908 loge("enableNrDualConnectivity: No phone object");
909 request.result =
910 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
911 notifyRequester(request);
912 }
913 break;
914 }
915
916 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 if (ar.exception == null) {
920 request.result =
921 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
922 } else {
923 request.result =
924 TelephonyManager
925 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
926 if (ar.exception instanceof CommandException) {
927 CommandException.Error error =
928 ((CommandException) (ar.exception)).getCommandError();
929 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
930 request.result =
931 TelephonyManager
932 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000933 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
934 request.result =
935 TelephonyManager
936 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700937 }
938 loge("enableNrDualConnectivity" + ": CommandException: "
939 + ar.exception);
940 } else {
941 loge("enableNrDualConnectivity" + ": Unknown exception");
942 }
943 }
944 notifyRequester(request);
945 break;
946 }
947
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700948 case CMD_ENABLE_VONR: {
949 request = (MainThreadRequest) msg.obj;
950 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
951 Phone phone = getPhoneFromRequest(request);
952 if (phone != null) {
953 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
954 request.workSource);
955 } else {
956 loge("setVoNrEnabled: No phone object");
957 request.result =
958 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
959 notifyRequester(request);
960 }
961 break;
962 }
963
964 case EVENT_ENABLE_VONR_DONE: {
965 ar = (AsyncResult) msg.obj;
966 request = (MainThreadRequest) ar.userObj;
967 if (ar.exception == null) {
968 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
969 } else {
970 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
971 if (ar.exception instanceof CommandException) {
972 CommandException.Error error =
973 ((CommandException) (ar.exception)).getCommandError();
974 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
975 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
976 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
977 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
978 } else {
979 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
980 }
981 loge("setVoNrEnabled" + ": CommandException: "
982 + ar.exception);
983 } else {
984 loge("setVoNrEnabled" + ": Unknown exception");
985 }
986 }
987 notifyRequester(request);
988 break;
989 }
990
SongFerngWang3ef3e072020-12-21 16:41:52 +0800991 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800992 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800993 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
994 request);
995 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800996 break;
997
SongFerngWang3ef3e072020-12-21 16:41:52 +0800998 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 if (ar.exception == null && ar.result != null) {
1002 request.result = ar.result; // Integer
1003 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301004 // request.result must be set to something non-null
1005 // for the calling thread to unblock
1006 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001007 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001008 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001009 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001010 loge("getAllowedNetworkTypesBitmask: CommandException: "
1011 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001012 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001013 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001014 }
1015 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001016 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001017 break;
1018
SongFerngWang3ef3e072020-12-21 16:41:52 +08001019 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001020 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001021 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1022 request);
1023 Pair<Integer, Long> reasonWithNetworkTypes =
1024 (Pair<Integer, Long>) request.argument;
1025 getPhoneFromRequest(request).setAllowedNetworkTypes(
1026 reasonWithNetworkTypes.first,
1027 reasonWithNetworkTypes.second,
1028 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001029 break;
1030
SongFerngWang3ef3e072020-12-21 16:41:52 +08001031 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1032 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001033 break;
1034
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001035 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1036 request = (MainThreadRequest)msg.obj;
1037 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001038 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001039 break;
1040
1041 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1042 ar = (AsyncResult)msg.obj;
1043 request = (MainThreadRequest)ar.userObj;
1044 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001045 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001046 break;
1047
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001048 case CMD_SET_VOICEMAIL_NUMBER:
1049 request = (MainThreadRequest) msg.obj;
1050 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1051 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001052 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1053 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001054 break;
1055
1056 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1057 handleNullReturnEvent(msg, "setVoicemailNumber");
1058 break;
1059
Stuart Scott54788802015-03-30 13:18:01 -07001060 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1061 request = (MainThreadRequest) msg.obj;
1062 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1063 request);
1064 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1065 break;
1066
1067 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1068 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1069 break;
1070
Shishir Agrawal302c8692015-06-19 13:49:39 -07001071 case CMD_PERFORM_NETWORK_SCAN:
1072 request = (MainThreadRequest) msg.obj;
1073 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1074 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1075 break;
1076
Hall Liu27d24262020-09-18 19:04:59 -07001077 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001078 request = (MainThreadRequest) msg.obj;
1079 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001080 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1081 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1082 request.argument;
1083 int callForwardingReason = args.first;
1084 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001085 break;
Hall Liu27d24262020-09-18 19:04:59 -07001086 }
1087 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001088 ar = (AsyncResult) msg.obj;
1089 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001090 TelephonyManager.CallForwardingInfoCallback callback =
1091 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1092 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001093 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001094 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001095 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1096 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1097 // Service Class is a bit mask per 3gpp 27.007. Search for
1098 // any service for voice call.
1099 if ((callForwardInfo.serviceClass
1100 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001101 callForwardingInfo = new CallForwardingInfo(true,
1102 callForwardInfo.reason,
1103 callForwardInfo.number,
1104 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001105 break;
1106 }
1107 }
1108 // Didn't find a call forward info for voice call.
1109 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001110 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1111 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001112 }
Hall Liu27d24262020-09-18 19:04:59 -07001113 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001114 } else {
1115 if (ar.result == null) {
1116 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1117 }
1118 if (ar.exception != null) {
1119 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1120 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001121 int errorCode = TelephonyManager
1122 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001123 if (ar.exception instanceof CommandException) {
1124 CommandException.Error error =
1125 ((CommandException) (ar.exception)).getCommandError();
1126 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001127 errorCode = TelephonyManager
1128 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001129 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001130 errorCode = TelephonyManager
1131 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001132 }
1133 }
Hall Liu27d24262020-09-18 19:04:59 -07001134 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001135 }
Shuo Qian4a594052020-01-23 11:59:30 -08001136 break;
Hall Liu27d24262020-09-18 19:04:59 -07001137 }
Shuo Qian4a594052020-01-23 11:59:30 -08001138
Hall Liu27d24262020-09-18 19:04:59 -07001139 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001140 request = (MainThreadRequest) msg.obj;
1141 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001142 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001143 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001144 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1145 request.argument).first;
1146 request.phone.setCallForwardingOption(
1147 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001148 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001149 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001150 callForwardingInfoToSet.getReason(),
1151 callForwardingInfoToSet.getNumber(),
1152 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1153 break;
Hall Liu27d24262020-09-18 19:04:59 -07001154 }
Shuo Qian4a594052020-01-23 11:59:30 -08001155
Hall Liu27d24262020-09-18 19:04:59 -07001156 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001157 ar = (AsyncResult) msg.obj;
1158 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001159 Consumer<Integer> callback =
1160 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1161 request.argument).second;
1162 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001163 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001164 int errorCode = TelephonyManager.CallForwardingInfoCallback
1165 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001166 if (ar.exception instanceof CommandException) {
1167 CommandException.Error error =
1168 ((CommandException) (ar.exception)).getCommandError();
1169 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001170 errorCode = TelephonyManager.CallForwardingInfoCallback
1171 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001172 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001173 errorCode = TelephonyManager.CallForwardingInfoCallback
1174 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001175 }
1176 }
1177 callback.accept(errorCode);
1178 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001179 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001180 }
Shuo Qian4a594052020-01-23 11:59:30 -08001181 break;
Hall Liu27d24262020-09-18 19:04:59 -07001182 }
Shuo Qian4a594052020-01-23 11:59:30 -08001183
Hall Liu27d24262020-09-18 19:04:59 -07001184 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001185 request = (MainThreadRequest) msg.obj;
1186 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1187 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1188 break;
Hall Liu27d24262020-09-18 19:04:59 -07001189 }
Shuo Qian4a594052020-01-23 11:59:30 -08001190
Hall Liu27d24262020-09-18 19:04:59 -07001191 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001192 ar = (AsyncResult) msg.obj;
1193 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001194 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001195 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1196 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001197 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001198 // Service Class is a bit mask per 3gpp 27.007.
1199 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001200 if (callForwardResults.length > 1
1201 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001202 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001203 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001204 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1205 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001206 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001207 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001208 }
1209 } else {
1210 if (ar.result == null) {
1211 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1212 }
1213 if (ar.exception != null) {
1214 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1215 }
1216 if (ar.exception instanceof CommandException) {
1217 CommandException.Error error =
1218 ((CommandException) (ar.exception)).getCommandError();
1219 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1220 callForwardingStatus =
1221 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1222 }
1223 }
1224 }
Hall Liu27d24262020-09-18 19:04:59 -07001225 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001226 break;
Hall Liu27d24262020-09-18 19:04:59 -07001227 }
Shuo Qian4a594052020-01-23 11:59:30 -08001228
Hall Liu27d24262020-09-18 19:04:59 -07001229 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001230 request = (MainThreadRequest) msg.obj;
1231 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001232 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1233 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001234 break;
Hall Liu27d24262020-09-18 19:04:59 -07001235 }
Shuo Qian4a594052020-01-23 11:59:30 -08001236
Hall Liu27d24262020-09-18 19:04:59 -07001237 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001238 ar = (AsyncResult) msg.obj;
1239 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001240 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1241 Consumer<Integer> callback =
1242 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1243 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001244 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001245 if (ar.exception instanceof CommandException) {
1246 CommandException.Error error =
1247 ((CommandException) (ar.exception)).getCommandError();
1248 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1249 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1250 } else {
1251 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1252 }
1253 } else {
1254 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1255 }
1256 } else {
1257 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1258 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001259 }
Shuo Qian4a594052020-01-23 11:59:30 -08001260 break;
Hall Liu27d24262020-09-18 19:04:59 -07001261 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001262 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1263 ar = (AsyncResult) msg.obj;
1264 request = (MainThreadRequest) ar.userObj;
1265 CellNetworkScanResult cellScanResult;
1266 if (ar.exception == null && ar.result != null) {
1267 cellScanResult = new CellNetworkScanResult(
1268 CellNetworkScanResult.STATUS_SUCCESS,
1269 (List<OperatorInfo>) ar.result);
1270 } else {
1271 if (ar.result == null) {
1272 loge("getCellNetworkScanResults: Empty response");
1273 }
1274 if (ar.exception != null) {
1275 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1276 }
1277 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1278 if (ar.exception instanceof CommandException) {
1279 CommandException.Error error =
1280 ((CommandException) (ar.exception)).getCommandError();
1281 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1282 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1283 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1284 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1285 }
1286 }
1287 cellScanResult = new CellNetworkScanResult(errorCode, null);
1288 }
1289 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001290 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001291 break;
1292
1293 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1294 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001295 ManualNetworkSelectionArgument selArg =
1296 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001297 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1298 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001299 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1300 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001301 break;
1302
1303 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001304 ar = (AsyncResult) msg.obj;
1305 request = (MainThreadRequest) ar.userObj;
1306 if (ar.exception == null) {
1307 request.result = true;
1308 } else {
1309 request.result = false;
1310 loge("setNetworkSelectionModeManual " + ar.exception);
1311 }
1312 notifyRequester(request);
1313 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001314 break;
1315
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001316 case CMD_GET_MODEM_ACTIVITY_INFO:
1317 request = (MainThreadRequest) msg.obj;
1318 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001319 if (defaultPhone != null) {
1320 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001321 } else {
1322 ResultReceiver result = (ResultReceiver) request.argument;
1323 Bundle bundle = new Bundle();
1324 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001325 new ModemActivityInfo(0, 0, 0,
1326 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001327 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001328 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001329 break;
1330
Hall Liud0f208c2020-10-14 16:54:44 -07001331 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001332 ar = (AsyncResult) msg.obj;
1333 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001334 ResultReceiver result = (ResultReceiver) request.argument;
1335
Hall Liud0f208c2020-10-14 16:54:44 -07001336 ModemActivityInfo ret = null;
1337 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001338 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001339 // Update the last modem activity info and the result of the request.
1340 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1341 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001342 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001343 int[] txTimeMs = info.getTransmitTimeMillis();
1344 int[] lastModemTxTimeMs = mLastModemActivityInfo
1345 .getTransmitTimeMillis();
1346 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1347 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1348 }
Hall Liu49656c02020-10-09 19:00:11 -07001349 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001350 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1351 + mLastModemActivityInfo.getSleepTimeMillis());
1352 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1353 + mLastModemActivityInfo.getIdleTimeMillis());
1354 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1355 mLastModemActivityInfo.setReceiveTimeMillis(
1356 info.getReceiveTimeMillis()
1357 + mLastModemActivityInfo.getReceiveTimeMillis());
1358 }
Hall Liu49656c02020-10-09 19:00:11 -07001359 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001360 mLastModemActivityInfo.getSleepTimeMillis(),
1361 mLastModemActivityInfo.getIdleTimeMillis(),
1362 mLastModemActivityInfo.getTransmitTimeMillis(),
1363 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001364 } else {
1365 if (ar.result == null) {
1366 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001367 error = TelephonyManager.ModemActivityInfoException
1368 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001369 } else if (ar.exception instanceof CommandException) {
1370 loge("queryModemActivityInfo: CommandException: " +
1371 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001372 error = TelephonyManager.ModemActivityInfoException
1373 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001374 } else {
1375 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001376 error = TelephonyManager.ModemActivityInfoException
1377 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001378 }
1379 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001380 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001381 if (ret != null) {
1382 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1383 } else {
1384 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1385 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001386 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001387 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001388 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001389 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001390
Meng Wang1a7c35a2016-05-05 20:56:15 -07001391 case CMD_SET_ALLOWED_CARRIERS:
1392 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001393 CarrierRestrictionRules argument =
1394 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001395 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001396 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001397 break;
1398
1399 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 if (ar.exception == null && ar.result != null) {
1403 request.result = ar.result;
1404 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001405 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1406 if (ar.exception instanceof CommandException) {
1407 loge("setAllowedCarriers: CommandException: " + ar.exception);
1408 CommandException.Error error =
1409 ((CommandException) (ar.exception)).getCommandError();
1410 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1411 request.result =
1412 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1413 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001414 } else {
1415 loge("setAllowedCarriers: Unknown exception");
1416 }
1417 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001418 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001419 break;
1420
1421 case CMD_GET_ALLOWED_CARRIERS:
1422 request = (MainThreadRequest) msg.obj;
1423 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001424 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001425 break;
1426
1427 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1428 ar = (AsyncResult) msg.obj;
1429 request = (MainThreadRequest) ar.userObj;
1430 if (ar.exception == null && ar.result != null) {
1431 request.result = ar.result;
1432 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001433 request.result = new IllegalStateException(
1434 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001435 if (ar.result == null) {
1436 loge("getAllowedCarriers: Empty response");
1437 } else if (ar.exception instanceof CommandException) {
1438 loge("getAllowedCarriers: CommandException: " +
1439 ar.exception);
1440 } else {
1441 loge("getAllowedCarriers: Unknown exception");
1442 }
1443 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001444 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001445 break;
1446
Nathan Haroldb3014052017-01-25 15:57:32 -08001447 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 if (ar.exception == null && ar.result != null) {
1451 request.result = ar.result;
1452 } else {
1453 request.result = new IllegalArgumentException(
1454 "Failed to retrieve Forbidden Plmns");
1455 if (ar.result == null) {
1456 loge("getForbiddenPlmns: Empty response");
1457 } else {
1458 loge("getForbiddenPlmns: Unknown exception");
1459 }
1460 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001461 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001462 break;
1463
1464 case CMD_GET_FORBIDDEN_PLMNS:
1465 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001466 uiccPort = getUiccPortFromRequest(request);
1467 if (uiccPort == null) {
1468 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001469 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001470 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001471 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001472 break;
1473 }
1474 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001475 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001476 if (uiccApp == null) {
1477 loge("getForbiddenPlmns() no app with specified type -- "
1478 + appType);
1479 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001480 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001481 break;
1482 } else {
1483 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1484 + " specified type -- " + appType);
1485 }
1486 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1487 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1488 onCompleted);
1489 break;
1490
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001491 case CMD_SWITCH_SLOTS:
1492 request = (MainThreadRequest) msg.obj;
1493 int[] physicalSlots = (int[]) request.argument;
1494 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1495 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1496 break;
1497
1498 case EVENT_SWITCH_SLOTS_DONE:
1499 ar = (AsyncResult) msg.obj;
1500 request = (MainThreadRequest) ar.userObj;
1501 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001502 notifyRequester(request);
1503 break;
1504 case CMD_GET_NETWORK_SELECTION_MODE:
1505 request = (MainThreadRequest) msg.obj;
1506 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1507 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1508 break;
1509
1510 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1511 ar = (AsyncResult) msg.obj;
1512 request = (MainThreadRequest) ar.userObj;
1513 if (ar.exception != null) {
1514 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1515 } else {
1516 int mode = ((int[]) ar.result)[0];
1517 if (mode == 0) {
1518 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1519 } else {
1520 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1521 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001523 notifyRequester(request);
1524 break;
1525 case CMD_GET_CDMA_ROAMING_MODE:
1526 request = (MainThreadRequest) msg.obj;
1527 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1528 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1529 break;
1530 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1531 ar = (AsyncResult) msg.obj;
1532 request = (MainThreadRequest) ar.userObj;
1533 if (ar.exception != null) {
1534 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1535 } else {
1536 request.result = ((int[]) ar.result)[0];
1537 }
1538 notifyRequester(request);
1539 break;
1540 case CMD_SET_CDMA_ROAMING_MODE:
1541 request = (MainThreadRequest) msg.obj;
1542 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1543 int mode = (int) request.argument;
1544 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1545 break;
1546 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1547 ar = (AsyncResult) msg.obj;
1548 request = (MainThreadRequest) ar.userObj;
1549 request.result = ar.exception == null;
1550 notifyRequester(request);
1551 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001552 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1553 request = (MainThreadRequest) msg.obj;
1554 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1555 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1556 break;
1557 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1558 ar = (AsyncResult) msg.obj;
1559 request = (MainThreadRequest) ar.userObj;
1560 if (ar.exception != null) {
1561 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1562 } else {
1563 request.result = ((int[]) ar.result)[0];
1564 }
1565 notifyRequester(request);
1566 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001567 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1568 request = (MainThreadRequest) msg.obj;
1569 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1570 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001571 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1572 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001573 break;
1574 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1575 ar = (AsyncResult) msg.obj;
1576 request = (MainThreadRequest) ar.userObj;
1577 request.result = ar.exception == null;
1578 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001579 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001580 case CMD_GET_ALL_CELL_INFO:
1581 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001582 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001583 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001584 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001585 case EVENT_GET_ALL_CELL_INFO_DONE:
1586 ar = (AsyncResult) msg.obj;
1587 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001588 // If a timeout occurs, the response will be null
1589 request.result = (ar.exception == null && ar.result != null)
1590 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001591 synchronized (request) {
1592 request.notifyAll();
1593 }
1594 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001595 case CMD_REQUEST_CELL_INFO_UPDATE:
1596 request = (MainThreadRequest) msg.obj;
1597 request.phone.requestCellInfoUpdate(request.workSource,
1598 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1599 break;
1600 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1601 ar = (AsyncResult) msg.obj;
1602 request = (MainThreadRequest) ar.userObj;
1603 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1604 try {
1605 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001606 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001607 cb.onError(
1608 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1609 ar.exception.getClass().getName(),
1610 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001611 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001612 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001613 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001614 } else {
1615 // use the result as returned
1616 cb.onCellInfo((List<CellInfo>) ar.result);
1617 }
1618 } catch (RemoteException re) {
1619 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1620 }
1621 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001622 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001623 request = (MainThreadRequest) msg.obj;
1624 WorkSource ws = (WorkSource) request.argument;
1625 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001626 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001627 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001628 }
1629 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001630 ar = (AsyncResult) msg.obj;
1631 request = (MainThreadRequest) ar.userObj;
1632 if (ar.exception == null) {
1633 request.result = ar.result;
1634 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001635 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001636 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001637 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001638 }
1639
1640 synchronized (request) {
1641 request.notifyAll();
1642 }
1643 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001644 }
chen xu6dac5ab2018-10-26 17:39:23 -07001645 case CMD_MODEM_REBOOT:
1646 request = (MainThreadRequest) msg.obj;
1647 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001648 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001649 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001650 case EVENT_CMD_MODEM_REBOOT_DONE:
1651 handleNullReturnEvent(msg, "rebootModem");
1652 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001653 case CMD_REQUEST_ENABLE_MODEM:
1654 request = (MainThreadRequest) msg.obj;
1655 boolean enable = (boolean) request.argument;
1656 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001657 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001658 PhoneConfigurationManager.getInstance()
1659 .enablePhone(request.phone, enable, onCompleted);
1660 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001661 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001662 ar = (AsyncResult) msg.obj;
1663 request = (MainThreadRequest) ar.userObj;
1664 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001665 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001666 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001667 if ((boolean) request.result) {
1668 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1669 updateModemStateMetrics();
1670 } else {
1671 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1672 + ar.exception);
1673 }
1674 notifyRequester(request);
1675 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001676 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001677 case CMD_GET_MODEM_STATUS:
1678 request = (MainThreadRequest) msg.obj;
1679 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1680 PhoneConfigurationManager.getInstance()
1681 .getPhoneStatusFromModem(request.phone, onCompleted);
1682 break;
1683 case EVENT_GET_MODEM_STATUS_DONE:
1684 ar = (AsyncResult) msg.obj;
1685 request = (MainThreadRequest) ar.userObj;
1686 int id = request.phone.getPhoneId();
1687 if (ar.exception == null && ar.result != null) {
1688 request.result = ar.result;
1689 //update the cache as modem status has changed
1690 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1691 (boolean) request.result);
1692 } else {
1693 // Return true if modem status cannot be retrieved. For most cases,
1694 // modem status is on. And for older version modems, GET_MODEM_STATUS
1695 // and disable modem are not supported. Modem is always on.
1696 // TODO: this should be fixed in R to support a third
1697 // status UNKNOWN b/131631629
1698 request.result = true;
1699 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1700 + ar.exception);
1701 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001702 notifyRequester(request);
1703 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001704 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1705 request = (MainThreadRequest) msg.obj;
1706 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1707 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1708 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1709 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1710 break;
1711 }
1712 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1716 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1717 args.second.accept(ar.exception == null);
1718 notifyRequester(request);
1719 break;
1720 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001721 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1722 request = (MainThreadRequest) msg.obj;
1723 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1724 Phone phone = getPhoneFromRequest(request);
1725 if (phone != null) {
1726 phone.getSystemSelectionChannels(onCompleted);
1727 } else {
1728 loge("getSystemSelectionChannels: No phone object");
1729 request.result = new ArrayList<RadioAccessSpecifier>();
1730 notifyRequester(request);
1731 }
1732 break;
1733 }
1734 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1735 ar = (AsyncResult) msg.obj;
1736 request = (MainThreadRequest) ar.userObj;
1737 if (ar.exception == null && ar.result != null) {
1738 request.result = ar.result;
1739 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001740 request.result = new IllegalStateException(
1741 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001742 if (ar.result == null) {
1743 loge("getSystemSelectionChannels: Empty response");
1744 } else {
1745 loge("getSystemSelectionChannels: Unknown exception");
1746 }
1747 }
1748 notifyRequester(request);
1749 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001750 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1751 ar = (AsyncResult) msg.obj;
1752 request = (MainThreadRequest) ar.userObj;
1753 if (ar.exception == null && ar.result != null) {
1754 request.result = ar.result;
1755 } else {
1756 request.result = -1;
1757 loge("Failed to set Forbidden Plmns");
1758 if (ar.result == null) {
1759 loge("setForbidenPlmns: Empty response");
1760 } else if (ar.exception != null) {
1761 loge("setForbiddenPlmns: Exception: " + ar.exception);
1762 request.result = -1;
1763 } else {
1764 loge("setForbiddenPlmns: Unknown exception");
1765 }
1766 }
1767 notifyRequester(request);
1768 break;
1769 case CMD_SET_FORBIDDEN_PLMNS:
1770 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001771 uiccPort = getUiccPortFromRequest(request);
1772 if (uiccPort == null) {
1773 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001774 request.result = -1;
1775 notifyRequester(request);
1776 break;
1777 }
1778 Pair<Integer, List<String>> setFplmnsArgs =
1779 (Pair<Integer, List<String>>) request.argument;
1780 appType = setFplmnsArgs.first;
1781 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001782 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001783 if (uiccApp == null) {
1784 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1785 request.result = -1;
1786 loge("Failed to get UICC App");
1787 notifyRequester(request);
1788 } else {
1789 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1790 ((SIMRecords) uiccApp.getIccRecords())
1791 .setForbiddenPlmns(onCompleted, fplmns);
1792 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001793 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001794 case CMD_ERASE_MODEM_CONFIG:
1795 request = (MainThreadRequest) msg.obj;
1796 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1797 defaultPhone.eraseModemConfig(onCompleted);
1798 break;
1799 case EVENT_ERASE_MODEM_CONFIG_DONE:
1800 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001801 break;
zoey chene02881a2019-12-30 16:11:23 +08001802
Kai Shif70f46f2021-03-03 13:59:46 -08001803 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1804 request = (MainThreadRequest) msg.obj;
1805 request.result = defaultPhone.eraseDataInSharedPreferences();
1806 notifyRequester(request);
1807 break;
1808
zoey chene02881a2019-12-30 16:11:23 +08001809 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1810 request = (MainThreadRequest) msg.obj;
1811 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1812 Pair<String, String> changed = (Pair<String, String>) request.argument;
1813 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1814 changed.first, changed.second, onCompleted);
1815 break;
1816 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1817 ar = (AsyncResult) msg.obj;
1818 request = (MainThreadRequest) ar.userObj;
1819 if (ar.exception == null) {
1820 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001821 // If the operation is successful, update the PIN storage
1822 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1823 int phoneId = getPhoneFromRequest(request).getPhoneId();
Grace Jia59437e82021-09-21 15:47:32 -07001824 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
1825 pinStorage.storePin(passwords.second, phoneId,
1826 pinStorage.getIccid(phoneId));
zoey chene02881a2019-12-30 16:11:23 +08001827 } else {
1828 request.result = msg.arg1;
1829 }
1830 notifyRequester(request);
1831 break;
1832
Michele Berionne5e411512020-11-13 02:36:59 +00001833 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001834 request = (MainThreadRequest) msg.obj;
1835 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1836 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1837 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1838 enabled.first, enabled.second, onCompleted);
1839 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001840 }
zoey chene02881a2019-12-30 16:11:23 +08001841 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1842 ar = (AsyncResult) msg.obj;
1843 request = (MainThreadRequest) ar.userObj;
1844 if (ar.exception == null) {
1845 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001846 // If the operation is successful, update the PIN storage
1847 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1848 int phoneId = getPhoneFromRequest(request).getPhoneId();
1849 if (enabled.first) {
Grace Jia59437e82021-09-21 15:47:32 -07001850 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
1851 pinStorage.storePin(enabled.second, phoneId,
1852 pinStorage.getIccid(phoneId));
Michele Berionne5e411512020-11-13 02:36:59 +00001853 } else {
1854 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1855 }
zoey chene02881a2019-12-30 16:11:23 +08001856 } else {
1857 request.result = msg.arg1;
1858 }
Michele Berionne5e411512020-11-13 02:36:59 +00001859
1860
zoey chene02881a2019-12-30 16:11:23 +08001861 notifyRequester(request);
1862 break;
1863
Peter Wangdafb9ac2020-01-15 14:13:38 -08001864 case MSG_NOTIFY_USER_ACTIVITY:
1865 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001866 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001867 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1868 getDefaultPhone().getContext().sendBroadcastAsUser(
1869 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1870 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001871
1872 case CMD_SET_DATA_THROTTLING: {
1873 request = (MainThreadRequest) msg.obj;
1874 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1875 DataThrottlingRequest dataThrottlingRequest =
1876 (DataThrottlingRequest) request.argument;
1877 Phone phone = getPhoneFromRequest(request);
1878 if (phone != null) {
1879 phone.setDataThrottling(onCompleted,
1880 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1881 dataThrottlingRequest.getCompletionDurationMillis());
1882 } else {
1883 loge("setDataThrottling: No phone object");
1884 request.result =
1885 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1886 notifyRequester(request);
1887 }
1888
1889 break;
1890 }
1891 case EVENT_SET_DATA_THROTTLING_DONE:
1892 ar = (AsyncResult) msg.obj;
1893 request = (MainThreadRequest) ar.userObj;
1894
1895 if (ar.exception == null) {
1896 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1897 } else if (ar.exception instanceof CommandException) {
1898 loge("setDataThrottling: CommandException: " + ar.exception);
1899 CommandException.Error error =
1900 ((CommandException) (ar.exception)).getCommandError();
1901
1902 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1903 request.result = TelephonyManager
1904 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1905 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1906 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001907 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1908 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001909 } else {
1910 request.result =
1911 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1912 }
1913 } else {
1914 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1915 }
1916 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1917 notifyRequester(request);
1918 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001919
1920 case CMD_SET_SIM_POWER: {
1921 request = (MainThreadRequest) msg.obj;
1922 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1923 request = (MainThreadRequest) msg.obj;
1924 int stateToSet =
1925 ((Pair<Integer, IIntegerConsumer>)
1926 request.argument).first;
1927 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1928 break;
1929 }
1930 case EVENT_SET_SIM_POWER_DONE: {
1931 ar = (AsyncResult) msg.obj;
1932 request = (MainThreadRequest) ar.userObj;
1933 IIntegerConsumer callback =
1934 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1935 if (ar.exception != null) {
1936 loge("setSimPower exception: " + ar.exception);
1937 int errorCode = TelephonyManager.CallForwardingInfoCallback
1938 .RESULT_ERROR_UNKNOWN;
1939 if (ar.exception instanceof CommandException) {
1940 CommandException.Error error =
1941 ((CommandException) (ar.exception)).getCommandError();
1942 if (error == CommandException.Error.SIM_ERR) {
1943 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1944 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1945 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1946 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1947 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1948 } else {
1949 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1950 }
1951 }
1952 try {
1953 callback.accept(errorCode);
1954 } catch (RemoteException e) {
1955 // Ignore if the remote process is no longer available to call back.
1956 Log.w(LOG_TAG, "setSimPower: callback not available.");
1957 }
1958 } else {
1959 try {
1960 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1961 } catch (RemoteException e) {
1962 // Ignore if the remote process is no longer available to call back.
1963 Log.w(LOG_TAG, "setSimPower: callback not available.");
1964 }
1965 }
1966 break;
1967 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001968 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1969 request = (MainThreadRequest) msg.obj;
1970
1971 final Phone phone = getPhoneFromRequest(request);
1972 if (phone == null || phone.getServiceStateTracker() == null) {
1973 request.result = new IllegalStateException("Phone or SST is null");
1974 notifyRequester(request);
1975 break;
1976 }
1977
1978 Pair<Integer, SignalStrengthUpdateRequest> pair =
1979 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1980 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1981 request);
1982 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1983 request.subId, pair.first /*callingUid*/,
1984 pair.second /*request*/, onCompleted);
1985 break;
1986 }
1987 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1988 ar = (AsyncResult) msg.obj;
1989 request = (MainThreadRequest) ar.userObj;
1990 // request.result will be the exception of ar if present, true otherwise.
1991 // Be cautious not to leave result null which will wait() forever
1992 request.result = ar.exception != null ? ar.exception : true;
1993 notifyRequester(request);
1994 break;
1995 }
1996 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1997 request = (MainThreadRequest) msg.obj;
1998
1999 Phone phone = getPhoneFromRequest(request);
2000 if (phone == null || phone.getServiceStateTracker() == null) {
2001 request.result = new IllegalStateException("Phone or SST is null");
2002 notifyRequester(request);
2003 break;
2004 }
2005
2006 Pair<Integer, SignalStrengthUpdateRequest> pair =
2007 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2008 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2009 request);
2010 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
2011 request.subId, pair.first /*callingUid*/,
2012 pair.second /*request*/, onCompleted);
2013 break;
2014 }
2015 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2016 ar = (AsyncResult) msg.obj;
2017 request = (MainThreadRequest) ar.userObj;
2018 request.result = ar.exception != null ? ar.exception : true;
2019 notifyRequester(request);
2020 break;
2021 }
Jordan Liu109698e2020-11-24 14:50:34 -08002022
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002023 case CMD_GET_SLICING_CONFIG: {
2024 request = (MainThreadRequest) msg.obj;
2025 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2026 request.phone.getSlicingConfig(onCompleted);
2027 break;
2028 }
2029 case EVENT_GET_SLICING_CONFIG_DONE: {
2030 ar = (AsyncResult) msg.obj;
2031 request = (MainThreadRequest) ar.userObj;
2032 ResultReceiver result = (ResultReceiver) request.argument;
2033
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002034 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002035 Bundle bundle = new Bundle();
2036 int resultCode = 0;
2037 if (ar.exception != null) {
2038 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2039 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002040 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002041 } else if (ar.result == null) {
2042 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002043 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002044 } else {
2045 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002046 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2047 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002048 }
2049
2050 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002051 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002052 }
2053 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2054 result.send(resultCode, bundle);
2055 notifyRequester(request);
2056 break;
2057 }
2058
Michele Berionne5e411512020-11-13 02:36:59 +00002059 case CMD_PREPARE_UNATTENDED_REBOOT:
2060 request = (MainThreadRequest) msg.obj;
2061 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002062 UiccController.getInstance().getPinStorage()
2063 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002064 notifyRequester(request);
2065 break;
2066
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067 default:
2068 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2069 break;
2070 }
2071 }
Jake Hambye994d462014-02-03 13:10:13 -08002072
Pengquan Menga1bb6272018-09-06 09:59:22 -07002073 private void notifyRequester(MainThreadRequest request) {
2074 synchronized (request) {
2075 request.notifyAll();
2076 }
2077 }
2078
Jake Hambye994d462014-02-03 13:10:13 -08002079 private void handleNullReturnEvent(Message msg, String command) {
2080 AsyncResult ar = (AsyncResult) msg.obj;
2081 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2082 if (ar.exception == null) {
2083 request.result = true;
2084 } else {
2085 request.result = false;
2086 if (ar.exception instanceof CommandException) {
2087 loge(command + ": CommandException: " + ar.exception);
2088 } else {
2089 loge(command + ": Unknown exception");
2090 }
2091 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002092 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 }
2095
2096 /**
2097 * Posts the specified command to be executed on the main thread,
2098 * waits for the request to complete, and returns the result.
2099 * @see #sendRequestAsync
2100 */
2101 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002102 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2103 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002104 }
2105
2106 /**
2107 * Posts the specified command to be executed on the main thread,
2108 * waits for the request to complete, and returns the result.
2109 * @see #sendRequestAsync
2110 */
2111 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2112 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002113 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002114 }
2115
2116 /**
2117 * Posts the specified command to be executed on the main thread,
2118 * waits for the request to complete, and returns the result.
2119 * @see #sendRequestAsync
2120 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002121 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002122 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2123 }
2124
2125 /**
2126 * Posts the specified command to be executed on the main thread,
2127 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2128 * if not timeout or null otherwise.
2129 * @see #sendRequestAsync
2130 */
2131 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2132 long timeoutInMs) {
2133 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002134 }
2135
2136 /**
2137 * Posts the specified command to be executed on the main thread,
2138 * waits for the request to complete, and returns the result.
2139 * @see #sendRequestAsync
2140 */
Nathan Harold92bed182018-10-12 18:16:49 -07002141 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002142 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002143 }
2144
2145 /**
2146 * Posts the specified command to be executed on the main thread,
2147 * waits for the request to complete, and returns the result.
2148 * @see #sendRequestAsync
2149 */
2150 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002151 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2152 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002153 }
2154
2155 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002156 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2157 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2158 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002159 * @see #sendRequestAsync
2160 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002161 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2162 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2164 throw new RuntimeException("This method will deadlock if called from the main thread.");
2165 }
2166
Nathan Harold92bed182018-10-12 18:16:49 -07002167 MainThreadRequest request = null;
2168 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2169 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2170 } else if (phone != null) {
2171 request = new MainThreadRequest(argument, phone, workSource);
2172 } else {
2173 request = new MainThreadRequest(argument, subId, workSource);
2174 }
2175
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176 Message msg = mMainThreadHandler.obtainMessage(command, request);
2177 msg.sendToTarget();
2178
Rambo Wang0f050d82021-02-12 11:43:36 -08002179
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002181 if (timeoutInMs >= 0) {
2182 // Wait for at least timeoutInMs before returning null request result
2183 long now = SystemClock.elapsedRealtime();
2184 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002185 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002186 try {
2187 request.wait(deadline - now);
2188 } catch (InterruptedException e) {
2189 // Do nothing, go back and check if request is completed or timeout
2190 } finally {
2191 now = SystemClock.elapsedRealtime();
2192 }
2193 }
2194 } else {
2195 // Wait for the request to complete
2196 while (request.result == null) {
2197 try {
2198 request.wait();
2199 } catch (InterruptedException e) {
2200 // Do nothing, go back and wait until the request is complete
2201 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 }
2203 }
2204 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002205 if (request.result == null) {
2206 Log.wtf(LOG_TAG,
2207 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 return request.result;
2210 }
2211
2212 /**
2213 * Asynchronous ("fire and forget") version of sendRequest():
2214 * Posts the specified command to be executed on the main thread, and
2215 * returns immediately.
2216 * @see #sendRequest
2217 */
2218 private void sendRequestAsync(int command) {
2219 mMainThreadHandler.sendEmptyMessage(command);
2220 }
2221
2222 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002223 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002224 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002225 */
2226 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002227 sendRequestAsync(command, argument, null, null);
2228 }
2229
2230 /**
2231 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2232 * @see {@link #sendRequest(int,Object)}
2233 */
2234 private void sendRequestAsync(
2235 int command, Object argument, Phone phone, WorkSource workSource) {
2236 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002237 Message msg = mMainThreadHandler.obtainMessage(command, request);
2238 msg.sendToTarget();
2239 }
2240
2241 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 * Initialize the singleton PhoneInterfaceManager instance.
2243 * This is only done once, at startup, from PhoneApp.onCreate().
2244 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002245 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 synchronized (PhoneInterfaceManager.class) {
2247 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002248 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 } else {
2250 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2251 }
2252 return sInstance;
2253 }
2254 }
2255
2256 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002257 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002260 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002261 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002263 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002265 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002266 mTelephonySharedPreferences =
2267 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002268 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002269 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002270 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002271 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002272
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 publish();
2274 }
2275
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002276 private Phone getDefaultPhone() {
2277 Phone thePhone = getPhone(getDefaultSubscription());
2278 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2279 }
2280
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 private void publish() {
2282 if (DBG) log("publish: " + this);
2283
Peter Wangc035ce42020-01-08 21:00:22 -08002284 TelephonyFrameworkInitializer
2285 .getTelephonyServiceManager()
2286 .getTelephonyServiceRegisterer()
2287 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 }
2289
Stuart Scott584921c2015-01-15 17:10:34 -08002290 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002291 if (request.phone != null) {
2292 return request.phone;
2293 } else {
2294 return getPhoneFromSubId(request.subId);
2295 }
2296 }
2297
2298 private Phone getPhoneFromSubId(int subId) {
2299 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2300 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002301 }
2302
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002303 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002304 Phone phone = getPhoneFromRequest(request);
2305 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002306 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002307 }
2308
Wink Saville36469e72014-06-11 15:17:00 -07002309 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002310 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002311 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313
Kai Shif70f46f2021-03-03 13:59:46 -08002314 private void sendEraseModemConfig(@NonNull Phone phone) {
2315 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2316 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2317 }
2318
2319 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2320 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2321 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002322 }
2323
Peter Wang44b186e2020-01-13 23:33:09 -08002324 private boolean isImsAvailableOnDevice() {
2325 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2326 if (pm == null) {
2327 // For some reason package manger is not available.. This will fail internally anyway,
2328 // so do not throw error and allow.
2329 return true;
2330 }
2331 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2332 }
2333
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002335 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002336 }
2337
Wink Savilleb564aae2014-10-23 10:18:09 -07002338 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 if (DBG) log("dial: " + number);
2340 // No permission check needed here: This is just a wrapper around the
2341 // ACTION_DIAL intent, which is available to any app since it puts up
2342 // the UI before it does anything.
2343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344 final long identity = Binder.clearCallingIdentity();
2345 try {
2346 String url = createTelUrl(number);
2347 if (url == null) {
2348 return;
2349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002351 // PENDING: should we just silently fail if phone is offhook or ringing?
2352 PhoneConstants.State state = mCM.getState(subId);
2353 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2354 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2355 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2356 mApp.startActivity(intent);
2357 }
2358 } finally {
2359 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
2361 }
2362
2363 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002364 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002365 }
2366
Wink Savilleb564aae2014-10-23 10:18:09 -07002367 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 if (DBG) log("call: " + number);
2369
2370 // This is just a wrapper around the ACTION_CALL intent, but we still
2371 // need to do a permission check since we're calling startActivity()
2372 // from the context of the phone app.
2373 enforceCallPermission();
2374
Jordan Liu1617b712019-07-10 15:06:26 -07002375 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 != AppOpsManager.MODE_ALLOWED) {
2377 return;
2378 }
2379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 String url = createTelUrl(number);
2383 if (url == null) {
2384 return;
2385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387 boolean isValid = false;
2388 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2389 if (slist != null) {
2390 for (SubscriptionInfo subInfoRecord : slist) {
2391 if (subInfoRecord.getSubscriptionId() == subId) {
2392 isValid = true;
2393 break;
2394 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002395 }
Wink Saville08874612014-08-31 19:19:58 -07002396 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397 if (!isValid) {
2398 return;
2399 }
Wink Saville08874612014-08-31 19:19:58 -07002400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002401 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2402 intent.putExtra(SUBSCRIPTION_KEY, subId);
2403 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2404 mApp.startActivity(intent);
2405 } finally {
2406 Binder.restoreCallingIdentity(identity);
2407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 }
2409
Wink Savilleb564aae2014-10-23 10:18:09 -07002410 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002411 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002412 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2413 }
2414
Wink Savilleb564aae2014-10-23 10:18:09 -07002415 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002416 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002417 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2418 }
2419
Wink Savilleb564aae2014-10-23 10:18:09 -07002420 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002422
2423 final long identity = Binder.clearCallingIdentity();
2424 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002425 Phone phone = getPhone(subId);
2426 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002427 checkSimPin.start();
2428 return checkSimPin.unlockSim(null, pin);
2429 } finally {
2430 Binder.restoreCallingIdentity(identity);
2431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 }
2433
Wink Savilleb564aae2014-10-23 10:18:09 -07002434 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002436
2437 final long identity = Binder.clearCallingIdentity();
2438 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002439 Phone phone = getPhone(subId);
2440 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002441 checkSimPuk.start();
2442 return checkSimPuk.unlockSim(puk, pin);
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
2445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 }
2447
2448 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002449 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 * a synchronous one.
2451 */
2452 private static class UnlockSim extends Thread {
2453
2454 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002455 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456
2457 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002458 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2459 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460
2461 // For replies from SimCard interface
2462 private Handler mHandler;
2463
2464 // For async handler to identify request type
2465 private static final int SUPPLY_PIN_COMPLETE = 100;
2466
Michele Berionne5e411512020-11-13 02:36:59 +00002467 UnlockSim(int phoneId, IccCard simCard) {
2468 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 mSimCard = simCard;
2470 }
2471
2472 @Override
2473 public void run() {
2474 Looper.prepare();
2475 synchronized (UnlockSim.this) {
2476 mHandler = new Handler() {
2477 @Override
2478 public void handleMessage(Message msg) {
2479 AsyncResult ar = (AsyncResult) msg.obj;
2480 switch (msg.what) {
2481 case SUPPLY_PIN_COMPLETE:
2482 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2483 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002484 mRetryCount = msg.arg1;
2485 if (ar.exception != null) {
2486 if (ar.exception instanceof CommandException &&
2487 ((CommandException)(ar.exception)).getCommandError()
2488 == CommandException.Error.PASSWORD_INCORRECT) {
2489 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002490 } //When UiccCardApp dispose,handle message and return exception
2491 else if (ar.exception instanceof CommandException &&
2492 ((CommandException) (ar.exception)).getCommandError()
2493 == CommandException.Error.ABORTED) {
2494 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002495 } else {
2496 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2497 }
2498 } else {
2499 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 mDone = true;
2502 UnlockSim.this.notifyAll();
2503 }
2504 break;
2505 }
2506 }
2507 };
2508 UnlockSim.this.notifyAll();
2509 }
2510 Looper.loop();
2511 }
2512
2513 /*
2514 * Use PIN or PUK to unlock SIM card
2515 *
2516 * If PUK is null, unlock SIM card with PIN
2517 *
2518 * If PUK is not null, unlock SIM card with PUK and set PIN code
2519 */
Wink Saville9de0f752013-10-22 19:04:03 -07002520 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521
2522 while (mHandler == null) {
2523 try {
2524 wait();
2525 } catch (InterruptedException e) {
2526 Thread.currentThread().interrupt();
2527 }
2528 }
2529 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2530
2531 if (puk == null) {
2532 mSimCard.supplyPin(pin, callback);
2533 } else {
2534 mSimCard.supplyPuk(puk, pin, callback);
2535 }
2536
2537 while (!mDone) {
2538 try {
2539 Log.d(LOG_TAG, "wait for done");
2540 wait();
2541 } catch (InterruptedException e) {
2542 // Restore the interrupted status
2543 Thread.currentThread().interrupt();
2544 }
2545 }
2546 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002547 int[] resultArray = new int[2];
2548 resultArray[0] = mResult;
2549 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002550
2551 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Grace Jia59437e82021-09-21 15:47:32 -07002552 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
2553 pinStorage.storePin(pin, mPhoneId, pinStorage.getIccid(mPhoneId));
Michele Berionne5e411512020-11-13 02:36:59 +00002554 }
2555
Wink Saville9de0f752013-10-22 19:04:03 -07002556 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 }
2558 }
2559
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002560 /**
2561 * This method has been removed due to privacy and stability concerns.
2562 */
2563 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002565 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2566 return;
Wink Saville36469e72014-06-11 15:17:00 -07002567 }
2568
Nathan Harold1f889d82020-06-04 17:05:26 -07002569 @Override
2570 public void updateServiceLocationWithPackageName(String callingPackage) {
2571 mApp.getSystemService(AppOpsManager.class)
2572 .checkPackage(Binder.getCallingUid(), callingPackage);
2573
Nathan Haroldf096d982020-11-18 17:18:06 -08002574 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002575 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2576 // Callers targeting S have no business invoking this method.
2577 return;
2578 }
2579
2580 LocationAccessPolicy.LocationPermissionResult locationResult =
2581 LocationAccessPolicy.checkLocationPermission(mApp,
2582 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2583 .setCallingPackage(callingPackage)
2584 .setCallingFeatureId(null)
2585 .setCallingPid(Binder.getCallingPid())
2586 .setCallingUid(Binder.getCallingUid())
2587 .setMethod("updateServiceLocation")
2588 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2589 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2590 .build());
2591 // Apps that lack location permission have no business calling this method;
2592 // however, because no permission was declared in the public API, denials must
2593 // all be "soft".
2594 switch (locationResult) {
2595 case DENIED_HARD: /* fall through */
2596 case DENIED_SOFT:
2597 return;
2598 }
2599
2600 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 final long identity = Binder.clearCallingIdentity();
2602 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002603 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002605 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606 }
2607 } finally {
2608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610 }
2611
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002612 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002613 @Override
2614 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002615 return isRadioOnWithFeature(callingPackage, null);
2616 }
2617
2618
2619 @Override
2620 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2621 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2622 callingFeatureId);
2623 }
2624
2625 @Deprecated
2626 @Override
2627 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2628 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002629 }
2630
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002631 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002632 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2633 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002635 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002636 return false;
2637 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638
2639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 return isRadioOnForSubscriber(subId);
2642 } finally {
2643 Binder.restoreCallingIdentity(identity);
2644 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002645 }
2646
2647 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 final long identity = Binder.clearCallingIdentity();
2649 try {
2650 final Phone phone = getPhone(subId);
2651 if (phone != null) {
2652 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2653 } else {
2654 return false;
2655 }
2656 } finally {
2657 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 }
2660
2661 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002662 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663 }
Wink Saville36469e72014-06-11 15:17:00 -07002664
Wink Savilleb564aae2014-10-23 10:18:09 -07002665 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667
2668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 final Phone phone = getPhone(subId);
2671 if (phone != null) {
2672 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2673 }
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002676 }
Wink Saville36469e72014-06-11 15:17:00 -07002677 }
2678
2679 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002680 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002681 }
2682
Wink Savilleb564aae2014-10-23 10:18:09 -07002683 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685
2686 final long identity = Binder.clearCallingIdentity();
2687 try {
2688 final Phone phone = getPhone(subId);
2689 if (phone == null) {
2690 return false;
2691 }
2692 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2693 toggleRadioOnOffForSubscriber(subId);
2694 }
2695 return true;
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 }
Wink Saville36469e72014-06-11 15:17:00 -07002700
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002701 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002702 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002703 /*
2704 * If any of the Radios are available, it will need to be
2705 * shutdown. So return true if any Radio is available.
2706 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707 final long identity = Binder.clearCallingIdentity();
2708 try {
2709 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2710 Phone phone = PhoneFactory.getPhone(i);
2711 if (phone != null && phone.isRadioAvailable()) return true;
2712 }
2713 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2714 return false;
2715 } finally {
2716 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002717 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002718 }
2719
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002721 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 enforceModifyPermission();
2723
2724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2727 logv("Shutting down Phone " + i);
2728 shutdownRadioUsingPhoneId(i);
2729 }
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002732 }
2733 }
2734
2735 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002736 Phone phone = PhoneFactory.getPhone(phoneId);
2737 if (phone != null && phone.isRadioAvailable()) {
2738 phone.shutdownRadio();
2739 }
2740 }
2741
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002743 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744
2745 final long identity = Binder.clearCallingIdentity();
2746 try {
2747 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2748 if (defaultPhone != null) {
2749 defaultPhone.setRadioPower(turnOn);
2750 return true;
2751 } else {
2752 loge("There's no default phone.");
2753 return false;
2754 }
2755 } finally {
2756 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002757 }
Wink Saville36469e72014-06-11 15:17:00 -07002758 }
2759
Wink Savilleb564aae2014-10-23 10:18:09 -07002760 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 final Phone phone = getPhone(subId);
2766 if (phone != null) {
2767 phone.setRadioPower(turnOn);
2768 return true;
2769 } else {
2770 return false;
2771 }
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 }
2776
Wink Saville36469e72014-06-11 15:17:00 -07002777 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002778 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 public boolean enableDataConnectivity() {
2780 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 int subId = mSubscriptionController.getDefaultDataSubId();
2785 final Phone phone = getPhone(subId);
2786 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002787 phone.getDataEnabledSettings().setDataEnabled(
2788 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 return true;
2790 } else {
2791 return false;
2792 }
2793 } finally {
2794 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 }
2797
Wink Saville36469e72014-06-11 15:17:00 -07002798 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002799 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002800 public boolean disableDataConnectivity() {
2801 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 int subId = mSubscriptionController.getDefaultDataSubId();
2806 final Phone phone = getPhone(subId);
2807 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002808 phone.getDataEnabledSettings().setDataEnabled(
2809 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810 return true;
2811 } else {
2812 return false;
2813 }
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002816 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 }
2818
Sanket Padawe356d7632015-06-22 14:03:32 -07002819 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002820 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 final Phone phone = getPhone(subId);
2824 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002825 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826 } else {
2827 return false;
2828 }
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 }
2833
2834 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002835 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002836 }
2837
pkanwarae03a6b2016-11-06 20:37:09 -08002838 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002839 enforceCallPermission();
2840
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2844 return;
2845 }
2846 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2847 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2848 } finally {
2849 Binder.restoreCallingIdentity(identity);
2850 }
pkanwar32d516d2016-10-14 19:37:38 -07002851 };
2852
Wink Savilleb564aae2014-10-23 10:18:09 -07002853 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002854 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002855
2856 final long identity = Binder.clearCallingIdentity();
2857 try {
2858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2859 return false;
2860 }
2861 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002865 }
2866
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002867 /**
2868 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2869 * tag on getCallState Binder call.
2870 */
2871 @Deprecated
2872 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002874 if (CompatChanges.isChangeEnabled(
2875 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2876 Binder.getCallingUid())) {
2877 // Do not allow this API to be called on API version 31+, it should only be
2878 // called on old apps using this Binder call directly.
2879 throw new SecurityException("This method can only be used for applications "
2880 + "targeting API version 30 or less.");
2881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882 final long identity = Binder.clearCallingIdentity();
2883 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002884 Phone phone = getPhone(getDefaultSubscription());
2885 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2886 PhoneConstantConversions.convertCallState(phone.getState());
2887 } finally {
2888 Binder.restoreCallingIdentity(identity);
2889 }
2890 }
2891
2892 @Override
2893 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2894 if (CompatChanges.isChangeEnabled(
2895 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2896 Binder.getCallingUid())) {
2897 // Check READ_PHONE_STATE for API version 31+
2898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2899 featureId, "getCallStateForSubscription")) {
2900 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2901 + "targeting API level 31+.");
2902 }
2903 }
2904 final long identity = Binder.clearCallingIdentity();
2905 try {
2906 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2908 PhoneConstantConversions.convertCallState(phone.getState());
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
2911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 }
2913
Sanket Padawe356d7632015-06-22 14:03:32 -07002914 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002915 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002916 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2917 }
2918
2919 @Override
2920 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 final long identity = Binder.clearCallingIdentity();
2922 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002923 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 if (phone != null) {
2925 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2926 } else {
2927 return PhoneConstantConversions.convertDataState(
2928 PhoneConstants.DataState.DISCONNECTED);
2929 }
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 }
2934
Sanket Padawe356d7632015-06-22 14:03:32 -07002935 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002936 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002937 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2938 }
2939
2940 @Override
2941 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942 final long identity = Binder.clearCallingIdentity();
2943 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002944 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 if (phone != null) {
2946 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2947 } else {
2948 return TelephonyManager.DATA_ACTIVITY_NONE;
2949 }
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 }
2954
2955 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002956 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002957 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002958 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002959
2960 LocationAccessPolicy.LocationPermissionResult locationResult =
2961 LocationAccessPolicy.checkLocationPermission(mApp,
2962 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2963 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002964 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002965 .setCallingPid(Binder.getCallingPid())
2966 .setCallingUid(Binder.getCallingUid())
2967 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002968 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002969 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2970 .build());
2971 switch (locationResult) {
2972 case DENIED_HARD:
2973 throw new SecurityException("Not allowed to access cell location");
2974 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002975 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2976 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002977 }
2978
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002979 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002983 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002984 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
Svetoslav64fad262015-04-14 14:35:21 -07002988 }
2989
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002990 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002991 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002992 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2993 // registered cell info, so return a NULL country instead.
2994 final long identity = Binder.clearCallingIdentity();
2995 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002996 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2997 // Get default phone in this case.
2998 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2999 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003000 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003002 if (phone == null) return "";
3003 ServiceStateTracker sst = phone.getServiceStateTracker();
3004 if (sst == null) return "";
3005 LocaleTracker lt = sst.getLocaleTracker();
3006 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003007 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003011 }
3012
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003013 /**
3014 * This method was removed due to potential issues caused by performing partial
3015 * updates of service state, and lack of a credible use case.
3016 *
3017 * This has the ability to break the telephony implementation by disabling notification of
3018 * changes in device connectivity. DO NOT USE THIS!
3019 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003020 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003021 public void enableLocationUpdates() {
3022 mApp.enforceCallingOrSelfPermission(
3023 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003024 }
3025
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003026 /**
3027 * This method was removed due to potential issues caused by performing partial
3028 * updates of service state, and lack of a credible use case.
3029 *
3030 * This has the ability to break the telephony implementation by disabling notification of
3031 * changes in device connectivity. DO NOT USE THIS!
3032 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003033 @Override
3034 public void disableLocationUpdates() {
3035 mApp.enforceCallingOrSelfPermission(
3036 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003037 }
3038
3039 @Override
3040 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003041 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3042 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003043 try {
3044 mApp.getSystemService(AppOpsManager.class)
3045 .checkPackage(Binder.getCallingUid(), callingPackage);
3046 } catch (SecurityException e) {
3047 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3048 throw e;
3049 }
3050
Nathan Haroldf096d982020-11-18 17:18:06 -08003051 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003052 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3053 throw new SecurityException(
3054 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3055 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003056
Jordan Liu1617b712019-07-10 15:06:26 -07003057 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003058 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3059 return null;
3060 }
Svetoslav64fad262015-04-14 14:35:21 -07003061
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003062 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003063
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003064 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003065 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003066
Nathan Haroldf180aac2018-06-01 18:43:55 -07003067 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3068 for (CellInfo ci : info) {
3069 if (ci instanceof CellInfoGsm) {
3070 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3071 } else if (ci instanceof CellInfoWcdma) {
3072 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3073 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003075 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003076 }
3077
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003078 private List<CellInfo> getCachedCellInfo() {
3079 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3080 for (Phone phone : PhoneFactory.getPhones()) {
3081 List<CellInfo> info = phone.getAllCellInfo();
3082 if (info != null) cellInfos.addAll(info);
3083 }
3084 return cellInfos;
3085 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003086
3087 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003088 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003089 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003090 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003091
3092 LocationAccessPolicy.LocationPermissionResult locationResult =
3093 LocationAccessPolicy.checkLocationPermission(mApp,
3094 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3095 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003096 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003097 .setCallingPid(Binder.getCallingPid())
3098 .setCallingUid(Binder.getCallingUid())
3099 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003100 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003101 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3102 .build());
3103 switch (locationResult) {
3104 case DENIED_HARD:
3105 throw new SecurityException("Not allowed to access cell info");
3106 case DENIED_SOFT:
3107 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 }
3109
Nathan Haroldf096d982020-11-18 17:18:06 -08003110 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003111 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3112 return getCachedCellInfo();
3113 }
3114
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003115 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003116 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117 final long identity = Binder.clearCallingIdentity();
3118 try {
3119 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3120 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003121 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003122 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123 if (info != null) cellInfos.addAll(info);
3124 }
3125 return cellInfos;
3126 } finally {
3127 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003128 }
3129 }
3130
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003131 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003132 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3133 String callingFeatureId) {
3134 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3135 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003136 }
3137
3138 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003139 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3140 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003141 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003142 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003143 }
3144
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003145 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3146 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003147 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003148 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003149
3150 LocationAccessPolicy.LocationPermissionResult locationResult =
3151 LocationAccessPolicy.checkLocationPermission(mApp,
3152 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3153 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003154 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003155 .setCallingPid(Binder.getCallingPid())
3156 .setCallingUid(Binder.getCallingUid())
3157 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003158 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3159 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003160 .build());
3161 switch (locationResult) {
3162 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003163 if (TelephonyPermissions
3164 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003165 // Safetynet logging for b/154934934
3166 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3167 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003168 throw new SecurityException("Not allowed to access cell info");
3169 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003170 if (TelephonyPermissions
3171 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003172 // Safetynet logging for b/154934934
3173 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3174 }
Nathan Harold5320c422019-05-09 10:26:08 -07003175 try {
3176 cb.onCellInfo(new ArrayList<CellInfo>());
3177 } catch (RemoteException re) {
3178 // Drop without consequences
3179 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003180 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003181 }
3182
Nathan Harolda939a962019-05-09 10:13:47 -07003183
3184 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003185 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3186
3187 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3188 }
3189
3190 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003192 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003193 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194
3195 final long identity = Binder.clearCallingIdentity();
3196 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003197 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003201 }
3202
Shishir Agrawala9f32182016-04-12 12:00:16 -07003203 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003204 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003205 Phone phone = PhoneFactory.getPhone(slotIndex);
3206 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003207 return null;
3208 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003209 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003210 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003211 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003212 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003213 return null;
3214 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215
3216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 return phone.getImei();
3219 } finally {
3220 Binder.restoreCallingIdentity(identity);
3221 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003222 }
3223
3224 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003225 public String getTypeAllocationCodeForSlot(int slotIndex) {
3226 Phone phone = PhoneFactory.getPhone(slotIndex);
3227 String tac = null;
3228 if (phone != null) {
3229 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003230 try {
3231 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3232 } catch (IndexOutOfBoundsException e) {
3233 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3234 return null;
3235 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003236 }
3237 return tac;
3238 }
3239
3240 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003241 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003242 try {
3243 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3244 } catch (SecurityException se) {
3245 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3246 throw new SecurityException("Package " + callingPackage + " does not belong to "
3247 + Binder.getCallingUid());
3248 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003249 Phone phone = PhoneFactory.getPhone(slotIndex);
3250 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003251 return null;
3252 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003253
Jeff Davidson913390f2018-02-23 17:11:49 -08003254 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003255 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003256 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003257 return null;
3258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003259
3260 final long identity = Binder.clearCallingIdentity();
3261 try {
3262 return phone.getMeid();
3263 } finally {
3264 Binder.restoreCallingIdentity(identity);
3265 }
Jack Yu2af8d712017-03-15 17:14:14 -07003266 }
3267
3268 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003269 public String getManufacturerCodeForSlot(int slotIndex) {
3270 Phone phone = PhoneFactory.getPhone(slotIndex);
3271 String manufacturerCode = null;
3272 if (phone != null) {
3273 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003274 try {
3275 manufacturerCode =
3276 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3277 } catch (IndexOutOfBoundsException e) {
3278 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3279 return null;
3280 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003281 }
3282 return manufacturerCode;
3283 }
3284
3285 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003286 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3287 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003288 Phone phone = PhoneFactory.getPhone(slotIndex);
3289 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003290 return null;
3291 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003292 int subId = phone.getSubId();
3293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003294 mApp, subId, callingPackage, callingFeatureId,
3295 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003296 return null;
3297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003298
3299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 return phone.getDeviceSvn();
3302 } finally {
3303 Binder.restoreCallingIdentity(identity);
3304 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003305 }
3306
fionaxu43304da2017-11-27 22:51:16 -08003307 @Override
3308 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 final Phone phone = getPhone(subId);
3312 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
fionaxu43304da2017-11-27 22:51:16 -08003316 }
3317
3318 @Override
3319 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003320 final long identity = Binder.clearCallingIdentity();
3321 try {
3322 final Phone phone = getPhone(subId);
3323 return phone == null ? null : phone.getCarrierName();
3324 } finally {
3325 Binder.restoreCallingIdentity(identity);
3326 }
fionaxu43304da2017-11-27 22:51:16 -08003327 }
3328
calvinpanffe225e2018-11-01 19:43:06 +08003329 @Override
chen xu0026ca62019-03-06 15:28:50 -08003330 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003331 final long identity = Binder.clearCallingIdentity();
3332 try {
3333 final Phone phone = getPhone(subId);
3334 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003335 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003336 } finally {
3337 Binder.restoreCallingIdentity(identity);
3338 }
3339 }
3340
3341 @Override
chen xu0026ca62019-03-06 15:28:50 -08003342 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003346 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
3350 }
3351
chen xu651eec72018-11-11 19:03:44 -08003352 @Override
chen xu864e11c2018-12-06 22:10:03 -08003353 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3354 if (!isSubscriptionMccMnc) {
3355 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3356 }
chen xu651eec72018-11-11 19:03:44 -08003357 final Phone phone = PhoneFactory.getPhone(slotIndex);
3358 if (phone == null) {
3359 return TelephonyManager.UNKNOWN_CARRIER_ID;
3360 }
3361 final long identity = Binder.clearCallingIdentity();
3362 try {
3363 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3364 } finally {
3365 Binder.restoreCallingIdentity(identity);
3366 }
3367 }
3368
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003369 //
3370 // Internal helper methods.
3371 //
3372
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003373 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003374 * Make sure the caller is the calling package itself
3375 *
3376 * @throws SecurityException if the caller is not the calling package
3377 */
3378 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3379 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003380 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3381 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003382 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003383 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003384 } catch (PackageManager.NameNotFoundException e) {
3385 // packageUid is -1
3386 }
3387 if (packageUid != callingUid) {
3388 throw new SecurityException(message + ": Package " + callingPackage
3389 + " does not belong to " + callingUid);
3390 }
3391 }
3392
3393 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003394 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3395 *
3396 * @throws SecurityException if the caller does not have the required permission
3397 */
3398 private void enforceModifyPermission() {
3399 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3400 }
3401
Shuo Qiancd19c462020-01-16 20:51:11 -08003402 /**
3403 * Make sure the caller is system.
3404 *
3405 * @throws SecurityException if the caller is not system.
3406 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003407 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003408 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3409 throw new SecurityException("Caller must be system");
3410 }
3411 }
3412
Shuo Qian3b6ee772019-11-13 17:43:31 -08003413 private void enforceActiveEmergencySessionPermission() {
3414 mApp.enforceCallingOrSelfPermission(
3415 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3416 }
3417
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003418 /**
3419 * Make sure the caller has the CALL_PHONE permission.
3420 *
3421 * @throws SecurityException if the caller does not have the required permission
3422 */
3423 private void enforceCallPermission() {
3424 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3425 }
3426
paulhu5a773602019-08-23 19:17:33 +08003427 private void enforceSettingsPermission() {
3428 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003429 }
3430
Michele Berionne5e411512020-11-13 02:36:59 +00003431 private void enforceRebootPermission() {
3432 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3433 }
3434
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003435 private String createTelUrl(String number) {
3436 if (TextUtils.isEmpty(number)) {
3437 return null;
3438 }
3439
Jake Hambye994d462014-02-03 13:10:13 -08003440 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003441 }
3442
Ihab Awadf9e92732013-12-05 18:02:52 -08003443 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003444 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3445 }
3446
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003447 private static void logv(String msg) {
3448 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3449 }
3450
Ihab Awadf9e92732013-12-05 18:02:52 -08003451 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3453 }
3454
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003455 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003456 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003457 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003458 }
3459
Sanket Padawe356d7632015-06-22 14:03:32 -07003460 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003461 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003462 final long identity = Binder.clearCallingIdentity();
3463 try {
3464 final Phone phone = PhoneFactory.getPhone(slotIndex);
3465 if (phone == null) {
3466 return PhoneConstants.PHONE_TYPE_NONE;
3467 } else {
3468 return phone.getPhoneType();
3469 }
3470 } finally {
3471 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003473 }
3474
3475 /**
3476 * Returns the CDMA ERI icon index to display
3477 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003478 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003479 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3480 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3481 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003482 }
3483
Sanket Padawe356d7632015-06-22 14:03:32 -07003484 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003485 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3486 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003488 mApp, subId, callingPackage, callingFeatureId,
3489 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003490 return -1;
3491 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003492
3493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 final Phone phone = getPhone(subId);
3496 if (phone != null) {
3497 return phone.getCdmaEriIconIndex();
3498 } else {
3499 return -1;
3500 }
3501 } finally {
3502 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003504 }
3505
3506 /**
3507 * Returns the CDMA ERI icon mode,
3508 * 0 - ON
3509 * 1 - FLASHING
3510 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003511 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003512 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3513 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3514 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003515 }
3516
Sanket Padawe356d7632015-06-22 14:03:32 -07003517 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003518 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3519 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003520 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003521 mApp, subId, callingPackage, callingFeatureId,
3522 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003523 return -1;
3524 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003525
3526 final long identity = Binder.clearCallingIdentity();
3527 try {
3528 final Phone phone = getPhone(subId);
3529 if (phone != null) {
3530 return phone.getCdmaEriIconMode();
3531 } else {
3532 return -1;
3533 }
3534 } finally {
3535 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003536 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003537 }
3538
3539 /**
3540 * Returns the CDMA ERI text,
3541 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003542 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003543 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3544 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3545 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003546 }
3547
Sanket Padawe356d7632015-06-22 14:03:32 -07003548 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003549 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3550 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003551 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003552 mApp, subId, callingPackage, callingFeatureId,
3553 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003554 return null;
3555 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003556
3557 final long identity = Binder.clearCallingIdentity();
3558 try {
3559 final Phone phone = getPhone(subId);
3560 if (phone != null) {
3561 return phone.getCdmaEriText();
3562 } else {
3563 return null;
3564 }
3565 } finally {
3566 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003568 }
3569
3570 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003571 * Returns the CDMA MDN.
3572 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003573 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003574 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3576 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003577
3578 final long identity = Binder.clearCallingIdentity();
3579 try {
3580 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003581 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003582 return phone.getLine1Number();
3583 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003584 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003585 return null;
3586 }
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003589 }
3590 }
3591
3592 /**
3593 * Returns the CDMA MIN.
3594 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003595 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003596 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3598 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003599
3600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 final Phone phone = getPhone(subId);
3603 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3604 return phone.getCdmaMin();
3605 } else {
3606 return null;
3607 }
3608 } finally {
3609 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003610 }
3611 }
3612
Hall Liud892bec2018-11-30 14:51:45 -08003613 @Override
3614 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3615 INumberVerificationCallback callback, String callingPackage) {
3616 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3617 != PERMISSION_GRANTED) {
3618 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3619 }
3620 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3621
3622 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3623 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003624 throw new SecurityException("Calling package must be configured in the device config: "
3625 + "calling package: " + callingPackage
3626 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003627 }
3628
3629 if (range == null) {
3630 throw new NullPointerException("Range must be non-null");
3631 }
3632
3633 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003634 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003635
3636 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3637 }
3638
Junda Liuca05d5d2014-08-14 22:36:34 -07003639 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003640 * Returns true if CDMA provisioning needs to run.
3641 */
3642 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643 final long identity = Binder.clearCallingIdentity();
3644 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003645 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646 } finally {
3647 Binder.restoreCallingIdentity(identity);
3648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003649 }
3650
3651 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003652 * Sets the voice mail number of a given subId.
3653 */
3654 @Override
3655 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003656 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3657 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003658
3659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3662 new Pair<String, String>(alphaTag, number), new Integer(subId));
3663 return success;
3664 } finally {
3665 Binder.restoreCallingIdentity(identity);
3666 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003667 }
3668
Ta-wei Yen87c49842016-05-13 21:19:52 -07003669 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003670 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3671 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003672 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3673 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003674 if (!TextUtils.equals(callingPackage, systemDialer)) {
3675 throw new SecurityException("caller must be system dialer");
3676 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003677
3678 final long identity = Binder.clearCallingIdentity();
3679 try {
3680 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3681 if (phoneAccountHandle == null) {
3682 return null;
3683 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003684 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003685 } finally {
3686 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003687 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003688 }
3689
3690 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003691 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3692 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003693 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003694 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003695 mApp, subId, callingPackage, callingFeatureId,
3696 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003697 return null;
3698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003699
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003700 final long identity = Binder.clearCallingIdentity();
3701 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003702 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003703 } finally {
3704 Binder.restoreCallingIdentity(identity);
3705 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003706 }
3707
3708 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003709 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3710 VisualVoicemailSmsFilterSettings settings) {
3711 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003712
3713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003716 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003717 } finally {
3718 Binder.restoreCallingIdentity(identity);
3719 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003720 }
3721
3722 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003723 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3724 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003725
3726 final long identity = Binder.clearCallingIdentity();
3727 try {
3728 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003729 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003730 } finally {
3731 Binder.restoreCallingIdentity(identity);
3732 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003733 }
3734
3735 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003736 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3737 String callingPackage, int subId) {
3738 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003739
3740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003743 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003744 } finally {
3745 Binder.restoreCallingIdentity(identity);
3746 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003747 }
3748
3749 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003750 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003751 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003752
3753 final long identity = Binder.clearCallingIdentity();
3754 try {
3755 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003756 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003757 } finally {
3758 Binder.restoreCallingIdentity(identity);
3759 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003760 }
3761
3762 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003763 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3764 String callingAttributionTag, int subId, String number, int port, String text,
3765 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003766 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003767 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003768 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003769 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003770 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3771 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003772 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003773
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003774 /**
fionaxu0152e512016-11-14 13:36:14 -08003775 * Sets the voice activation state of a given subId.
3776 */
3777 @Override
3778 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3780 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003781
3782 final long identity = Binder.clearCallingIdentity();
3783 try {
3784 final Phone phone = getPhone(subId);
3785 if (phone != null) {
3786 phone.setVoiceActivationState(activationState);
3787 } else {
3788 loge("setVoiceActivationState fails with invalid subId: " + subId);
3789 }
3790 } finally {
3791 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003792 }
3793 }
3794
3795 /**
3796 * Sets the data activation state of a given subId.
3797 */
3798 @Override
3799 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3801 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003802
3803 final long identity = Binder.clearCallingIdentity();
3804 try {
3805 final Phone phone = getPhone(subId);
3806 if (phone != null) {
3807 phone.setDataActivationState(activationState);
3808 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003809 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810 }
3811 } finally {
3812 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003813 }
3814 }
3815
3816 /**
3817 * Returns the voice activation state of a given subId.
3818 */
3819 @Override
3820 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003821 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003822
fionaxu0152e512016-11-14 13:36:14 -08003823 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003824 final long identity = Binder.clearCallingIdentity();
3825 try {
3826 if (phone != null) {
3827 return phone.getVoiceActivationState();
3828 } else {
3829 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3830 }
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003833 }
3834 }
3835
3836 /**
3837 * Returns the data activation state of a given subId.
3838 */
3839 @Override
3840 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003841 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003842
fionaxu0152e512016-11-14 13:36:14 -08003843 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003844 final long identity = Binder.clearCallingIdentity();
3845 try {
3846 if (phone != null) {
3847 return phone.getDataActivationState();
3848 } else {
3849 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3850 }
3851 } finally {
3852 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003853 }
3854 }
3855
3856 /**
Wink Saville36469e72014-06-11 15:17:00 -07003857 * Returns the unread count of voicemails for a subId
3858 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003859 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003860 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3861 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003862 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003863 mApp, subId, callingPackage, callingFeatureId,
3864 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003865 return 0;
3866 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003867 final long identity = Binder.clearCallingIdentity();
3868 try {
3869 final Phone phone = getPhone(subId);
3870 if (phone != null) {
3871 return phone.getVoiceMessageCount();
3872 } else {
3873 return 0;
3874 }
3875 } finally {
3876 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003877 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003878 }
3879
3880 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003881 * returns true, if the device is in a state where both voice and data
3882 * are supported simultaneously. This can change based on location or network condition.
3883 */
3884 @Override
3885 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886 final long identity = Binder.clearCallingIdentity();
3887 try {
3888 final Phone phone = getPhone(subId);
3889 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3890 } finally {
3891 Binder.restoreCallingIdentity(identity);
3892 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003893 }
3894
3895 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003896 * Send the dialer code if called from the current default dialer or the caller has
3897 * carrier privilege.
3898 * @param inputCode The dialer code to send
3899 */
3900 @Override
3901 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003902 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003903 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003904 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3905 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003906 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003907 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003908 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910
3911 final long identity = Binder.clearCallingIdentity();
3912 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003913 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003914 } finally {
3915 Binder.restoreCallingIdentity(identity);
3916 }
fionaxu235cc5e2017-03-06 22:25:57 -08003917 }
3918
Pengquan Menga1bb6272018-09-06 09:59:22 -07003919 @Override
3920 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003921 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003922 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003923 mApp, subId, "getNetworkSelectionMode");
3924 final long identity = Binder.clearCallingIdentity();
3925 try {
3926 if (!isActiveSubscription(subId)) {
3927 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3928 }
3929 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3930 } finally {
3931 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003932 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003933 }
3934
Brad Ebinger35c841c2018-10-01 10:40:55 -07003935 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003936 public boolean isInEmergencySmsMode() {
3937 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3938 final long identity = Binder.clearCallingIdentity();
3939 try {
3940 for (Phone phone : PhoneFactory.getPhones()) {
3941 if (phone.isInEmergencySmsMode()) {
3942 return true;
3943 }
3944 }
3945 } finally {
3946 Binder.restoreCallingIdentity(identity);
3947 }
3948 return false;
3949 }
3950
shilu366312e2019-12-17 09:28:10 -08003951 /**
3952 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3953 * @param subId The subscription to use to check the configuration.
3954 * @param c The callback that will be used to send the result.
3955 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003956 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003957 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3958 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003959 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003960 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003961
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003962 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3963 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3964 "IMS not available on device.");
3965 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003966 final long token = Binder.clearCallingIdentity();
3967 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003968 int slotId = getSlotIndexOrException(subId);
3969 verifyImsMmTelConfiguredOrThrow(slotId);
3970 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003971 } catch (ImsException e) {
3972 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 } finally {
3974 Binder.restoreCallingIdentity(token);
3975 }
3976 }
3977
shilu366312e2019-12-17 09:28:10 -08003978 /**
3979 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3980 * @param subId The subscription to use to check the configuration.
3981 * @param c The callback that will be used to send the result.
3982 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003983 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003984 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003985 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003986 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003987 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3988 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3989 }
Meng Wangafbc5852019-09-19 17:37:13 -07003990 final long token = Binder.clearCallingIdentity();
3991 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003992 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3993 .removeRegistrationCallbackForSubscription(c, subId);
3994 } catch (ImsException e) {
3995 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3996 + "is inactive, ignoring unregister.");
3997 // If the subscription is no longer active, just return, since the callback
3998 // will already have been removed internally.
3999 } finally {
4000 Binder.restoreCallingIdentity(token);
4001 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004002 }
4003
Brad Ebingera34a6c22019-10-22 17:36:18 -07004004 /**
4005 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4006 */
4007 @Override
4008 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4009 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4010 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4011 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4012 "IMS not available on device.");
4013 }
4014 final long token = Binder.clearCallingIdentity();
4015 try {
4016 Phone phone = getPhone(subId);
4017 if (phone == null) {
4018 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4019 + subId + "'");
4020 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4021 }
4022 phone.getImsRegistrationState(regState -> {
4023 try {
4024 consumer.accept((regState == null)
4025 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4026 } catch (RemoteException e) {
4027 // Ignore if the remote process is no longer available to call back.
4028 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4029 }
4030 });
4031 } finally {
4032 Binder.restoreCallingIdentity(token);
4033 }
4034 }
4035
4036 /**
4037 * Get the transport type for the IMS service registration state.
4038 */
4039 @Override
4040 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004041 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004042 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004043 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4044 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4045 "IMS not available on device.");
4046 }
4047 final long token = Binder.clearCallingIdentity();
4048 try {
4049 Phone phone = getPhone(subId);
4050 if (phone == null) {
4051 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4052 + subId + "'");
4053 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4054 }
4055 phone.getImsRegistrationTech(regTech -> {
4056 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4057 int regTechConverted = (regTech == null)
4058 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4059 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4060 regTechConverted);
4061 try {
4062 consumer.accept(regTechConverted);
4063 } catch (RemoteException e) {
4064 // Ignore if the remote process is no longer available to call back.
4065 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4066 }
4067 });
4068 } finally {
4069 Binder.restoreCallingIdentity(token);
4070 }
4071 }
4072
shilu366312e2019-12-17 09:28:10 -08004073 /**
4074 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4075 * @param subId The subscription to use to check the configuration.
4076 * @param c The callback that will be used to send the result.
4077 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004078 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004079 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4080 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004081 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004082 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004083 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4084 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4085 "IMS not available on device.");
4086 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004087 final long token = Binder.clearCallingIdentity();
4088 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004089 int slotId = getSlotIndexOrException(subId);
4090 verifyImsMmTelConfiguredOrThrow(slotId);
4091 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004092 } catch (ImsException e) {
4093 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 } finally {
4095 Binder.restoreCallingIdentity(token);
4096 }
4097 }
4098
shilu366312e2019-12-17 09:28:10 -08004099 /**
4100 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4101 * @param subId The subscription to use to check the configuration.
4102 * @param c The callback that will be used to send the result.
4103 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004104 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004105 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004106 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004107 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004108 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4109 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4110 }
Meng Wangafbc5852019-09-19 17:37:13 -07004111
4112 final long token = Binder.clearCallingIdentity();
4113 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004114 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004115 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004116 } catch (ImsException e) {
4117 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4118 + "is inactive, ignoring unregister.");
4119 // If the subscription is no longer active, just return, since the callback
4120 // will already have been removed internally.
4121 } finally {
4122 Binder.restoreCallingIdentity(token);
4123 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004124 }
4125
4126 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004127 public boolean isCapable(int subId, int capability, int regTech) {
4128 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004129 final long token = Binder.clearCallingIdentity();
4130 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004131 int slotId = getSlotIndexOrException(subId);
4132 verifyImsMmTelConfiguredOrThrow(slotId);
4133 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004134 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004135 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4136 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004137 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004138 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4139 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004140 } finally {
4141 Binder.restoreCallingIdentity(token);
4142 }
4143 }
4144
4145 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004146 public boolean isAvailable(int subId, int capability, int regTech) {
4147 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004148 final long token = Binder.clearCallingIdentity();
4149 try {
4150 Phone phone = getPhone(subId);
4151 if (phone == null) return false;
4152 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004153 } catch (com.android.ims.ImsException e) {
4154 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4155 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004156 } finally {
4157 Binder.restoreCallingIdentity(token);
4158 }
4159 }
4160
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004161 /**
4162 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4163 * subscription.
4164 * @param subId The subscription to use to check the configuration.
4165 * @param callback The callback that will be used to send the result.
4166 * @param capability The MmTelFeature capability that will be used to send the result.
4167 * @param transportType The transport type of the MmTelFeature capability.
4168 */
4169 @Override
4170 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4171 int transportType) {
4172 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4173 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4174 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4175 "IMS not available on device.");
4176 }
4177 final long token = Binder.clearCallingIdentity();
4178 try {
4179 int slotId = getSlotIndex(subId);
4180 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4181 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4182 + subId + "'");
4183 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4184 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004185 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004186 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4187 transportType, aBoolean -> {
4188 try {
4189 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4190 } catch (RemoteException e) {
4191 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4192 + "running. Ignore");
4193 }
4194 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004195 } catch (ImsException e) {
4196 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004197 } finally {
4198 Binder.restoreCallingIdentity(token);
4199 }
4200 }
4201
shilu366312e2019-12-17 09:28:10 -08004202 /**
4203 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4204 * @param subId The subscription to use to check the configuration.
4205 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004206 @Override
4207 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004208 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004209 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004210
Brad Ebinger35c841c2018-10-01 10:40:55 -07004211 final long token = Binder.clearCallingIdentity();
4212 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004213 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004214 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004215 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004216 } catch (ImsException e) {
4217 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004218 } finally {
4219 Binder.restoreCallingIdentity(token);
4220 }
4221 }
4222
4223 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004224 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004226 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004227 final long identity = Binder.clearCallingIdentity();
4228 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004229 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004230 // This setting doesn't require an active ImsService connection, so do not verify. The
4231 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004232 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004233 } catch (ImsException e) {
4234 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004235 } finally {
4236 Binder.restoreCallingIdentity(identity);
4237 }
4238 }
4239
shilu366312e2019-12-17 09:28:10 -08004240 /**
4241 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4242 * @param subId The subscription to use to check the configuration.
4243 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004245 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004246 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004247 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004248 final long identity = Binder.clearCallingIdentity();
4249 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004250 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004251 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004252 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004253 } catch (ImsException e) {
4254 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004255 } finally {
4256 Binder.restoreCallingIdentity(identity);
4257 }
4258 }
4259
4260 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004261 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004262 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004263 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 final long identity = Binder.clearCallingIdentity();
4265 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004266 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004267 // This setting doesn't require an active ImsService connection, so do not verify. The
4268 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004269 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004270 } catch (ImsException e) {
4271 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004272 } finally {
4273 Binder.restoreCallingIdentity(identity);
4274 }
4275 }
4276
shilu366312e2019-12-17 09:28:10 -08004277 /**
4278 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4279 * @param subId The subscription to use to check the configuration.
4280 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004281 @Override
4282 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004283 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004284 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004285 final long identity = Binder.clearCallingIdentity();
4286 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004287 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004288 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004289 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004290 } catch (ImsException e) {
4291 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004292 } finally {
4293 Binder.restoreCallingIdentity(identity);
4294 }
4295 }
4296
4297 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004298 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004300 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004301 final long identity = Binder.clearCallingIdentity();
4302 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004303 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004304 // This setting doesn't require an active ImsService connection, so do not verify. The
4305 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004306 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004307 } catch (ImsException e) {
4308 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004309 } finally {
4310 Binder.restoreCallingIdentity(identity);
4311 }
4312 }
4313
shilu366312e2019-12-17 09:28:10 -08004314 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004315 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4316 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4317 * @param subId The subscription to use to check the configuration.
4318 */
4319 @Override
4320 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004321 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004322 mApp, subId, "isCrossSimCallingEnabledByUser");
4323 final long identity = Binder.clearCallingIdentity();
4324 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004325 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004326 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004327 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004328 } catch (ImsException e) {
4329 throw new ServiceSpecificException(e.getCode());
4330 } finally {
4331 Binder.restoreCallingIdentity(identity);
4332 }
4333 }
4334
4335 /**
4336 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4337 * Requires MODIFY_PHONE_STATE permission.
4338 * @param subId The subscription to use to check the configuration.
4339 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4340 * false otherwise
4341 */
4342 @Override
4343 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4345 "setCrossSimCallingEnabled");
4346 final long identity = Binder.clearCallingIdentity();
4347 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004348 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004349 // This setting doesn't require an active ImsService connection, so do not verify. The
4350 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004351 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004352 } catch (ImsException e) {
4353 throw new ServiceSpecificException(e.getCode());
4354 } finally {
4355 Binder.restoreCallingIdentity(identity);
4356 }
4357 }
4358
4359 /**
shilu366312e2019-12-17 09:28:10 -08004360 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4361 * @param subId The subscription to use to check the configuration.
4362 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004363 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004364
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004366 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004367 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004368 final long identity = Binder.clearCallingIdentity();
4369 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004370 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004371 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004372 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004373 } catch (ImsException e) {
4374 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 } finally {
4376 Binder.restoreCallingIdentity(identity);
4377 }
4378 }
4379
4380 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004381 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004383 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004384 final long identity = Binder.clearCallingIdentity();
4385 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004386 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004387 // This setting doesn't require an active ImsService connection, so do not verify. The
4388 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004389 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004390 } catch (ImsException e) {
4391 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004392 } finally {
4393 Binder.restoreCallingIdentity(identity);
4394 }
4395 }
4396
4397 @Override
4398 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4400 "setVoWiFiNonPersistent");
4401 final long identity = Binder.clearCallingIdentity();
4402 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004403 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004404 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004405 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004406 } catch (ImsException e) {
4407 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004408 } finally {
4409 Binder.restoreCallingIdentity(identity);
4410 }
4411 }
4412
shilu366312e2019-12-17 09:28:10 -08004413 /**
4414 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4415 * @param subId The subscription to use to check the configuration.
4416 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004417 @Override
4418 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004419 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004420 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004421 final long identity = Binder.clearCallingIdentity();
4422 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004423 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004424 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004425 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004426 } catch (ImsException e) {
4427 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004428 } finally {
4429 Binder.restoreCallingIdentity(identity);
4430 }
4431 }
4432
4433 @Override
4434 public void setVoWiFiModeSetting(int subId, int mode) {
4435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4436 "setVoWiFiModeSetting");
4437 final long identity = Binder.clearCallingIdentity();
4438 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004439 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004440 // This setting doesn't require an active ImsService connection, so do not verify. The
4441 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004442 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004443 } catch (ImsException e) {
4444 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004445 } finally {
4446 Binder.restoreCallingIdentity(identity);
4447 }
4448 }
4449
4450 @Override
4451 public int getVoWiFiRoamingModeSetting(int subId) {
4452 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4453 final long identity = Binder.clearCallingIdentity();
4454 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004455 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004456 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004457 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004458 } catch (ImsException e) {
4459 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004460 } finally {
4461 Binder.restoreCallingIdentity(identity);
4462 }
4463 }
4464
4465 @Override
4466 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4468 "setVoWiFiRoamingModeSetting");
4469 final long identity = Binder.clearCallingIdentity();
4470 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004471 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004472 // This setting doesn't require an active ImsService connection, so do not verify. The
4473 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004474 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004475 } catch (ImsException e) {
4476 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004477 } finally {
4478 Binder.restoreCallingIdentity(identity);
4479 }
4480 }
4481
4482 @Override
4483 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4485 "setRttCapabilityEnabled");
4486 final long identity = Binder.clearCallingIdentity();
4487 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004488 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004489 // This setting doesn't require an active ImsService connection, so do not verify. The
4490 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004491 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004492 } catch (ImsException e) {
4493 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004494 } finally {
4495 Binder.restoreCallingIdentity(identity);
4496 }
4497 }
4498
shilu366312e2019-12-17 09:28:10 -08004499 /**
4500 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4501 * @param subId The subscription to use to check the configuration.
4502 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004503 @Override
4504 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004505 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004506 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004507 final long identity = Binder.clearCallingIdentity();
4508 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004509 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004510 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004511 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004512 } catch (ImsException e) {
4513 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004514 } finally {
4515 Binder.restoreCallingIdentity(identity);
4516 }
4517 }
4518
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004519 @Override
4520 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4521 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4522 final long identity = Binder.clearCallingIdentity();
4523 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004524 if (!isImsAvailableOnDevice()) {
4525 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4526 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004527 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004528 int slotId = getSlotIndexOrException(subId);
4529 verifyImsMmTelConfiguredOrThrow(slotId);
4530 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004531 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004532 } catch (ImsException e) {
4533 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004534 } finally {
4535 Binder.restoreCallingIdentity(identity);
4536 }
4537 }
4538
4539 @Override
4540 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4541 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4542 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004543 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4544 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4545 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004546 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004547 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004548 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004549 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004550 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4551 + "is inactive, ignoring unregister.");
4552 // If the subscription is no longer active, just return, since the callback will already
4553 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004554 } finally {
4555 Binder.restoreCallingIdentity(identity);
4556 }
4557 }
4558
allenwtsu99c623b2020-01-03 18:24:23 +08004559
4560 private void checkModifyPhoneStatePermission(int subId, String message) {
4561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4562 message);
4563 }
4564
4565 private boolean isImsProvisioningRequired(int subId, int capability,
4566 boolean isMmtelCapability) {
4567 Phone phone = getPhone(subId);
4568 if (phone == null) {
4569 loge("phone instance null for subid " + subId);
4570 return false;
4571 }
4572 if (isMmtelCapability) {
4573 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4574 return false;
4575 }
4576 } else {
4577 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4578 return false;
4579 }
4580 }
4581 return true;
4582 }
4583
4584 @Override
4585 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4586 boolean isProvisioned) {
4587 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4588
4589 final long identity = Binder.clearCallingIdentity();
4590 try {
4591 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4592 if (!isImsProvisioningRequired(subId, capability, false)) {
4593 return;
4594 }
4595
4596 // this capability requires provisioning, route to the correct API.
4597 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4598 switch (capability) {
4599 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4600 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4601 ims.setEabProvisioned(isProvisioned);
4602 break;
4603 default: {
4604 throw new IllegalArgumentException("Tried to set provisioning for "
4605 + "rcs capability '" + capability + "', which does not require "
4606 + "provisioning.");
4607 }
4608 }
4609 } finally {
4610 Binder.restoreCallingIdentity(identity);
4611 }
4612
4613 }
4614
4615
4616 @Override
4617 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4618 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4619 final long identity = Binder.clearCallingIdentity();
4620 try {
4621 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4622 if (!isImsProvisioningRequired(subId, capability, false)) {
4623 return true;
4624 }
4625
4626 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4627 switch (capability) {
4628 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4629 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4630 return ims.isEabProvisionedOnDevice();
4631
4632 default: {
4633 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4634 + "capability '" + capability + "', which does not require "
4635 + "provisioning.");
4636 }
4637 }
4638
4639 } finally {
4640 Binder.restoreCallingIdentity(identity);
4641 }
4642 }
4643
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004644 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004645 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4646 boolean isProvisioned) {
4647 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004648 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4649 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4650 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004651 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4652 }
allenwtsu99c623b2020-01-03 18:24:23 +08004653 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004654 final long identity = Binder.clearCallingIdentity();
4655 try {
4656 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004657 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004658 return;
4659 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004660 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4661 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4662 loge("setImsProvisioningStatusForCapability: called for technology that does "
4663 + "not support provisioning - " + tech);
4664 return;
4665 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004666
4667 // this capability requires provisioning, route to the correct API.
4668 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4669 switch (capability) {
4670 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4671 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4672 ims.setVolteProvisioned(isProvisioned);
4673 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4674 ims.setWfcProvisioned(isProvisioned);
4675 }
4676 break;
4677 }
4678 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4679 // There is currently no difference in VT provisioning type.
4680 ims.setVtProvisioned(isProvisioned);
4681 break;
4682 }
4683 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4684 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4685 // change the capability of the feature instead if needed.
4686 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4687 == isProvisioned) {
4688 // No change in provisioning.
4689 return;
4690 }
4691 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4692 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004693 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004694 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004695 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4696 + ", Exception" + e.getMessage());
4697 }
4698 break;
4699 }
4700 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004701 throw new IllegalArgumentException("Tried to set provisioning for "
4702 + "MmTel capability '" + capability + "', which does not require "
4703 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004704 }
4705 }
4706
4707 } finally {
4708 Binder.restoreCallingIdentity(identity);
4709 }
4710 }
4711
4712 @Override
4713 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4714 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004715 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4716 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4717 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004718 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4719 }
4720 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4721 final long identity = Binder.clearCallingIdentity();
4722 try {
4723 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004724 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004725 return true;
4726 }
4727
Brad Ebinger0d79c572021-04-17 15:20:49 -07004728 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4729 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4730 loge("getImsProvisioningStatusForCapability: called for technology that does "
4731 + "not support provisioning - " + tech);
4732 return true;
4733 }
4734
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004735 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4736 switch (capability) {
4737 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4738 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4739 return ims.isVolteProvisionedOnDevice();
4740 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4741 return ims.isWfcProvisionedOnDevice();
4742 }
4743 // This should never happen, since we are checking tech above to make sure it
4744 // is either LTE or IWLAN.
4745 throw new IllegalArgumentException("Invalid radio technology for voice "
4746 + "capability.");
4747 }
4748 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4749 // There is currently no difference in VT provisioning type.
4750 return ims.isVtProvisionedOnDevice();
4751 }
4752 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4753 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4754 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4755 }
4756 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004757 throw new IllegalArgumentException(
4758 "Tried to get provisioning for MmTel capability '" + capability
4759 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004760 }
4761 }
4762
4763 } finally {
4764 Binder.restoreCallingIdentity(identity);
4765 }
4766 }
4767
4768 @Override
4769 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4770 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4771 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4772 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4773 }
4774 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4775 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4776 return (provisionedBits & capability) > 0;
4777 }
4778
4779 @Override
4780 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4781 boolean isProvisioned) {
4782 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4783 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4784 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4785 }
4786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4787 "setProvisioningStatusForCapability");
4788 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4789 // If the current provisioning status for capability already matches isProvisioned,
4790 // do nothing.
4791 if (((provisionedBits & capability) > 0) == isProvisioned) {
4792 return;
4793 }
4794 if (isProvisioned) {
4795 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4796 } else {
4797 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4798 }
4799 }
4800
4801 /**
4802 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4803 * technology. The bitfield should mirror the bitfield defined by
4804 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4805 */
4806 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4807 String key = getMmTelProvisioningKey(subId, tech);
4808 // Default is no capabilities are provisioned.
4809 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4810 }
4811
4812 /**
4813 * Sets the MmTel capability provisioning bitfield (defined by
4814 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4815 * technology specified.
4816 *
4817 * Note: This is a synchronous command and should not be called on UI thread.
4818 */
4819 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4820 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4821 String key = getMmTelProvisioningKey(subId, tech);
4822 editor.putInt(key, newField);
4823 editor.commit();
4824 }
4825
4826 private static String getMmTelProvisioningKey(int subId, int tech) {
4827 // resulting key is provision_ims_mmtel_{subId}_{tech}
4828 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4829 }
4830
4831 /**
4832 * Query CarrierConfig to see if the specified capability requires provisioning for the
4833 * carrier associated with the subscription id.
4834 */
4835 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4836 int capability) {
4837 CarrierConfigManager configManager = new CarrierConfigManager(context);
4838 PersistableBundle c = configManager.getConfigForSubId(subId);
4839 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004840 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004841 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4842 false);
4843 boolean requireVoiceVtProvisioning = c.getBoolean(
4844 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4845
4846 // First check to make sure that the capability requires provisioning.
4847 switch (capability) {
4848 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4849 // intentional fallthrough
4850 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4851 if (requireVoiceVtProvisioning) {
4852 // Voice and Video requires provisioning
4853 return true;
4854 }
4855 break;
4856 }
4857 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4858 if (requireUtProvisioning) {
4859 // UT requires provisioning
4860 return true;
4861 }
4862 break;
4863 }
4864 }
4865 return false;
4866 }
4867
allenwtsu99c623b2020-01-03 18:24:23 +08004868 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4869 int capability) {
4870 CarrierConfigManager configManager = new CarrierConfigManager(context);
4871 PersistableBundle c = configManager.getConfigForSubId(subId);
4872
4873 boolean requireRcsProvisioning = c.getBoolean(
4874 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4875
4876 // First check to make sure that the capability requires provisioning.
4877 switch (capability) {
4878 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4879 // intentional fallthrough
4880 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4881 if (requireRcsProvisioning) {
4882 // OPTION or PRESENCE requires provisioning
4883 return true;
4884 }
4885 break;
4886 }
4887 }
4888 return false;
4889 }
4890
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004891 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004892 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004893 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4894 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4895 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004896 enforceReadPrivilegedPermission("getImsProvisioningInt");
4897 final long identity = Binder.clearCallingIdentity();
4898 try {
4899 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004900 int slotId = getSlotIndex(subId);
4901 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4902 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4903 + subId + "' for key:" + key);
4904 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4905 }
calvinpanb5a34062021-02-08 19:59:36 +08004906 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004907 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004908 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4909 + subId + "' for key:" + key);
4910 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004911 } finally {
4912 Binder.restoreCallingIdentity(identity);
4913 }
4914 }
4915
4916 @Override
4917 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004918 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4919 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4920 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004921 enforceReadPrivilegedPermission("getImsProvisioningString");
4922 final long identity = Binder.clearCallingIdentity();
4923 try {
4924 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004925 int slotId = getSlotIndex(subId);
4926 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4927 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4928 + subId + "' for key:" + key);
4929 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4930 }
calvinpanb5a34062021-02-08 19:59:36 +08004931 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004932 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004933 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4934 + subId + "' for key:" + key);
4935 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004936 } finally {
4937 Binder.restoreCallingIdentity(identity);
4938 }
4939 }
4940
4941 @Override
4942 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004943 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4944 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4945 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4947 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004948 final long identity = Binder.clearCallingIdentity();
4949 try {
4950 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004951 int slotId = getSlotIndex(subId);
4952 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4953 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4954 + subId + "' for key:" + key);
4955 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4956 }
calvinpanb5a34062021-02-08 19:59:36 +08004957 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4958 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004959 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004960 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004961 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004962 } finally {
4963 Binder.restoreCallingIdentity(identity);
4964 }
4965 }
4966
4967 @Override
4968 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004969 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4970 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4971 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4973 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004974 final long identity = Binder.clearCallingIdentity();
4975 try {
4976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004977 int slotId = getSlotIndex(subId);
4978 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4979 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4980 + subId + "' for key:" + key);
4981 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4982 }
calvinpanb5a34062021-02-08 19:59:36 +08004983 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4984 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004985 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004986 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004987 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004988 } finally {
4989 Binder.restoreCallingIdentity(identity);
4990 }
4991 }
4992
Brad Ebinger919631e2021-06-02 17:46:35 -07004993 /**
4994 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4995 * for the given slot ID or no ImsResolver instance has been created.
4996 * @param slotId The slot ID that the IMS service is created for.
4997 * @throws ImsException If there is no ImsService configured for this slot.
4998 */
4999 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5000 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5001 ImsFeature.FEATURE_MMTEL)) {
5002 throw new ImsException("This subscription does not support MMTEL over IMS",
5003 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5004 }
5005 }
5006
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005007 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005008 int slotId = SubscriptionManager.getSlotIndex(subId);
5009 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005010 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5011 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005012 }
5013 return slotId;
5014 }
5015
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005016 private int getSlotIndex(int subId) {
5017 int slotId = SubscriptionManager.getSlotIndex(subId);
5018 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5019 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5020 }
5021 return slotId;
5022 }
5023
Wink Saville36469e72014-06-11 15:17:00 -07005024 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005025 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005026 */
5027 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005028 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5029 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005030 try {
5031 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5032 } catch (SecurityException se) {
5033 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5034 throw new SecurityException("Package " + callingPackage + " does not belong to "
5035 + Binder.getCallingUid());
5036 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005037 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005038 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005039 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005040 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005041 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005042 mApp, subId, callingPackage, callingFeatureId,
5043 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005044 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5045 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005047 final long identity = Binder.clearCallingIdentity();
5048 try {
5049 final Phone phone = getPhone(subId);
5050 if (phone != null) {
5051 return phone.getServiceState().getDataNetworkType();
5052 } else {
5053 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5054 }
5055 } finally {
5056 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005057 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005058 }
5059
5060 /**
5061 * Returns the data network type
5062 */
5063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005064 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005065 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5066 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005067 }
5068
5069 /**
5070 * Returns the data network type for a subId
5071 */
5072 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005073 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5074 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005075 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005076 mApp, subId, callingPackage, callingFeatureId,
5077 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005078 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5079 }
5080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 final long identity = Binder.clearCallingIdentity();
5082 try {
5083 final Phone phone = getPhone(subId);
5084 if (phone != null) {
5085 return phone.getServiceState().getDataNetworkType();
5086 } else {
5087 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5088 }
5089 } finally {
5090 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005092 }
5093
5094 /**
Wink Saville36469e72014-06-11 15:17:00 -07005095 * Returns the Voice network type for a subId
5096 */
5097 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005098 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5099 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005100 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005101 mApp, subId, callingPackage, callingFeatureId,
5102 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005103 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5104 }
5105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106 final long identity = Binder.clearCallingIdentity();
5107 try {
5108 final Phone phone = getPhone(subId);
5109 if (phone != null) {
5110 return phone.getServiceState().getVoiceNetworkType();
5111 } else {
5112 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5113 }
5114 } finally {
5115 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005116 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005117 }
5118
5119 /**
5120 * @return true if a ICC card is present
5121 */
5122 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005123 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005124 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5125 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005126 }
5127
5128 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005129 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005130 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005131 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005132 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 final long identity = Binder.clearCallingIdentity();
5134 try {
5135 final Phone phone = PhoneFactory.getPhone(slotIndex);
5136 if (phone != null) {
5137 return phone.getIccCard().hasIccCard();
5138 } else {
5139 return false;
5140 }
5141 } finally {
5142 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005144 }
5145
5146 /**
5147 * Return if the current radio is LTE on CDMA. This
5148 * is a tri-state return value as for a period of time
5149 * the mode may be unknown.
5150 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005151 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005152 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005153 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005154 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005155 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005156 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5157 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5158 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005159 }
5160
Sanket Padawe356d7632015-06-22 14:03:32 -07005161 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005162 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5163 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005164 try {
5165 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5166 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005167 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5168 }
5169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005170 final long identity = Binder.clearCallingIdentity();
5171 try {
5172 final Phone phone = getPhone(subId);
5173 if (phone == null) {
5174 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5175 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005176 return TelephonyProperties.lte_on_cdma_device()
5177 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178 }
5179 } finally {
5180 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005181 }
Wink Saville36469e72014-06-11 15:17:00 -07005182 }
5183
Wink Saville36469e72014-06-11 15:17:00 -07005184 /**
5185 * {@hide}
5186 * Returns Default subId, 0 in the case of single standby.
5187 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005188 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005189 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005190 }
5191
Shishir Agrawala9f32182016-04-12 12:00:16 -07005192 private int getSlotForDefaultSubscription() {
5193 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5194 }
5195
Wink Savilleb564aae2014-10-23 10:18:09 -07005196 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005197 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005198 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005199
Pengquan Menge92a50d2018-09-21 15:54:48 -07005200 private boolean isActiveSubscription(int subId) {
5201 return mSubscriptionController.isActiveSubId(subId);
5202 }
5203
Ihab Awadf2177b72013-11-25 13:33:23 -08005204 /**
5205 * @see android.telephony.TelephonyManager.WifiCallingChoices
5206 */
5207 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 final long identity = Binder.clearCallingIdentity();
5209 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005210 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5212 getWhenToMakeWifiCallsDefaultPreference());
5213 } finally {
5214 Binder.restoreCallingIdentity(identity);
5215 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005216 }
5217
5218 /**
5219 * @see android.telephony.TelephonyManager.WifiCallingChoices
5220 */
5221 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005222 final long identity = Binder.clearCallingIdentity();
5223 try {
5224 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005225 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005226 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5227 } finally {
5228 Binder.restoreCallingIdentity(identity);
5229 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005230 }
5231
Sailesh Nepald1e68152013-12-12 19:08:02 -08005232 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005233 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005234 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005235 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005236
Jordan Liu4c733742019-02-28 12:03:40 -08005237 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5238 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5239 if (phoneId == -1) {
5240 throw new IllegalArgumentException("Given slot index: " + slotIndex
5241 + " does not correspond to an active phone");
5242 }
5243 return PhoneFactory.getPhone(phoneId);
5244 }
5245
Shishir Agrawal566b7612013-10-28 14:41:00 -07005246 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005247 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5248 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5250 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005252 if (DBG) {
5253 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5254 }
5255 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5256 p2);
5257 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005258
Jordan Liu4c733742019-02-28 12:03:40 -08005259
5260 @Override
5261 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5262 int slotIndex, String callingPackage, String aid, int p2) {
5263 enforceModifyPermission();
5264 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5265 if (DBG) {
5266 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5267 }
5268 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5269 callingPackage, aid, p2);
5270 }
5271
5272 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5273 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274 final long identity = Binder.clearCallingIdentity();
5275 try {
5276 if (TextUtils.equals(ISDR_AID, aid)) {
5277 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005278 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5279 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 if (bestComponent == null
5281 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5282 loge("The calling package is not allowed to access ISD-R.");
5283 throw new SecurityException(
5284 "The calling package is not allowed to access ISD-R.");
5285 }
Derek Tan740e1672017-06-27 14:56:27 -07005286 }
Derek Tan740e1672017-06-27 14:56:27 -07005287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005289 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5290 null /* workSource */);
5291 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292 return response;
5293 } finally {
5294 Binder.restoreCallingIdentity(identity);
5295 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005296 }
5297
5298 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005299 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5301 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005302 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5303 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5304 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005305
Jordan Liu4c733742019-02-28 12:03:40 -08005306 @Override
5307 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5308 enforceModifyPermission();
5309 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5310 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5311 channel);
5312 }
5313
5314 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005315 final long identity = Binder.clearCallingIdentity();
5316 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005317 if (channel < 0) {
5318 return false;
5319 }
Jordan Liu4c733742019-02-28 12:03:40 -08005320 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5321 null /* workSource */);
5322 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 return success;
5324 } finally {
5325 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005326 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005327 }
5328
5329 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005330 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005331 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5333 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005334 if (DBG) {
5335 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5336 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5337 + p3 + " data=" + data);
5338 }
5339 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5340 command, p1, p2, p3, data);
5341 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005342
Jordan Liu4c733742019-02-28 12:03:40 -08005343 @Override
5344 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5345 int command, int p1, int p2, int p3, String data) {
5346 enforceModifyPermission();
5347 if (DBG) {
5348 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5349 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5350 + p3 + " data=" + data);
5351 }
5352 return iccTransmitApduLogicalChannelWithPermission(
5353 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5354 data);
5355 }
5356
5357 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5358 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 final long identity = Binder.clearCallingIdentity();
5360 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005361 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362 return "";
5363 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005365 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005366 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5367 null /* workSource */);
5368 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005369
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370 // Append the returned status code to the end of the response payload.
5371 String s = Integer.toHexString(
5372 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5373 if (response.payload != null) {
5374 s = IccUtils.bytesToHexString(response.payload) + s;
5375 }
5376 return s;
5377 } finally {
5378 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005379 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005380 }
Jake Hambye994d462014-02-03 13:10:13 -08005381
Evan Charltonc66da362014-05-16 14:06:40 -07005382 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005383 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5384 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5386 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005387 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005388 if (DBG) {
5389 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5390 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5391 }
5392 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5393 cla, command, p1, p2, p3, data);
5394 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005395
Jordan Liu4c733742019-02-28 12:03:40 -08005396 @Override
5397 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5398 int command, int p1, int p2, int p3, String data) {
5399 enforceModifyPermission();
5400 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5401 if (DBG) {
5402 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5403 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5404 + " data=" + data);
5405 }
5406
5407 return iccTransmitApduBasicChannelWithPermission(
5408 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5409 p2, p3, data);
5410 }
5411
5412 // open APDU basic channel assuming the caller has sufficient permissions
5413 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5414 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415 final long identity = Binder.clearCallingIdentity();
5416 try {
5417 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5418 && TextUtils.equals(ISDR_AID, data)) {
5419 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005420 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5421 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422 if (bestComponent == null
5423 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5424 loge("The calling package is not allowed to select ISD-R.");
5425 throw new SecurityException(
5426 "The calling package is not allowed to select ISD-R.");
5427 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005428 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005431 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5432 null /* workSource */);
5433 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005434
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435 // Append the returned status code to the end of the response payload.
5436 String s = Integer.toHexString(
5437 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5438 if (response.payload != null) {
5439 s = IccUtils.bytesToHexString(response.payload) + s;
5440 }
5441 return s;
5442 } finally {
5443 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005444 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005445 }
5446
5447 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005448 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005449 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5451 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005453 final long identity = Binder.clearCallingIdentity();
5454 try {
5455 if (DBG) {
5456 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5457 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5458 }
5459
5460 IccIoResult response =
5461 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5462 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5463 subId);
5464
5465 if (DBG) {
5466 log("Exchange SIM_IO [R]" + response);
5467 }
5468
5469 byte[] result = null;
5470 int length = 2;
5471 if (response.payload != null) {
5472 length = 2 + response.payload.length;
5473 result = new byte[length];
5474 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5475 } else {
5476 result = new byte[length];
5477 }
5478
5479 result[length - 1] = (byte) response.sw2;
5480 result[length - 2] = (byte) response.sw1;
5481 return result;
5482 } finally {
5483 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005484 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005485 }
5486
Nathan Haroldb3014052017-01-25 15:57:32 -08005487 /**
5488 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5489 * on a particular subscription
5490 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005491 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5492 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005493 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005494 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005495 return null;
5496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005497
5498 final long identity = Binder.clearCallingIdentity();
5499 try {
5500 if (appType != TelephonyManager.APPTYPE_USIM
5501 && appType != TelephonyManager.APPTYPE_SIM) {
5502 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5503 return null;
5504 }
5505 Object response = sendRequest(
5506 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5507 if (response instanceof String[]) {
5508 return (String[]) response;
5509 }
yincheng zhao2737e882019-09-06 17:06:54 -07005510 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005512 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513 } finally {
5514 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005515 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005516 }
5517
yincheng zhao2737e882019-09-06 17:06:54 -07005518 /**
5519 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5520 * subscription.
5521 *
5522 * @param subId the id of the subscription.
5523 * @param appType the uicc app type, must be USIM or SIM.
5524 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5525 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005526 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005527 * @return number of fplmns that is successfully written to the SIM.
5528 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005529 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5530 String callingFeatureId) {
5531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5532 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005533 if (DBG) logv("no permissions for setForbiddenplmns");
5534 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5535 }
5536 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5537 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5538 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5539 }
5540 if (fplmns == null) {
5541 throw new IllegalArgumentException("Fplmn List provided is null");
5542 }
5543 for (String fplmn : fplmns) {
5544 if (!CellIdentity.isValidPlmn(fplmn)) {
5545 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5546 }
5547 }
5548 final long identity = Binder.clearCallingIdentity();
5549 try {
5550 Object response = sendRequest(
5551 CMD_SET_FORBIDDEN_PLMNS,
5552 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5553 subId);
5554 return (int) response;
5555 } finally {
5556 Binder.restoreCallingIdentity(identity);
5557 }
5558 }
5559
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005560 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005561 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5563 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 final long identity = Binder.clearCallingIdentity();
5566 try {
5567 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5568 if (response.payload == null) {
5569 return "";
5570 }
Evan Charltonc66da362014-05-16 14:06:40 -07005571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005572 // Append the returned status code to the end of the response payload.
5573 String s = Integer.toHexString(
5574 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5575 s = IccUtils.bytesToHexString(response.payload) + s;
5576 return s;
5577 } finally {
5578 Binder.restoreCallingIdentity(identity);
5579 }
Evan Charltonc66da362014-05-16 14:06:40 -07005580 }
5581
Jake Hambye994d462014-02-03 13:10:13 -08005582 /**
5583 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5584 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5585 *
5586 * @param itemID the ID of the item to read
5587 * @return the NV item as a String, or null on error.
5588 */
5589 @Override
5590 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005591 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5593 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594
5595 final long identity = Binder.clearCallingIdentity();
5596 try {
5597 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005598 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5600 return value;
5601 } finally {
5602 Binder.restoreCallingIdentity(identity);
5603 }
Jake Hambye994d462014-02-03 13:10:13 -08005604 }
5605
5606 /**
5607 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5608 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5609 *
5610 * @param itemID the ID of the item to read
5611 * @param itemValue the value to write, as a String
5612 * @return true on success; false on any failure
5613 */
5614 @Override
5615 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005616 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5618 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619
5620 final long identity = Binder.clearCallingIdentity();
5621 try {
5622 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5623 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005624 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005625 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5626 return success;
5627 } finally {
5628 Binder.restoreCallingIdentity(identity);
5629 }
Jake Hambye994d462014-02-03 13:10:13 -08005630 }
5631
5632 /**
5633 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5634 * Used for device configuration by some CDMA operators.
5635 *
5636 * @param preferredRoamingList byte array containing the new PRL
5637 * @return true on success; false on any failure
5638 */
5639 @Override
5640 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5642 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643
5644 final long identity = Binder.clearCallingIdentity();
5645 try {
5646 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5647 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5648 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5649 return success;
5650 } finally {
5651 Binder.restoreCallingIdentity(identity);
5652 }
Jake Hambye994d462014-02-03 13:10:13 -08005653 }
5654
5655 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005656 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005657 * Used for device configuration by some CDMA operators.
5658 *
chen xu6dac5ab2018-10-26 17:39:23 -07005659 * @param slotIndex - device slot.
5660 *
Jake Hambye994d462014-02-03 13:10:13 -08005661 * @return true on success; false on any failure
5662 */
5663 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005664 public boolean resetModemConfig(int slotIndex) {
5665 Phone phone = PhoneFactory.getPhone(slotIndex);
5666 if (phone != null) {
5667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5668 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005669
chen xu6dac5ab2018-10-26 17:39:23 -07005670 final long identity = Binder.clearCallingIdentity();
5671 try {
5672 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5673 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5674 return success;
5675 } finally {
5676 Binder.restoreCallingIdentity(identity);
5677 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678 }
chen xu6dac5ab2018-10-26 17:39:23 -07005679 return false;
5680 }
5681
5682 /**
5683 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5684 *
5685 * @param slotIndex - device slot.
5686 *
5687 * @return true on success; false on any failure
5688 */
5689 @Override
5690 public boolean rebootModem(int slotIndex) {
5691 Phone phone = PhoneFactory.getPhone(slotIndex);
5692 if (phone != null) {
5693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5694 mApp, phone.getSubId(), "rebootModem");
5695
5696 final long identity = Binder.clearCallingIdentity();
5697 try {
5698 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5699 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5700 return success;
5701 } finally {
5702 Binder.restoreCallingIdentity(identity);
5703 }
5704 }
5705 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005706 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005707
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005708 public String[] getPcscfAddress(String apnType, String callingPackage,
5709 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005710 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5712 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005713 return new String[0];
5714 }
5715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 final long identity = Binder.clearCallingIdentity();
5717 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005718 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719 } finally {
5720 Binder.restoreCallingIdentity(identity);
5721 }
Wink Saville36469e72014-06-11 15:17:00 -07005722 }
5723
Brad Ebinger51f743a2017-01-23 13:50:20 -08005724 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005725 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5726 * {@link #disableIms(int)}.
5727 * @param slotIndex device slot.
5728 */
5729 public void resetIms(int slotIndex) {
5730 enforceModifyPermission();
5731
5732 final long identity = Binder.clearCallingIdentity();
5733 try {
5734 if (mImsResolver == null) {
5735 // may happen if the does not support IMS.
5736 return;
5737 }
5738 mImsResolver.disableIms(slotIndex);
5739 mImsResolver.enableIms(slotIndex);
5740 } finally {
5741 Binder.restoreCallingIdentity(identity);
5742 }
5743 }
5744
5745 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005746 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5747 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005748 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005749 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005750 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751
5752 final long identity = Binder.clearCallingIdentity();
5753 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005754 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005755 // may happen if the device does not support IMS.
5756 return;
5757 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005758 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005759 } finally {
5760 Binder.restoreCallingIdentity(identity);
5761 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005762 }
5763
5764 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005765 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5766 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005767 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005768 public void disableIms(int slotId) {
5769 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770
5771 final long identity = Binder.clearCallingIdentity();
5772 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005773 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005774 // may happen if the device does not support IMS.
5775 return;
5776 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005777 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 } finally {
5779 Binder.restoreCallingIdentity(identity);
5780 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005781 }
5782
5783 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005784 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5785 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005786 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005787 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005788 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005789 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790
5791 final long identity = Binder.clearCallingIdentity();
5792 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005793 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005794 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5795 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005796 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005797 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798 } finally {
5799 Binder.restoreCallingIdentity(identity);
5800 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005801 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005802 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005803 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5804 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005805 @Override
5806 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005807 enforceModifyPermission();
5808
5809 final long identity = Binder.clearCallingIdentity();
5810 try {
5811 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005812 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005813 } finally {
5814 Binder.restoreCallingIdentity(identity);
5815 }
5816 }
5817
5818 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005819 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005820 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005821 */
5822 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5823 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005824
5825 final long identity = Binder.clearCallingIdentity();
5826 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005827 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005828 // may happen if the device does not support IMS.
5829 return null;
5830 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005831 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832 } finally {
5833 Binder.restoreCallingIdentity(identity);
5834 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005835 }
5836
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005837 /**
5838 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005839 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005840 */
5841 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5842 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005843
5844 final long identity = Binder.clearCallingIdentity();
5845 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005846 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005847 // may happen if the device does not support IMS.
5848 return null;
5849 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005850 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851 } finally {
5852 Binder.restoreCallingIdentity(identity);
5853 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005854 }
5855
Brad Ebinger884c07b2018-02-15 16:17:40 -08005856 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005857 * Sets the ImsService Package Name that Telephony will bind to.
5858 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005859 * @param slotIndex the slot ID that the ImsService should bind for.
5860 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005861 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005862 * @param featureTypes An integer array of feature types associated with a packageName.
5863 * @param packageName The name of the package that the current configuration will be replaced
5864 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005865 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005866 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005867 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5868 int[] featureTypes, String packageName) {
5869 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5870 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5872 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005873 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005874
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875 final long identity = Binder.clearCallingIdentity();
5876 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005877 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005878 // may happen if the device does not support IMS.
5879 return false;
5880 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005881 Map<Integer, String> featureConfig = new HashMap<>();
5882 for (int featureType : featureTypes) {
5883 featureConfig.put(featureType, packageName);
5884 }
5885 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5886 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 } finally {
5888 Binder.restoreCallingIdentity(identity);
5889 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005890 }
5891
5892 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005893 * Clears any carrier ImsService overrides for the slot index specified that were previously
5894 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5895 *
5896 * This should only be used for testing.
5897 *
5898 * @param slotIndex the slot ID that the ImsService should bind for.
5899 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5900 */
5901 @Override
5902 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5903 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5904 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5905 "clearCarrierImsServiceOverride");
5906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5907 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5908 "clearCarrierImsServiceOverride");
5909
5910 final long identity = Binder.clearCallingIdentity();
5911 try {
5912 if (mImsResolver == null) {
5913 // may happen if the device does not support IMS.
5914 return false;
5915 }
5916 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5917 } finally {
5918 Binder.restoreCallingIdentity(identity);
5919 }
5920 }
5921
5922 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005923 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005924 *
5925 * @param slotId The slot that the ImsService is associated with.
5926 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5927 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005928 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005929 * @return the package name of the ImsService configuration.
5930 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005931 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5932 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005933 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005934 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005935 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005936 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5937 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939 final long identity = Binder.clearCallingIdentity();
5940 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005941 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005942 // may happen if the device does not support IMS.
5943 return "";
5944 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005945 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005946 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5947 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005951 }
5952
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005953 /**
5954 * Get the MmTelFeature state associated with the requested subscription id.
5955 * @param subId The subscription that the MmTelFeature is associated with.
5956 * @param callback A callback with an integer containing the
5957 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5958 */
5959 @Override
5960 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5961 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5962 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5963 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5964 "IMS not available on device.");
5965 }
5966 final long token = Binder.clearCallingIdentity();
5967 try {
5968 int slotId = getSlotIndex(subId);
5969 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5970 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5971 + subId + "'");
5972 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5973 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005974 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005975 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5976 try {
5977 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5978 } catch (RemoteException e) {
5979 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5980 + "Ignore");
5981 }
5982 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005983 } catch (ImsException e) {
5984 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005985 } finally {
5986 Binder.restoreCallingIdentity(token);
5987 }
5988 }
5989
Daniel Brightbb5840b2021-01-12 15:48:18 -08005990 /**
5991 * Sets the ims registration state on all valid {@link Phone}s.
5992 */
5993 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005994 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995
5996 final long identity = Binder.clearCallingIdentity();
5997 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005998 // NOTE: Before S, this method only set the default phone.
5999 for (final Phone phone : PhoneFactory.getPhones()) {
6000 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6001 phone.setImsRegistrationState(registered);
6002 }
6003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 } finally {
6005 Binder.restoreCallingIdentity(identity);
6006 }
Wink Saville36469e72014-06-11 15:17:00 -07006007 }
6008
6009 /**
Stuart Scott54788802015-03-30 13:18:01 -07006010 * Set the network selection mode to automatic.
6011 *
6012 */
6013 @Override
6014 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6016 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017
6018 final long identity = Binder.clearCallingIdentity();
6019 try {
shilufc958392020-01-20 11:36:01 -08006020 if (!isActiveSubscription(subId)) {
6021 return;
6022 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006023 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006024 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6025 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006026 } finally {
6027 Binder.restoreCallingIdentity(identity);
6028 }
Stuart Scott54788802015-03-30 13:18:01 -07006029 }
6030
Jack Yud10cdd42020-09-28 20:28:01 -07006031 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006032 * Ask the radio to connect to the input network and change selection mode to manual.
6033 *
6034 * @param subId the id of the subscription.
6035 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6036 * the operator to attach to.
6037 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6038 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6039 * normal network selection next time.
6040 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006041 */
6042 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006043 public boolean setNetworkSelectionModeManual(
6044 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6046 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006047
6048 if (!isActiveSubscription(subId)) {
6049 return false;
6050 }
6051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052 final long identity = Binder.clearCallingIdentity();
6053 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006054 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006056 if (DBG) {
6057 log("setNetworkSelectionModeManual: subId: " + subId
6058 + " operator: " + operatorInfo);
6059 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6061 } finally {
6062 Binder.restoreCallingIdentity(identity);
6063 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006064 }
shilu84f6e8b2019-12-19 13:58:01 -08006065 /**
6066 * Get the manual network selection
6067 *
6068 * @param subId the id of the subscription.
6069 *
6070 * @return the previously saved user selected PLMN
6071 */
6072 @Override
6073 public String getManualNetworkSelectionPlmn(int subId) {
6074 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006075 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006076 mApp, subId, "getManualNetworkSelectionPlmn");
6077
6078 final long identity = Binder.clearCallingIdentity();
6079 try {
6080 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006081 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006082 }
6083
6084 final Phone phone = getPhone(subId);
6085 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006086 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006087 }
6088 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6089 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6090 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6091 } finally {
6092 Binder.restoreCallingIdentity(identity);
6093 }
6094 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006095
6096 /**
6097 * Scans for available networks.
6098 */
6099 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006100 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6101 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6103 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006104 LocationAccessPolicy.LocationPermissionResult locationResult =
6105 LocationAccessPolicy.checkLocationPermission(mApp,
6106 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6107 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006108 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006109 .setCallingPid(Binder.getCallingPid())
6110 .setCallingUid(Binder.getCallingUid())
6111 .setMethod("getCellNetworkScanResults")
6112 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006113 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6114 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006115 .build());
6116 switch (locationResult) {
6117 case DENIED_HARD:
6118 throw new SecurityException("Not allowed to access scan results -- location");
6119 case DENIED_SOFT:
6120 return null;
6121 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122
Pengquan Menga1bb6272018-09-06 09:59:22 -07006123 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006124 try {
6125 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006126 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006127 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 } finally {
6129 Binder.restoreCallingIdentity(identity);
6130 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006131 }
6132
6133 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006134 * Get the call forwarding info, given the call forwarding reason.
6135 */
6136 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006137 public void getCallForwarding(int subId, int callForwardingReason,
6138 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006139 enforceReadPrivilegedPermission("getCallForwarding");
6140 long identity = Binder.clearCallingIdentity();
6141 try {
6142 if (DBG) {
6143 log("getCallForwarding: subId " + subId
6144 + " callForwardingReason" + callForwardingReason);
6145 }
Hall Liu27d24262020-09-18 19:04:59 -07006146
6147 Phone phone = getPhone(subId);
6148 if (phone == null) {
6149 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006150 callback.onError(
6151 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006152 } catch (RemoteException e) {
6153 // ignore
6154 }
6155 return;
6156 }
6157
6158 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6159 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6160 @Override
6161 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6162 try {
6163 callback.onCallForwardingInfoAvailable(info);
6164 } catch (RemoteException e) {
6165 // ignore
6166 }
6167 }
6168
6169 @Override
6170 public void onError(int error) {
6171 try {
6172 callback.onError(error);
6173 } catch (RemoteException e) {
6174 // ignore
6175 }
6176 }
6177 });
6178 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006179 } finally {
6180 Binder.restoreCallingIdentity(identity);
6181 }
6182 }
6183
6184 /**
6185 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6186 * reason, the number to forward, and the timeout before the forwarding is attempted.
6187 */
6188 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006189 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6190 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006191 enforceModifyPermission();
6192 long identity = Binder.clearCallingIdentity();
6193 try {
6194 if (DBG) {
6195 log("setCallForwarding: subId " + subId
6196 + " callForwardingInfo" + callForwardingInfo);
6197 }
Hall Liu27d24262020-09-18 19:04:59 -07006198
6199 Phone phone = getPhone(subId);
6200 if (phone == null) {
6201 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006202 callback.accept(
6203 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006204 } catch (RemoteException e) {
6205 // ignore
6206 }
6207 return;
6208 }
6209
6210 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6211 FunctionalUtils.ignoreRemoteException(callback::accept));
6212
6213 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006214 } finally {
6215 Binder.restoreCallingIdentity(identity);
6216 }
6217 }
6218
6219 /**
Hall Liu27d24262020-09-18 19:04:59 -07006220 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006221 */
6222 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006223 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006224 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006225 long identity = Binder.clearCallingIdentity();
6226 try {
Hall Liu27d24262020-09-18 19:04:59 -07006227 Phone phone = getPhone(subId);
6228 if (phone == null) {
6229 try {
6230 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6231 } catch (RemoteException e) {
6232 // ignore
6233 }
6234 return;
6235 }
SongFerngWang0e767992021-03-31 22:08:45 +08006236 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6237 PersistableBundle c = configManager.getConfigForSubId(subId);
6238 boolean requireUssd = c.getBoolean(
6239 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006240
Shuo Qian4a594052020-01-23 11:59:30 -08006241 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006242 if (requireUssd) {
6243 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6244 getSubscriptionCarrierId(subId));
6245 String newUssdCommand = "";
6246 try {
6247 newUssdCommand = carrierXmlParser.getFeature(
6248 CarrierXmlParser.FEATURE_CALL_WAITING)
6249 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6250 } catch (NullPointerException e) {
6251 loge("Failed to generate USSD number" + e);
6252 }
6253 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6254 mMainThreadHandler, callback, carrierXmlParser,
6255 CarrierXmlParser.SsEntry.SSAction.QUERY);
6256 final String ussdCommand = newUssdCommand;
6257 Executors.newSingleThreadExecutor().execute(() -> {
6258 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6259 });
6260 } else {
6261 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6262 callback::accept);
6263 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6264 }
Shuo Qian4a594052020-01-23 11:59:30 -08006265 } finally {
6266 Binder.restoreCallingIdentity(identity);
6267 }
6268 }
6269
6270 /**
Hall Liu27d24262020-09-18 19:04:59 -07006271 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006272 */
6273 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006274 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006275 enforceModifyPermission();
6276 long identity = Binder.clearCallingIdentity();
6277 try {
Hall Liu27d24262020-09-18 19:04:59 -07006278 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6279
6280 Phone phone = getPhone(subId);
6281 if (phone == null) {
6282 try {
6283 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6284 } catch (RemoteException e) {
6285 // ignore
6286 }
6287 return;
6288 }
6289
SongFerngWang0e767992021-03-31 22:08:45 +08006290 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6291 PersistableBundle c = configManager.getConfigForSubId(subId);
6292 boolean requireUssd = c.getBoolean(
6293 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006294
SongFerngWang0e767992021-03-31 22:08:45 +08006295 if (DBG) log("getCallWaitingStatus: subId " + subId);
6296 if (requireUssd) {
6297 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6298 getSubscriptionCarrierId(subId));
6299 CarrierXmlParser.SsEntry.SSAction ssAction =
6300 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6301 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6302 String newUssdCommand = "";
6303 try {
6304 newUssdCommand = carrierXmlParser.getFeature(
6305 CarrierXmlParser.FEATURE_CALL_WAITING)
6306 .makeCommand(ssAction, null);
6307 } catch (NullPointerException e) {
6308 loge("Failed to generate USSD number" + e);
6309 }
6310 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6311 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6312 final String ussdCommand = newUssdCommand;
6313 Executors.newSingleThreadExecutor().execute(() -> {
6314 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6315 });
6316 } else {
6317 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6318 FunctionalUtils.ignoreRemoteException(callback::accept));
6319
6320 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6321 }
Shuo Qian4a594052020-01-23 11:59:30 -08006322 } finally {
6323 Binder.restoreCallingIdentity(identity);
6324 }
6325 }
6326
6327 /**
yinxub1bed742017-04-17 11:45:04 -07006328 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006329 *
yinxub1bed742017-04-17 11:45:04 -07006330 * @param subId id of the subscription
6331 * @param request contains the radio access networks with bands/channels to scan
6332 * @param messenger callback messenger for scan results or errors
6333 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006334 * @return the id of the requested scan which can be used to stop the scan.
6335 */
6336 @Override
6337 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006338 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6340 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006341 LocationAccessPolicy.LocationPermissionResult locationResult =
6342 LocationAccessPolicy.checkLocationPermission(mApp,
6343 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6344 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006345 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006346 .setCallingPid(Binder.getCallingPid())
6347 .setCallingUid(Binder.getCallingUid())
6348 .setMethod("requestNetworkScan")
6349 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006350 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6351 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006352 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006353 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006354 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6355 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006356 if (e != null) {
6357 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6358 throw e;
6359 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006360 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006361 return TelephonyScanManager.INVALID_SCAN_ID;
6362 }
6363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 }
Hall Liu912dfd32019-04-25 14:02:26 -07006365 int callingUid = Binder.getCallingUid();
6366 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006367 final long identity = Binder.clearCallingIdentity();
6368 try {
6369 return mNetworkScanRequestTracker.startNetworkScan(
6370 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006371 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006372 } finally {
6373 Binder.restoreCallingIdentity(identity);
6374 }
yinxu504e1392017-04-12 16:03:22 -07006375 }
6376
Hall Liub2ac8ef2019-02-28 15:56:23 -08006377 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006378 NetworkScanRequest request, int subId, String callingPackage) {
6379 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006380 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6381 boolean hasNetworkScanPermission =
6382 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6383 == PERMISSION_GRANTED;
6384
6385 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6386 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6387 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006388 }
6389
6390 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6391 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006392 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6393 return new SecurityException("Specific channels must not be"
6394 + " scanned without location access.");
6395 }
6396 }
6397 }
6398
Hall Liub2ac8ef2019-02-28 15:56:23 -08006399 return null;
6400 }
6401
yinxu504e1392017-04-12 16:03:22 -07006402 /**
6403 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006404 *
6405 * @param subId id of the subscription
6406 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006407 */
6408 @Override
6409 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6411 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412
Hall Liu912dfd32019-04-25 14:02:26 -07006413 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 final long identity = Binder.clearCallingIdentity();
6415 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006416 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
yinxu504e1392017-04-12 16:03:22 -07006420 }
6421
6422 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006423 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006424 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006425 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006426 */
6427 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006428 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006429 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006430 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006431 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432
6433 final long identity = Binder.clearCallingIdentity();
6434 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006435 if (DBG) log("getAllowedNetworkTypesBitmask");
6436 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6437 int networkTypesBitmask = (result != null ? result[0] : -1);
6438 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6439 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440 } finally {
6441 Binder.restoreCallingIdentity(identity);
6442 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006443 }
6444
6445 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006446 * Get the allowed network types for certain reason.
6447 *
6448 * @param subId the id of the subscription.
6449 * @param reason the reason the allowed network type change is taking place
6450 * @return the allowed network types.
6451 */
6452 @Override
6453 public long getAllowedNetworkTypesForReason(int subId,
6454 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006455 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006456 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006457 final long identity = Binder.clearCallingIdentity();
6458 try {
6459 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6460 } finally {
6461 Binder.restoreCallingIdentity(identity);
6462 }
6463 }
6464
6465 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006466 * Enable/Disable E-UTRA-NR Dual Connectivity
6467 * @param subId subscription id of the sim card
6468 * @param nrDualConnectivityState expected NR dual connectivity state
6469 * This can be passed following states
6470 * <ol>
6471 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6472 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6473 * <li>Disable NR dual connectivity and force secondary cell to be released
6474 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6475 * </ol>
6476 * @return operation result.
6477 */
6478 @Override
6479 public int setNrDualConnectivityState(int subId,
6480 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6482 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006483 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006484 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6485 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6486 }
6487
Sooraj Sasindran37444802020-08-11 10:40:43 -07006488 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6489 final long identity = Binder.clearCallingIdentity();
6490 try {
6491 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6492 nrDualConnectivityState, subId,
6493 workSource);
6494 if (DBG) log("enableNRDualConnectivity result: " + result);
6495 return result;
6496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
6499 }
6500
6501 /**
6502 * Is E-UTRA-NR Dual Connectivity enabled
6503 * @return true if dual connectivity is enabled else false
6504 */
6505 @Override
6506 public boolean isNrDualConnectivityEnabled(int subId) {
6507 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006508 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006509 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006510 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006511 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6512 return false;
6513 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006514 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6515 final long identity = Binder.clearCallingIdentity();
6516 try {
6517 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6518 null, subId, workSource);
6519 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6520 return isEnabled;
6521 } finally {
6522 Binder.restoreCallingIdentity(identity);
6523 }
6524 }
6525
6526 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006527 * Set the allowed network types of the device and
6528 * provide the reason triggering the allowed network change.
6529 *
6530 * @param subId the id of the subscription.
6531 * @param reason the reason the allowed network type change is taking place
6532 * @param allowedNetworkTypes the allowed network types.
6533 * @return true on success; false on any failure.
6534 */
6535 @Override
6536 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006537 @TelephonyManager.AllowedNetworkTypesReason int reason,
6538 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6540 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006541 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006542 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6543 return false;
6544 }
6545 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6546 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006547 return false;
6548 }
6549
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006550 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6551 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6552
6553
6554 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6555 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6556 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006557 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006558
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006559 final long identity = Binder.clearCallingIdentity();
6560 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006561 Boolean success = (Boolean) sendRequest(
6562 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6563 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6564
6565 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6566 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006567 } finally {
6568 Binder.restoreCallingIdentity(identity);
6569 }
6570 }
6571
6572 /**
Miaoa84611c2019-03-15 09:21:10 +08006573 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006574 *
Miaoa84611c2019-03-15 09:21:10 +08006575 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006576 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006577 * @hide
6578 */
6579 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006580 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006581 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006583 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584 try {
Miaoa84611c2019-03-15 09:21:10 +08006585 if (phone != null) {
6586 return phone.hasMatchedTetherApnSetting();
6587 } else {
6588 return false;
6589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 } finally {
6591 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006592 }
Junda Liu475951f2014-11-07 16:45:03 -08006593 }
6594
6595 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006596 * Enable or disable always reporting signal strength changes from radio.
6597 *
6598 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6599 */
6600 @Override
6601 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6602 enforceModifyPermission();
6603 enforceSystemCaller();
6604
6605 final long identity = Binder.clearCallingIdentity();
6606 final Phone phone = getPhone(subId);
6607 try {
6608 if (phone != null) {
6609 if (DBG) {
6610 log("setAlwaysReportSignalStrength: subId=" + subId
6611 + " isEnable=" + isEnable);
6612 }
6613 phone.setAlwaysReportSignalStrength(isEnable);
6614 } else {
6615 loge("setAlwaysReportSignalStrength: no phone found for subId="
6616 + subId);
6617 }
6618 } finally {
6619 Binder.restoreCallingIdentity(identity);
6620 }
6621 }
6622
6623 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006624 * Get the user enabled state of Mobile Data.
6625 *
6626 * TODO: remove and use isUserDataEnabled.
6627 * This can't be removed now because some vendor codes
6628 * calls through ITelephony directly while they should
6629 * use TelephonyManager.
6630 *
6631 * @return true on enabled
6632 */
6633 @Override
6634 public boolean getDataEnabled(int subId) {
6635 return isUserDataEnabled(subId);
6636 }
6637
6638 /**
6639 * Get whether mobile data is enabled per user setting.
6640 *
6641 * There are other factors deciding whether mobile data is actually enabled, but they are
6642 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006643 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006644 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006645 *
6646 * @return {@code true} if data is enabled else {@code false}
6647 */
6648 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006649 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006650 try {
6651 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6652 null);
6653 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6655 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006656 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657
6658 final long identity = Binder.clearCallingIdentity();
6659 try {
6660 int phoneId = mSubscriptionController.getPhoneId(subId);
6661 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6662 Phone phone = PhoneFactory.getPhone(phoneId);
6663 if (phone != null) {
6664 boolean retVal = phone.isUserDataEnabled();
6665 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6666 return retVal;
6667 } else {
6668 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6669 return false;
6670 }
6671 } finally {
6672 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006673 }
6674 }
6675
6676 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006677 * Checks if the device is capable of mobile data by considering whether whether the
6678 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6679 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006680 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006681 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006682 */
6683 @Override
6684 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006685 try {
6686 try {
6687 mApp.enforceCallingOrSelfPermission(
6688 android.Manifest.permission.ACCESS_NETWORK_STATE,
6689 null);
6690 } catch (Exception e) {
6691 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6692 "isDataEnabled");
6693 }
6694 } catch (Exception e) {
6695 enforceReadPrivilegedPermission("isDataEnabled");
6696 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006697
6698 final long identity = Binder.clearCallingIdentity();
6699 try {
6700 int phoneId = mSubscriptionController.getPhoneId(subId);
6701 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6702 Phone phone = PhoneFactory.getPhone(phoneId);
6703 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006704 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6706 return retVal;
6707 } else {
6708 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6709 return false;
6710 }
6711 } finally {
6712 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006713 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006714 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006715
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006716 /**
6717 * Check if data is enabled for a specific reason
6718 * @param subId Subscription index
6719 * @param reason the reason the data enable change is taking place
6720 * @return {@code true} if the overall data is enabled; {@code false} if not.
6721 */
6722 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006723 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006724 @TelephonyManager.DataEnabledReason int reason) {
6725 try {
6726 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6727 null);
6728 } catch (Exception e) {
6729 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006730 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006731 }
6732
6733
6734 final long identity = Binder.clearCallingIdentity();
6735 try {
6736 int phoneId = mSubscriptionController.getPhoneId(subId);
6737 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006738 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006739 + " reason=" + reason);
6740 }
6741 Phone phone = PhoneFactory.getPhone(phoneId);
6742 if (phone != null) {
6743 boolean retVal;
6744 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6745 retVal = phone.isUserDataEnabled();
6746 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006747 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006748 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006749 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006750 return retVal;
6751 } else {
6752 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006753 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006754 + subId + " retVal=false");
6755 }
6756 return false;
6757 }
6758 } finally {
6759 Binder.restoreCallingIdentity(identity);
6760 }
6761 }
6762
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006763 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006764 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006765 if (uid == Process.PHONE_UID) {
6766 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6767 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006768 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6769 }
6770
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006771 //load access rules from carrier configs, and check those as well: b/139133814
6772 SubscriptionController subController = SubscriptionController.getInstance();
6773 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6774 || subController == null) return privilegeFromSim;
6775
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006776 PackageManager pkgMgr = phone.getContext().getPackageManager();
6777 String[] packages = pkgMgr.getPackagesForUid(uid);
6778
6779 final long identity = Binder.clearCallingIdentity();
6780 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006781 int subId = phone.getSubId();
6782 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6783 // A test override is in place for the privileges for this subId, so don't try to
6784 // read the subscription privileges.
6785 return privilegeFromSim;
6786 }
6787 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006788 SubscriptionManager subManager = (SubscriptionManager)
6789 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6790 for (String pkg : packages) {
6791 if (subManager.canManageSubscription(subInfo, pkg)) {
6792 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6793 }
6794 }
6795 return privilegeFromSim;
6796 } finally {
6797 Binder.restoreCallingIdentity(identity);
6798 }
6799 }
6800
6801 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6802 String pkgName) {
6803 //load access rules from carrier configs, and check those as well: b/139133814
6804 SubscriptionController subController = SubscriptionController.getInstance();
6805 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6806 || subController == null) return privilegeFromSim;
6807
6808 final long identity = Binder.clearCallingIdentity();
6809 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006810 int subId = phone.getSubId();
6811 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6812 // A test override is in place for the privileges for this subId, so don't try to
6813 // read the subscription privileges.
6814 return privilegeFromSim;
6815 }
6816 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006817 SubscriptionManager subManager = (SubscriptionManager)
6818 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6819 return subManager.canManageSubscription(subInfo, pkgName)
6820 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6821 } finally {
6822 Binder.restoreCallingIdentity(identity);
6823 }
6824 }
6825
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006826 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006827 public int getCarrierPrivilegeStatus(int subId) {
6828 final Phone phone = getPhone(subId);
6829 if (phone == null) {
6830 loge("getCarrierPrivilegeStatus: Invalid subId");
6831 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6832 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006833 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6834 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006835 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006836 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6837 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006838
6839 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006840 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006841 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006842 }
Junda Liu29340342014-07-10 15:23:27 -07006843
6844 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006845 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006846 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006847 final Phone phone = getPhone(subId);
6848 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006849 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006850 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6851 }
6852 UiccProfile profile =
6853 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6854 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006855 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006856 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6857 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006858 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006859 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006860 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006861 }
6862
6863 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006864 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006865 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006866 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006867 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006868 }
6869
6870 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006871 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6872 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006873 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006874 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6875 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006876 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006877 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006878 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006879 }
6880
6881 @Override
6882 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006883 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006884 if (TextUtils.isEmpty(pkgName))
6885 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006886 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6887 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006888 UiccPort port = UiccController.getInstance().getUiccPort(i);
6889 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006890 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006891 continue;
6892 }
6893
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006894 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006895 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006896 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006897 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6898 break;
6899 }
6900 }
6901
6902 return result;
Junda Liu29340342014-07-10 15:23:27 -07006903 }
Derek Tan89e89d42014-07-08 17:00:10 -07006904
6905 @Override
Junda Liue64de782015-04-16 17:19:16 -07006906 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006907 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006908 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6909 loge("phoneId " + phoneId + " is not valid.");
6910 return null;
6911 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006912 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6913 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006914 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006915 return null ;
6916 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006917 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006918 }
6919
Amith Yamasani6e118872016-02-19 12:53:51 -08006920 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006921 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006922 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006923 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006924 List<String> privilegedPackages = new ArrayList<>();
6925 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006926 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006927 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006928 if (port != null) {
6929 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006930 if (packages == null) {
6931 // Only check packages in user 0 for now
6932 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006933 PackageManager.MATCH_DISABLED_COMPONENTS
6934 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006935 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006936 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006937 }
6938 for (int p = packages.size() - 1; p >= 0; p--) {
6939 PackageInfo pkgInfo = packages.get(p);
6940 if (pkgInfo != null && pkgInfo.packageName != null
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006941 && port.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006942 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006943 privilegedPackages.add(pkgInfo.packageName);
6944 }
6945 }
6946 }
6947 }
6948 return privilegedPackages;
6949 }
6950
chen xuf7e9fe82019-05-09 19:31:02 -07006951 @Override
6952 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006953 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6954
6955 final long identity = Binder.clearCallingIdentity();
6956
chen xuf7e9fe82019-05-09 19:31:02 -07006957 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006958 try {
6959 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6960 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6961 }
6962 } finally {
6963 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006964 }
6965 return privilegedPackages;
6966 }
6967
Wink Savilleb564aae2014-10-23 10:18:09 -07006968 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006969 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006970 UiccPort port = phone == null ? null : phone.getUiccPort();
6971 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006972 return null;
6973 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006974 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006975 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006976 return null;
6977 }
6978 return iccId;
6979 }
6980
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006981 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006982 public void setCallComposerStatus(int subId, int status) {
6983 enforceModifyPermission();
6984
6985 final long identity = Binder.clearCallingIdentity();
6986 try {
6987 Phone phone = getPhone(subId);
6988 if (phone != null) {
6989 Phone defaultPhone = phone.getImsPhone();
6990 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6991 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6992 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006993 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6994 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006995 }
6996 }
Shuo Qian284ae752020-12-22 19:10:14 -08006997 } catch (ImsException e) {
6998 throw new ServiceSpecificException(e.getCode());
6999 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007000 Binder.restoreCallingIdentity(identity);
7001 }
7002 }
7003
7004 @Override
7005 public int getCallComposerStatus(int subId) {
7006 enforceReadPrivilegedPermission("getCallComposerStatus");
7007
7008 final long identity = Binder.clearCallingIdentity();
7009 try {
7010 Phone phone = getPhone(subId);
7011 if (phone != null) {
7012 Phone defaultPhone = phone.getImsPhone();
7013 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7014 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7015 return imsPhone.getCallComposerStatus();
7016 }
7017 }
7018 } finally {
7019 Binder.restoreCallingIdentity(identity);
7020 }
7021 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7022 }
7023
7024 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007025 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7026 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007027 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007028 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007030 final long identity = Binder.clearCallingIdentity();
7031 try {
7032 final String iccId = getIccId(subId);
7033 final Phone phone = getPhone(subId);
7034 if (phone == null) {
7035 return false;
7036 }
7037 final String subscriberId = phone.getSubscriberId();
7038
7039 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007040 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041 + subscriberId + " to " + number);
7042 }
7043
7044 if (TextUtils.isEmpty(iccId)) {
7045 return false;
7046 }
7047
7048 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7049
7050 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7051 if (alphaTag == null) {
7052 editor.remove(alphaTagPrefKey);
7053 } else {
7054 editor.putString(alphaTagPrefKey, alphaTag);
7055 }
7056
7057 // Record both the line number and IMSI for this ICCID, since we need to
7058 // track all merged IMSIs based on line number
7059 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7060 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7061 if (number == null) {
7062 editor.remove(numberPrefKey);
7063 editor.remove(subscriberPrefKey);
7064 } else {
7065 editor.putString(numberPrefKey, number);
7066 editor.putString(subscriberPrefKey, subscriberId);
7067 }
7068
7069 editor.commit();
7070 return true;
7071 } finally {
7072 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007073 }
Derek Tan7226c842014-07-02 17:42:23 -07007074 }
7075
7076 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007077 public String getLine1NumberForDisplay(int subId, String callingPackage,
7078 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007079 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007080 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007081 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007082 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007083 return null;
7084 }
Derek Tan97ebb422014-09-05 16:55:38 -07007085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007086 final long identity = Binder.clearCallingIdentity();
7087 try {
7088 String iccId = getIccId(subId);
7089 if (iccId != null) {
7090 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7091 if (DBG_MERGE) {
7092 log("getLine1NumberForDisplay returning "
7093 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7094 }
7095 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007096 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7098 return null;
7099 } finally {
7100 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007101 }
Derek Tan7226c842014-07-02 17:42:23 -07007102 }
7103
7104 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007105 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7106 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007107 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007108 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007109 return null;
7110 }
Derek Tan97ebb422014-09-05 16:55:38 -07007111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007112 final long identity = Binder.clearCallingIdentity();
7113 try {
7114 String iccId = getIccId(subId);
7115 if (iccId != null) {
7116 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7117 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7118 }
7119 return null;
7120 } finally {
7121 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007122 }
Derek Tan7226c842014-07-02 17:42:23 -07007123 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007124
7125 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007126 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7127 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007128 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7129 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007131 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007132 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007133 return null;
7134 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007135
Jordan Liub49b04b2019-05-06 14:45:15 -07007136 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7137 // the process, where TelephonyManager was instantiated.
7138 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007139 final long identity = Binder.clearCallingIdentity();
7140 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007141 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007142 final TelephonyManager tele = TelephonyManager.from(context);
7143 final SubscriptionManager sub = SubscriptionManager.from(context);
7144
7145 // Figure out what subscribers are currently active
7146 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147
Jordan Liub49b04b2019-05-06 14:45:15 -07007148 // Only consider subs which match the current subId
7149 // This logic can be simplified. See b/131189269 for progress.
7150 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007151 activeSubscriberIds.add(tele.getSubscriberId(subId));
7152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007153
7154 // First pass, find a number override for an active subscriber
7155 String mergeNumber = null;
7156 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7157 for (String key : prefs.keySet()) {
7158 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7159 final String subscriberId = (String) prefs.get(key);
7160 if (activeSubscriberIds.contains(subscriberId)) {
7161 final String iccId = key.substring(
7162 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7163 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7164 mergeNumber = (String) prefs.get(numberKey);
7165 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007166 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007167 + " for active subscriber " + subscriberId);
7168 }
7169 if (!TextUtils.isEmpty(mergeNumber)) {
7170 break;
7171 }
7172 }
7173 }
7174 }
7175
7176 // Shortcut when no active merged subscribers
7177 if (TextUtils.isEmpty(mergeNumber)) {
7178 return null;
7179 }
7180
7181 // Second pass, find all subscribers under that line override
7182 final ArraySet<String> result = new ArraySet<>();
7183 for (String key : prefs.keySet()) {
7184 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7185 final String number = (String) prefs.get(key);
7186 if (mergeNumber.equals(number)) {
7187 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7188 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7189 final String subscriberId = (String) prefs.get(subscriberKey);
7190 if (!TextUtils.isEmpty(subscriberId)) {
7191 result.add(subscriberId);
7192 }
7193 }
7194 }
7195 }
7196
7197 final String[] resultArray = result.toArray(new String[result.size()]);
7198 Arrays.sort(resultArray);
7199 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007200 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7202 }
7203 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007204 } finally {
7205 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007206 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007207 }
7208
7209 @Override
zoey chen38003472019-12-13 17:16:31 +08007210 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7211 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007212
7213 final long identity = Binder.clearCallingIdentity();
7214 try {
7215 final TelephonyManager telephonyManager = mApp.getSystemService(
7216 TelephonyManager.class);
7217 String subscriberId = telephonyManager.getSubscriberId(subId);
7218 if (subscriberId == null) {
7219 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007220 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007221 + subId);
7222 }
7223 return null;
7224 }
7225
7226 final SubscriptionInfo info = SubscriptionController.getInstance()
7227 .getSubscriptionInfo(subId);
7228 final ParcelUuid groupUuid = info.getGroupUuid();
7229 // If it doesn't belong to any group, return just subscriberId of itself.
7230 if (groupUuid == null) {
7231 return new String[]{subscriberId};
7232 }
7233
7234 // Get all subscriberIds from the group.
7235 final List<String> mergedSubscriberIds = new ArrayList<>();
7236 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007237 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007238 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007239 for (SubscriptionInfo subInfo : groupInfos) {
7240 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7241 if (subscriberId != null) {
7242 mergedSubscriberIds.add(subscriberId);
7243 }
7244 }
7245
7246 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7247 } finally {
7248 Binder.restoreCallingIdentity(identity);
7249
7250 }
7251 }
7252
7253 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007254 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007255 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007256 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007257
7258 final long identity = Binder.clearCallingIdentity();
7259 try {
7260 final Phone phone = getPhone(subId);
7261 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7262 } finally {
7263 Binder.restoreCallingIdentity(identity);
7264 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007265 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007266
7267 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007268 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007269 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7270 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007271 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7272 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007273
7274 final long identity = Binder.clearCallingIdentity();
7275 try {
7276 final Phone phone = getPhone(subId);
7277 if (phone == null) {
7278 return false;
7279 }
7280 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7281 cdmaNonRoamingList);
7282 } finally {
7283 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007284 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007285 }
7286
7287 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007288 @Deprecated
7289 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7290 enforceModifyPermission();
7291
7292 int returnValue = 0;
7293 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007294 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007295 if(result.exception == null) {
7296 if (result.result != null) {
7297 byte[] responseData = (byte[])(result.result);
7298 if(responseData.length > oemResp.length) {
7299 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7300 responseData.length + "bytes. Buffer Size is " +
7301 oemResp.length + "bytes.");
7302 }
7303 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7304 returnValue = responseData.length;
7305 }
7306 } else {
7307 CommandException ex = (CommandException) result.exception;
7308 returnValue = ex.getCommandError().ordinal();
7309 if(returnValue > 0) returnValue *= -1;
7310 }
7311 } catch (RuntimeException e) {
7312 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7313 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7314 if(returnValue > 0) returnValue *= -1;
7315 }
7316
7317 return returnValue;
7318 }
7319
7320 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007321 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007322 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007323 try {
7324 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007325 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007326 mApp, phone.getSubId(), "getRadioAccessFamily");
7327 } catch (SecurityException e) {
7328 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7329 throw e;
7330 }
chen xub97461a2018-10-26 14:17:57 -07007331 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007332 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007333 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007334 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 final long identity = Binder.clearCallingIdentity();
7336 try {
chen xub97461a2018-10-26 14:17:57 -07007337 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007338 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007339 mApp, phone.getSubId(), "getRadioAccessFamily");
7340 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341 } finally {
7342 Binder.restoreCallingIdentity(identity);
7343 }
chen xub97461a2018-10-26 14:17:57 -07007344 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007345 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007346
7347 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007348 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007349 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007350 try {
7351 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7352 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007353 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007354 }
7355 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007356 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007357 }
7358 RoleManager rm = mApp.getSystemService(RoleManager.class);
7359 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7360 if (!dialerRoleHolders.contains(callingPackage)) {
7361 throw new SecurityException("App must be the dialer role holder to"
7362 + " upload a call composer pic");
7363 }
7364
7365 Executors.newSingleThreadExecutor().execute(() -> {
7366 ByteArrayOutputStream output = new ByteArrayOutputStream(
7367 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7368 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7369 boolean readUntilEnd = false;
7370 int totalBytesRead = 0;
7371 byte[] buffer = new byte[16 * 1024];
7372 while (true) {
7373 int numRead;
7374 try {
7375 numRead = input.read(buffer);
7376 } catch (IOException e) {
7377 try {
7378 fd.checkError();
7379 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7380 null);
7381 } catch (IOException e1) {
7382 // This means that the other side closed explicitly with an error. If this
7383 // happens, log and ignore.
7384 loge("Remote end of call composer picture pipe closed: " + e1);
7385 }
7386 break;
7387 }
7388 if (numRead == -1) {
7389 readUntilEnd = true;
7390 break;
7391 }
7392 totalBytesRead += numRead;
7393 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7394 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7395 try {
7396 input.close();
7397 } catch (IOException e) {
7398 // ignore
7399 }
7400 break;
7401 }
7402 output.write(buffer, 0, numRead);
7403 }
7404 // Generally, the remote end will close the file descriptors. The only case where we
7405 // close is above, where the picture size is too big.
7406
7407 try {
7408 fd.checkError();
7409 } catch (IOException e) {
7410 loge("Remote end for call composer closed with an error: " + e);
7411 return;
7412 }
7413
Hall Liuaa4211e2021-01-20 15:43:39 -08007414 if (!readUntilEnd) {
7415 loge("Did not finish reading entire image; aborting");
7416 return;
7417 }
Hall Liu82694d52020-12-11 18:22:04 -08007418
Hall Liuaa4211e2021-01-20 15:43:39 -08007419 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7420 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7421 new CallComposerPictureTransfer.Factory() {},
7422 imageData,
7423 (result) -> {
7424 if (result.first != null) {
7425 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7426 Bundle outputResult = new Bundle();
7427 outputResult.putParcelable(
7428 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7429 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7430 outputResult);
7431 } else {
7432 callback.send(result.second, null);
7433 }
7434 }
7435 );
Hall Liu82694d52020-12-11 18:22:04 -08007436 });
7437 }
7438
7439 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007440 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007441 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007442 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443
7444 final long identity = Binder.clearCallingIdentity();
7445 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007446 ImsManager.getInstance(defaultPhone.getContext(),
7447 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007448 } finally {
7449 Binder.restoreCallingIdentity(identity);
7450 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007451 }
7452
7453 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007454 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007455 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007456 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7457 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007458 return false;
7459 }
Svet Ganovb320e182015-04-16 12:30:10 -07007460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 final long identity = Binder.clearCallingIdentity();
7462 try {
7463 // Check the user preference and the system-level IMS setting. Even if the user has
7464 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7465 // In the long run, we may instead need to check if there exists a connection service
7466 // which can support video calling.
7467 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007468 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007469 return imsManager.isVtEnabledByPlatform()
7470 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7471 && imsManager.isVtEnabledByUser();
7472 } finally {
7473 Binder.restoreCallingIdentity(identity);
7474 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007475 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007476
Andrew Leea1239f22015-03-02 17:44:07 -08007477 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007478 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7479 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007481 mApp, subId, callingPackage, callingFeatureId,
7482 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 return false;
7484 }
7485
7486 final long identity = Binder.clearCallingIdentity();
7487 try {
7488 CarrierConfigManager configManager =
7489 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007490 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
7494 }
Andrew Leea1239f22015-03-02 17:44:07 -08007495 }
7496
7497 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007498 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007500 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 return false;
7502 }
7503
7504 final long identity = Binder.clearCallingIdentity();
7505 try {
7506 CarrierConfigManager configManager =
7507 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007508 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7510 } finally {
7511 Binder.restoreCallingIdentity(identity);
7512 }
Andrew Leea1239f22015-03-02 17:44:07 -08007513 }
7514
Andrew Lee9431b832015-03-09 18:46:45 -07007515 @Override
7516 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007517 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007518 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007519 }
7520
7521 @Override
7522 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 final long identity = Binder.clearCallingIdentity();
7524 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007525 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526 } finally {
7527 Binder.restoreCallingIdentity(identity);
7528 }
Andrew Lee9431b832015-03-09 18:46:45 -07007529 }
7530
Hall Liuf6668912018-10-31 17:05:23 -07007531 /**
7532 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7533 * support for the feature and device firmware support.
7534 *
7535 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7536 */
7537 @Override
7538 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007540 final Phone phone = getPhone(subscriptionId);
7541 if (phone == null) {
7542 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7543 return false;
7544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007546 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7548 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007549 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 return isCarrierSupported && isDeviceSupported;
7551 } finally {
7552 Binder.restoreCallingIdentity(identity);
7553 }
Hall Liu98187582018-01-22 19:15:32 -08007554 }
7555
Hall Liuf6668912018-10-31 17:05:23 -07007556 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007557 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7558 * RTT setting, will return true if the device and carrier both support RTT.
7559 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007560 */
7561 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562 final long identity = Binder.clearCallingIdentity();
7563 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007564 boolean isRttSupported = isRttSupported(subscriptionId);
7565 boolean isUserRttSettingOn = Settings.Secure.getInt(
7566 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7567 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7568 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7569 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570 } finally {
7571 Binder.restoreCallingIdentity(identity);
7572 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007573 }
7574
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007575 @Deprecated
7576 @Override
7577 public String getDeviceId(String callingPackage) {
7578 return getDeviceIdWithFeature(callingPackage, null);
7579 }
7580
Sanket Padawe7310cc72015-01-14 09:53:20 -08007581 /**
7582 * Returns the unique device ID of phone, for example, the IMEI for
7583 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7584 *
7585 * <p>Requires Permission:
7586 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7587 */
7588 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007589 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007590 try {
7591 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7592 } catch (SecurityException se) {
7593 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7594 throw new SecurityException("Package " + callingPackage + " does not belong to "
7595 + Binder.getCallingUid());
7596 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007597 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007598 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007599 return null;
7600 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007601 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007602 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007603 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007604 return null;
7605 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007606
7607 final long identity = Binder.clearCallingIdentity();
7608 try {
7609 return phone.getDeviceId();
7610 } finally {
7611 Binder.restoreCallingIdentity(identity);
7612 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007613 }
7614
Ping Sunc67b7c22016-03-02 19:16:45 +08007615 /**
7616 * {@hide}
7617 * Returns the IMS Registration Status on a particular subid
7618 *
7619 * @param subId
7620 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007621 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007622 Phone phone = getPhone(subId);
7623 if (phone != null) {
7624 return phone.isImsRegistered();
7625 } else {
7626 return false;
7627 }
7628 }
7629
Santos Cordon7a1885b2015-02-03 11:15:19 -08007630 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007631 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007632 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007634 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007635 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7636 }
7637 final long identity = Binder.clearCallingIdentity();
7638 try {
7639 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7640 } finally {
7641 Binder.restoreCallingIdentity(identity);
7642 }
7643 }
7644
7645 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007646 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007647 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007648 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007649 mApp,
7650 subscriptionId,
7651 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007652 final long identity = Binder.clearCallingIdentity();
7653 try {
7654 Phone phone = getPhone(subscriptionId);
7655 if (phone == null) {
7656 return null;
7657 }
7658 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7659 } finally {
7660 Binder.restoreCallingIdentity(identity);
7661 }
7662 }
7663
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007664 /**
7665 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007666 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007667 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007668 final long identity = Binder.clearCallingIdentity();
7669 try {
7670 Phone phone = getPhone(subId);
7671 if (phone != null) {
7672 return phone.isWifiCallingEnabled();
7673 } else {
7674 return false;
7675 }
7676 } finally {
7677 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007678 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007679 }
7680
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007681 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007682 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007683 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007684 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 final long identity = Binder.clearCallingIdentity();
7686 try {
7687 Phone phone = getPhone(subId);
7688 if (phone != null) {
7689 return phone.isVideoEnabled();
7690 } else {
7691 return false;
7692 }
7693 } finally {
7694 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007695 }
7696 }
7697
7698 /**
7699 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7700 * defined in {@link ImsRegistrationImplBase}.
7701 */
7702 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007703 final long identity = Binder.clearCallingIdentity();
7704 try {
7705 Phone phone = getPhone(subId);
7706 if (phone != null) {
7707 return phone.getImsRegistrationTech();
7708 } else {
7709 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7710 }
7711 } finally {
7712 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007713 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007714 }
7715
Stuart Scott8eef64f2015-04-08 15:13:54 -07007716 @Override
7717 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007718 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007719 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7720 return;
7721 }
Kai Shif70f46f2021-03-03 13:59:46 -08007722 Phone defaultPhone = getDefaultPhone();
7723 if (defaultPhone != null) {
7724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7725 mApp, getDefaultPhone().getSubId(), "factoryReset");
7726 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007727 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007728
Svet Ganovcc087f82015-05-12 20:35:54 -07007729 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007730 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7731 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007732 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007733 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007734 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007735 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007736 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007737 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007738 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007739 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007740 // There has been issues when Sms raw table somehow stores orphan
7741 // fragments. They lead to garbled message when new fragments come
7742 // in and combined with those stale ones. In case this happens again,
7743 // user can reset all network settings which will clean up this table.
7744 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007745 // Clean up IMS settings as well here.
7746 int slotId = getSlotIndex(subId);
7747 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7748 ImsManager.getInstance(mApp, slotId).factoryReset();
7749 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007750
Kai Shif70f46f2021-03-03 13:59:46 -08007751 if (defaultPhone == null) {
7752 return;
7753 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007754 // Erase modem config if erase modem on network setting is enabled.
7755 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7756 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7757 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007758 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007759 }
Kai Shif70f46f2021-03-03 13:59:46 -08007760
7761 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007762 } finally {
7763 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007764 }
7765 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007766
SongFerngWangfd89b102021-05-27 22:44:54 +08007767 @VisibleForTesting
7768 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7769 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7770 return;
7771 }
7772 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7773 RILConstants.PREFERRED_NETWORK_MODE);
7774 SubscriptionManager.setSubscriptionProperty(subId,
7775 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7776 "user=" + defaultNetworkType);
7777 phone.loadAllowedNetworksFromSubscriptionDatabase();
7778 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7779 defaultNetworkType, null);
7780 }
7781
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007782 private void cleanUpSmsRawTable(Context context) {
7783 ContentResolver resolver = context.getContentResolver();
7784 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7785 resolver.delete(uri, null, null);
7786 }
7787
Narayan Kamath1c496c22015-04-16 14:40:19 +01007788 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007789 public String getSimLocaleForSubscriber(int subId) {
7790 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7791 final Phone phone = getPhone(subId);
7792 if (phone == null) {
7793 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007794 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007795 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007796 final long identity = Binder.clearCallingIdentity();
7797 try {
chen xu5d3637b2019-01-21 23:31:38 -08007798 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007799 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007800 if (info == null) {
7801 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7802 return null;
7803 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007804 // Try and fetch the locale from the carrier properties or from the SIM language
7805 // preferences (EF-PL and EF-LI)...
7806 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007807 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007808 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7809 if (localeFromDefaultSim != null) {
7810 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7811 if (DBG) log("Using locale from subId: " + subId + " locale: "
7812 + localeFromDefaultSim);
7813 return localeFromDefaultSim.toLanguageTag();
7814 } else {
7815 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007816 }
7817 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007818
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007819 // The SIM language preferences only store a language (e.g. fr = French), not an
7820 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7821 // the SIM and carrier preferences does not include a country we add the country
7822 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007823 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007824 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007825 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007826 return mccLocale.toLanguageTag();
7827 }
7828
7829 if (DBG) log("No locale found - returning null");
7830 return null;
7831 } finally {
7832 Binder.restoreCallingIdentity(identity);
7833 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007834 }
7835
7836 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007837 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007838 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007839 }
7840
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007841 /**
7842 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7843 */
7844 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007845 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007846 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007847 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007848
Chenjie Yu1ba97252018-01-11 18:16:20 -08007849 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007850 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007851
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007852 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007853 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7854 * representing the state of the modem.
7855 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007856 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7857 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007858 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007859 */
7860 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007861 public void requestModemActivityInfo(ResultReceiver result) {
7862 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007863 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007864
7865 final long identity = Binder.clearCallingIdentity();
7866 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007867 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 } finally {
7869 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007870 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007871 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007872
Siddharth Rayb8114062018-06-17 15:02:38 -07007873 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7874 // less than total activity duration.
7875 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7876 if (info == null) {
7877 return false;
7878 }
7879 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007880 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7881 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7882
Siddharth Rayb8114062018-06-17 15:02:38 -07007883 return (info.isValid()
7884 && (info.getSleepTimeMillis() <= activityDurationMs)
7885 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007886 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007887 && (totalTxTimeMs <= activityDurationMs));
7888 }
7889
Jack Yu85bd38a2015-11-09 11:34:32 -08007890 /**
7891 * {@hide}
7892 * Returns the service state information on specified subscription.
7893 */
7894 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007895 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7896 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007897 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007898 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007899 return null;
7900 }
7901
Hall Liuf19c44f2018-11-27 14:38:17 -08007902 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7903 LocationAccessPolicy.checkLocationPermission(mApp,
7904 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7905 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007906 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007907 .setCallingPid(Binder.getCallingPid())
7908 .setCallingUid(Binder.getCallingUid())
7909 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007910 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007911 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007912 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7913 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007914 .build());
7915
7916 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7917 LocationAccessPolicy.checkLocationPermission(mApp,
7918 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7919 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007920 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007921 .setCallingPid(Binder.getCallingPid())
7922 .setCallingUid(Binder.getCallingUid())
7923 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007924 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007925 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007926 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7927 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007928 .build());
7929 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7930 boolean hasFinePermission =
7931 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7932 boolean hasCoarsePermission =
7933 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7934
Jack Yu479f40e2020-10-27 21:29:25 -07007935 final Phone phone = getPhone(subId);
7936 if (phone == null) {
7937 return null;
7938 }
7939
Jordan Liu0f2bc442020-11-18 16:47:37 -08007940 final long identity = Binder.clearCallingIdentity();
7941
Jack Yu479f40e2020-10-27 21:29:25 -07007942 boolean isCallingPackageDataService = phone.getDataServicePackages()
7943 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007944 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007945 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7946 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7947 Rlog.d(LOG_TAG,
7948 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7949 return null;
7950 }
7951
Hall Liuf19c44f2018-11-27 14:38:17 -08007952 ServiceState ss = phone.getServiceState();
7953
7954 // Scrub out the location info in ServiceState depending on what level of access
7955 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007956 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007957 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7958 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 } finally {
7960 Binder.restoreCallingIdentity(identity);
7961 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007962 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007963
7964 /**
7965 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7966 *
7967 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7968 * voicemail ringtone.
7969 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7970 * PhoneAccount.
7971 */
7972 @Override
7973 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007974 final long identity = Binder.clearCallingIdentity();
7975 try {
7976 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7977 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007978 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007979 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007981 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7982 } finally {
7983 Binder.restoreCallingIdentity(identity);
7984 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007985 }
7986
7987 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007988 * Sets the per-account voicemail ringtone.
7989 *
7990 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7991 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7992 *
7993 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7994 * voicemail ringtone.
7995 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7996 * PhoneAccount.
7997 */
7998 @Override
7999 public void setVoicemailRingtoneUri(String callingPackage,
8000 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008001 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008002 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008003 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8004 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8006 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8007 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008009
8010 final long identity = Binder.clearCallingIdentity();
8011 try {
8012 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8013 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008014 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008015 }
8016 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8017 } finally {
8018 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008019 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008020 }
8021
8022 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008023 * Returns whether vibration is set for voicemail notification in Phone settings.
8024 *
8025 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8026 * voicemail vibration setting.
8027 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8028 */
8029 @Override
8030 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008031 final long identity = Binder.clearCallingIdentity();
8032 try {
8033 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8034 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008035 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008036 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008038 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8039 } finally {
8040 Binder.restoreCallingIdentity(identity);
8041 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008042 }
8043
Youhan Wange64578a2016-05-02 15:32:42 -07008044 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008045 * Sets the per-account voicemail vibration.
8046 *
8047 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8048 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8049 *
8050 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8051 * voicemail vibration setting.
8052 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8053 * specific PhoneAccount.
8054 */
8055 @Override
8056 public void setVoicemailVibrationEnabled(String callingPackage,
8057 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008058 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008059 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008060 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8061 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8063 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8064 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008065 }
8066
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008067 final long identity = Binder.clearCallingIdentity();
8068 try {
8069 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8070 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008071 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008072 }
8073 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8074 } finally {
8075 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008076 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008077 }
8078
8079 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008080 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8081 *
8082 * @throws SecurityException if the caller does not have the required permission
8083 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008084 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008085 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008086 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008087 }
8088
8089 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008090 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8091 * permission.
8092 *
8093 * @throws SecurityException if the caller does not have the required permission
8094 */
8095 private void enforceSendSmsPermission() {
8096 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8097 }
8098
8099 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008100 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008101 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008102 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008103 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008104 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008105 final long identity = Binder.clearCallingIdentity();
8106 try {
8107 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008108 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008109 if (componentName == null) {
8110 throw new SecurityException(
8111 "Caller not current active visual voicemail package[null]");
8112 }
8113 String vvmPackage = componentName.getPackageName();
8114 if (!callingPackage.equals(vvmPackage)) {
8115 throw new SecurityException("Caller not current active visual voicemail package["
8116 + vvmPackage + "]");
8117 }
8118 } finally {
8119 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008120 }
8121 }
8122
8123 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008124 * Return the application ID for the app type.
8125 *
8126 * @param subId the subscription ID that this request applies to.
8127 * @param appType the uicc app type.
8128 * @return Application ID for specificied app type, or null if no uicc.
8129 */
8130 @Override
8131 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008132 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008133 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008134
8135 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008136 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008137 if (phone == null) {
8138 return null;
8139 }
8140 String aid = null;
8141 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008142 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008143 .getApplicationByType(appType).getAid();
8144 } catch (Exception e) {
8145 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8146 }
8147 return aid;
8148 } finally {
8149 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008150 }
Youhan Wange64578a2016-05-02 15:32:42 -07008151 }
8152
Youhan Wang4001d252016-05-11 10:29:41 -07008153 /**
8154 * Return the Electronic Serial Number.
8155 *
8156 * @param subId the subscription ID that this request applies to.
8157 * @return ESN or null if error.
8158 */
8159 @Override
8160 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008161 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008162 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008163
8164 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008165 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008166 if (phone == null) {
8167 return null;
8168 }
8169 String esn = null;
8170 try {
8171 esn = phone.getEsn();
8172 } catch (Exception e) {
8173 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8174 }
8175 return esn;
8176 } finally {
8177 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008178 }
Youhan Wang4001d252016-05-11 10:29:41 -07008179 }
8180
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008181 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008182 * Return the Preferred Roaming List Version.
8183 *
8184 * @param subId the subscription ID that this request applies to.
8185 * @return PRLVersion or null if error.
8186 */
8187 @Override
8188 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008189 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008190 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008191
8192 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008193 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008194 if (phone == null) {
8195 return null;
8196 }
8197 String cdmaPrlVersion = null;
8198 try {
8199 cdmaPrlVersion = phone.getCdmaPrlVersion();
8200 } catch (Exception e) {
8201 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8202 }
8203 return cdmaPrlVersion;
8204 } finally {
8205 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008206 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008207 }
8208
8209 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008210 * Get snapshot of Telephony histograms
8211 * @return List of Telephony histograms
8212 * @hide
8213 */
8214 @Override
8215 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8217 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008218
8219 final long identity = Binder.clearCallingIdentity();
8220 try {
8221 return RIL.getTelephonyRILTimingHistograms();
8222 } finally {
8223 Binder.restoreCallingIdentity(identity);
8224 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008225 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008226
8227 /**
8228 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008229 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8230 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008231 * Require system privileges. In the future we may add this to carrier APIs.
8232 *
Michele Berionne482f8202018-11-27 18:57:59 -08008233 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008234 */
8235 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008236 @TelephonyManager.SetCarrierRestrictionResult
8237 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008238 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008239 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008240
Michele Berionne482f8202018-11-27 18:57:59 -08008241 if (carrierRestrictionRules == null) {
8242 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008243 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008245 final long identity = Binder.clearCallingIdentity();
8246 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008247 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008248 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249 } finally {
8250 Binder.restoreCallingIdentity(identity);
8251 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008252 }
8253
8254 /**
8255 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008256 * Get the allowed carrier list and the excluded carrier list, including the priority between
8257 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008258 * Require system privileges. In the future we may add this to carrier APIs.
8259 *
Michele Berionne482f8202018-11-27 18:57:59 -08008260 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008261 */
8262 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008263 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008264 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008265 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008266
8267 final long identity = Binder.clearCallingIdentity();
8268 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008269 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8270 if (response instanceof CarrierRestrictionRules) {
8271 return (CarrierRestrictionRules) response;
8272 }
8273 // Response is an Exception of some kind,
8274 // which is signalled to the user as a NULL retval
8275 return null;
8276 } catch (Exception e) {
8277 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8278 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279 } finally {
8280 Binder.restoreCallingIdentity(identity);
8281 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008282 }
8283
fionaxu59545b42016-05-25 15:53:37 -07008284 /**
fionaxu59545b42016-05-25 15:53:37 -07008285 * Action set from carrier signalling broadcast receivers to enable/disable radio
8286 * @param subId the subscription ID that this action applies to.
8287 * @param enabled control enable or disable radio.
8288 * {@hide}
8289 */
8290 @Override
8291 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8292 enforceModifyPermission();
8293 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294
8295 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008296 if (phone == null) {
8297 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8298 return;
8299 }
8300 try {
8301 phone.carrierActionSetRadioEnabled(enabled);
8302 } catch (Exception e) {
8303 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008304 } finally {
8305 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008306 }
8307 }
8308
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008309 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008310 * Enable or disable Voice over NR (VoNR)
8311 * @param subId the subscription ID that this action applies to.
8312 * @param enabled enable or disable VoNR.
8313 * @return operation result.
8314 */
8315 @Override
8316 public int setVoNrEnabled(int subId, boolean enabled) {
8317 enforceModifyPermission();
8318 final Phone phone = getPhone(subId);
8319
8320 final long identity = Binder.clearCallingIdentity();
8321 if (phone == null) {
8322 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8323 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8324 }
8325
8326 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8327 try {
8328 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8329 workSource);
8330 if (DBG) log("setVoNrEnabled result: " + result);
8331 return result;
8332 } finally {
8333 Binder.restoreCallingIdentity(identity);
8334 }
8335 }
8336
8337 /**
8338 * Is voice over NR enabled
8339 * @return true if VoNR is enabled else false
8340 */
8341 @Override
8342 public boolean isVoNrEnabled(int subId) {
8343 enforceReadPrivilegedPermission("isVoNrEnabled");
8344 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8345 final long identity = Binder.clearCallingIdentity();
8346 try {
8347 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8348 null, subId, workSource);
8349 if (DBG) log("isVoNrEnabled: " + isEnabled);
8350 return isEnabled;
8351 } finally {
8352 Binder.restoreCallingIdentity(identity);
8353 }
8354 }
8355
8356 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008357 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8358 * network status based on which carrier apps could apply actions accordingly,
8359 * enable/disable default url handler for example.
8360 *
8361 * @param subId the subscription ID that this action applies to.
8362 * @param report control start/stop reporting the default network status.
8363 * {@hide}
8364 */
8365 @Override
8366 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8367 enforceModifyPermission();
8368 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369
8370 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008371 if (phone == null) {
8372 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8373 return;
8374 }
8375 try {
8376 phone.carrierActionReportDefaultNetworkStatus(report);
8377 } catch (Exception e) {
8378 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008379 } finally {
8380 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008381 }
8382 }
8383
8384 /**
fionaxud9622282017-07-17 17:51:30 -07008385 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8386 * @param subId the subscription ID that this action applies to.
8387 * {@hide}
8388 */
8389 @Override
8390 public void carrierActionResetAll(int subId) {
8391 enforceModifyPermission();
8392 final Phone phone = getPhone(subId);
8393 if (phone == null) {
8394 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8395 return;
8396 }
8397 try {
8398 phone.carrierActionResetAll();
8399 } catch (Exception e) {
8400 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8401 }
8402 }
8403
8404 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008405 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8406 * bug report is being generated.
8407 */
8408 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008409 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008410 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8411 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008412 writer.println("Permission Denial: can't dump Phone from pid="
8413 + Binder.getCallingPid()
8414 + ", uid=" + Binder.getCallingUid()
8415 + "without permission "
8416 + android.Manifest.permission.DUMP);
8417 return;
8418 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008419 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008420 }
Jack Yueb89b242016-06-22 13:27:47 -07008421
Brad Ebingerdac2f002018-04-03 15:17:52 -07008422 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008423 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8424 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8425 @NonNull String[] args) {
8426 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8427 this, in.getFileDescriptor(), out.getFileDescriptor(),
8428 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008429 }
8430
Jack Yueb89b242016-06-22 13:27:47 -07008431 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008432 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008433 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008434 * @param reason the reason the data enable change is taking place
8435 * @param enabled True if enabling the data, otherwise disabling.
8436 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008437 */
8438 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008439 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008440 boolean enabled) {
8441 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8442 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8443 try {
8444 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008445 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008446 } catch (SecurityException se) {
8447 enforceModifyPermission();
8448 }
8449 } else {
8450 enforceModifyPermission();
8451 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008452
8453 final long identity = Binder.clearCallingIdentity();
8454 try {
8455 Phone phone = getPhone(subId);
8456 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008457 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8458 phone.carrierActionSetMeteredApnsEnabled(enabled);
8459 } else {
8460 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008462 }
8463 } finally {
8464 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008465 }
8466 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008467
8468 /**
8469 * Get Client request stats
8470 * @return List of Client Request Stats
8471 * @hide
8472 */
8473 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008474 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8475 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008477 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008478 return null;
8479 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008480 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008482 final long identity = Binder.clearCallingIdentity();
8483 try {
8484 if (phone != null) {
8485 return phone.getClientRequestStats();
8486 }
8487
8488 return null;
8489 } finally {
8490 Binder.restoreCallingIdentity(identity);
8491 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008492 }
8493
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008494 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008495 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008496 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008497 }
Jack Yueb4124c2017-02-16 15:32:43 -08008498
8499 /**
Grace Chen70990072017-03-24 17:21:30 -07008500 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008501 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008502 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008503 * @param state State of SIM (power down, power up, pass through)
8504 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8505 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8506 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008507 *
8508 **/
8509 @Override
Grace Chen70990072017-03-24 17:21:30 -07008510 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008511 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008512 Phone phone = PhoneFactory.getPhone(slotIndex);
8513
vagdeviaf9a5b92018-08-15 16:01:53 -07008514 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8515
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008516 final long identity = Binder.clearCallingIdentity();
8517 try {
8518 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008519 phone.setSimPowerState(state, null, workSource);
8520 }
8521 } finally {
8522 Binder.restoreCallingIdentity(identity);
8523 }
8524 }
8525
8526 /**
8527 * Set SIM card power state.
8528 *
8529 * @param slotIndex SIM slot id.
8530 * @param state State of SIM (power down, power up, pass through)
8531 * @param callback callback to trigger after success or failure
8532 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8533 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8534 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8535 *
8536 **/
8537 @Override
8538 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8539 IIntegerConsumer callback) {
8540 enforceModifyPermission();
8541 Phone phone = PhoneFactory.getPhone(slotIndex);
8542
8543 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8544
8545 final long identity = Binder.clearCallingIdentity();
8546 try {
8547 if (phone != null) {
8548 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8549 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008550 }
8551 } finally {
8552 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008553 }
8554 }
Shuo Qiandd210312017-04-12 22:11:33 +00008555
Tyler Gunn65d45c22017-06-05 11:22:26 -07008556 private boolean isUssdApiAllowed(int subId) {
8557 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008558 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008559 if (configManager == null) {
8560 return false;
8561 }
8562 PersistableBundle pb = configManager.getConfigForSubId(subId);
8563 if (pb == null) {
8564 return false;
8565 }
8566 return pb.getBoolean(
8567 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8568 }
8569
Shuo Qiandd210312017-04-12 22:11:33 +00008570 /**
8571 * Check if phone is in emergency callback mode
8572 * @return true if phone is in emergency callback mode
8573 * @param subId sub id
8574 */
goneil9c5f4872017-12-05 14:07:56 -08008575 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008576 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008577 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008578 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008579
8580 final long identity = Binder.clearCallingIdentity();
8581 try {
8582 if (phone != null) {
8583 return phone.isInEcm();
8584 } else {
8585 return false;
8586 }
8587 } finally {
8588 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008589 }
8590 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008591
8592 /**
8593 * Get the current signal strength information for the given subscription.
8594 * Because this information is not updated when the device is in a low power state
8595 * it should not be relied-upon to be current.
8596 * @param subId Subscription index
8597 * @return the most recent cached signal strength info from the modem
8598 */
8599 @Override
8600 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008601 final long identity = Binder.clearCallingIdentity();
8602 try {
8603 Phone p = getPhone(subId);
8604 if (p == null) {
8605 return null;
8606 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008608 return p.getSignalStrength();
8609 } finally {
8610 Binder.restoreCallingIdentity(identity);
8611 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008612 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008613
Pengquan Meng77b7f132018-08-22 14:49:57 -07008614 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008615 * Get the current modem radio state for the given slot.
8616 * @param slotIndex slot index.
8617 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008618 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008619 * @return the current radio power state from the modem
8620 */
8621 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008622 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008623 Phone phone = PhoneFactory.getPhone(slotIndex);
8624 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8626 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008627 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8628 }
8629
8630 final long identity = Binder.clearCallingIdentity();
8631 try {
8632 return phone.getRadioPowerState();
8633 } finally {
8634 Binder.restoreCallingIdentity(identity);
8635 }
8636 }
8637 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8638 }
8639
8640 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008641 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8642 *
8643 * <p>Requires one of the following permissions:
8644 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8645 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8646 * privileges.
8647 *
8648 * @param subId subscription id
8649 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8650 * {@code false}.
8651 */
8652 @Override
8653 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008654 try {
8655 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8656 null);
8657 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008658 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008659 mApp, subId, "isDataRoamingEnabled");
8660 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008661
Pengquan Menga1bb6272018-09-06 09:59:22 -07008662 boolean isEnabled = false;
8663 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008664 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008665 Phone phone = getPhone(subId);
8666 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008667 } finally {
8668 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008669 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008670 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008671 }
8672
8673
8674 /**
8675 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8676 *
8677 * <p> Requires permission:
8678 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8679 * privileges.
8680 *
8681 * @param subId subscription id
8682 * @param isEnabled {@code true} means enable, {@code false} means disable.
8683 */
8684 @Override
8685 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8687 mApp, subId, "setDataRoamingEnabled");
8688
Pengquan Menga1bb6272018-09-06 09:59:22 -07008689 final long identity = Binder.clearCallingIdentity();
8690 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008691 Phone phone = getPhone(subId);
8692 if (phone != null) {
8693 phone.setDataRoamingEnabled(isEnabled);
8694 }
8695 } finally {
8696 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008697 }
8698 }
8699
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008700 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008701 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008702 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008703 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008704 mApp, subId, "isManualNetworkSelectionAllowed");
8705
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008706 boolean isAllowed = true;
8707 final long identity = Binder.clearCallingIdentity();
8708 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008709 Phone phone = getPhone(subId);
8710 if (phone != null) {
8711 isAllowed = phone.isCspPlmnEnabled();
8712 }
8713 } finally {
8714 Binder.restoreCallingIdentity(identity);
8715 }
8716 return isAllowed;
8717 }
8718
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008719 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8720 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8721 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8722 // Update each UiccPort object based on privilege access
8723 UiccPort[] uiccPorts = card.getUiccPortList();
8724 for (UiccPort port : uiccPorts) {
8725 UiccProfile profile = port.getUiccProfile();
8726 if (profile == null ||
8727 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8728 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8729 return false;
8730 }
8731 }
8732 return true;
8733 }
8734
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008735 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008736 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008737 // Verify that tha callingPackage belongs to the calling UID
8738 mApp.getSystemService(AppOpsManager.class)
8739 .checkPackage(Binder.getCallingUid(), callingPackage);
8740
Jordan Liu1e142fc2019-04-22 15:10:43 -07008741 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008742 try {
8743 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008744 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008745 } catch (SecurityException e) {
8746 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8747 // has carrier privileges on an active UICC
8748 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8749 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008750 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008751 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008752 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008753
8754 final long identity = Binder.clearCallingIdentity();
8755 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008756 UiccController uiccController = UiccController.getInstance();
8757 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008758 if (hasReadPermission) {
8759 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008760 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008761
8762 // Remove private info if the caller doesn't have access
8763 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8764 for (UiccCardInfo cardInfo : cardInfos) {
8765 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8766 // is available
8767 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008768 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8769 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8770 if (card == null || card.getUiccPortList().length == 0) {
8771 // assume no access if the card or ports are unavailable
Jordan Liu1e142fc2019-04-22 15:10:43 -07008772 filteredInfos.add(cardInfo.getUnprivileged());
8773 continue;
8774 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008775
8776 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008777 filteredInfos.add(cardInfo);
8778 } else {
8779 filteredInfos.add(cardInfo.getUnprivileged());
8780 }
8781 }
8782 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008783 } finally {
8784 Binder.restoreCallingIdentity(identity);
8785 }
8786 }
8787
8788 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008789 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008790 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008791
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008792 final long identity = Binder.clearCallingIdentity();
8793 try {
8794 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8795 if (slots == null) {
8796 Rlog.i(LOG_TAG, "slots is null.");
8797 return null;
8798 }
8799
8800 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8801 for (int i = 0; i < slots.length; i++) {
8802 UiccSlot slot = slots[i];
8803 if (slot == null) {
8804 continue;
8805 }
8806
Jordan Liu7be7e652019-05-06 18:55:02 +00008807 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008808 UiccCard card = slot.getUiccCard();
8809 if (card != null) {
8810 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008811 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008812 cardId = slot.getEid();
8813 if (TextUtils.isEmpty(cardId)) {
8814 cardId = slot.getIccId();
8815 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008816 }
8817
Jordan Liu857451f2019-05-09 16:35:35 -07008818 if (cardId != null) {
8819 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8820 // if cardId is an EID, it's all digits so this is fine
8821 cardId = IccUtils.stripTrailingFs(cardId);
8822 }
8823
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008824 int cardState = 0;
8825 switch (slot.getCardState()) {
8826 case CARDSTATE_ABSENT:
8827 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8828 break;
8829 case CARDSTATE_PRESENT:
8830 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8831 break;
8832 case CARDSTATE_ERROR:
8833 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8834 break;
8835 case CARDSTATE_RESTRICTED:
8836 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8837 break;
8838 default:
8839 break;
8840
8841 }
8842
8843 infos[i] = new UiccSlotInfo(
8844 slot.isActive(),
8845 slot.isEuicc(),
8846 cardId,
8847 cardState,
8848 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008849 slot.isExtendedApduSupported(),
8850 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008851 }
8852 return infos;
8853 } finally {
8854 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008855 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008856 }
8857
8858 @Override
8859 public boolean switchSlots(int[] physicalSlots) {
8860 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008861
8862 final long identity = Binder.clearCallingIdentity();
8863 try {
8864 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8865 } finally {
8866 Binder.restoreCallingIdentity(identity);
8867 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008868 }
Jack Yu4c988042018-02-27 15:30:01 -08008869
8870 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008871 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008872 final long identity = Binder.clearCallingIdentity();
8873 try {
8874 return UiccController.getInstance().getCardIdForDefaultEuicc();
8875 } finally {
8876 Binder.restoreCallingIdentity(identity);
8877 }
8878 }
8879
Pengquan Meng85728fb2018-03-12 16:31:21 -07008880 /**
goneil47ffb6e2018-04-06 15:40:58 -07008881 * A test API to reload the UICC profile.
8882 *
8883 * <p>Requires that the calling app has permission
8884 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8885 * @hide
8886 */
8887 @Override
8888 public void refreshUiccProfile(int subId) {
8889 enforceModifyPermission();
8890
8891 final long identity = Binder.clearCallingIdentity();
8892 try {
8893 Phone phone = getPhone(subId);
8894 if (phone == null) {
8895 return;
8896 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008897 UiccPort uiccPort = phone.getUiccPort();
8898 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008899 return;
8900 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008901 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008902 if (uiccProfile == null) {
8903 return;
8904 }
8905 uiccProfile.refresh();
8906 } finally {
8907 Binder.restoreCallingIdentity(identity);
8908 }
8909 }
8910
8911 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008912 * Returns false if the mobile data is disabled by default, otherwise return true.
8913 */
8914 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008915 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008916 }
8917
8918 /**
8919 * Returns true if the data roaming is enabled by default, i.e the system property
8920 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8921 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8922 */
8923 private boolean getDefaultDataRoamingEnabled(int subId) {
8924 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008925 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008926 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008927 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8928 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8929 return isDataRoamingEnabled;
8930 }
8931
8932 /**
8933 * Returns the default network type for the given {@code subId}, if the default network type is
8934 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8935 */
8936 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008937 List<Integer> list = TelephonyProperties.default_network();
8938 int phoneId = mSubscriptionController.getPhoneId(subId);
8939 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8940 return list.get(phoneId);
8941 }
8942 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008943 }
fionaxua13278b2018-03-21 00:08:13 -07008944
8945 @Override
8946 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008947 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008948 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008949
8950 final long identity = Binder.clearCallingIdentity();
8951 try {
8952 final Phone phone = getPhone(subId);
8953 if (phone == null) {
8954 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8955 return;
8956 }
chen xueaba88a2019-03-15 13:15:10 -07008957 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8958 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008959 if (carrierPrivilegeRules == null) {
8960 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8961 } else {
8962 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008964 } finally {
8965 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008966 }
fionaxua13278b2018-03-21 00:08:13 -07008967 }
8968
8969 @Override
8970 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008971 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008972
8973 final long identity = Binder.clearCallingIdentity();
8974 try {
8975 final Phone phone = getPhone(subId);
8976 if (phone == null) {
8977 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8978 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8979 }
8980 return phone.getCarrierIdListVersion();
8981 } finally {
8982 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008983 }
fionaxua13278b2018-03-21 00:08:13 -07008984 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008985
8986 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008987 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8988 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008990 mApp, subId, callingPackage, callingFeatureId,
8991 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008992 return -1;
8993 }
8994
8995 final long identity = Binder.clearCallingIdentity();
8996 try {
8997 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8998 } finally {
8999 Binder.restoreCallingIdentity(identity);
9000 }
9001 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009002
9003 @Override
9004 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009005 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009006 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009007 mApp, subId, "getCdmaRoamingMode");
9008
9009 final long identity = Binder.clearCallingIdentity();
9010 try {
9011 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9012 } finally {
9013 Binder.restoreCallingIdentity(identity);
9014 }
9015 }
9016
9017 @Override
9018 public boolean setCdmaRoamingMode(int subId, int mode) {
9019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9020 mApp, subId, "setCdmaRoamingMode");
9021
9022 final long identity = Binder.clearCallingIdentity();
9023 try {
9024 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9025 } finally {
9026 Binder.restoreCallingIdentity(identity);
9027 }
9028 }
9029
9030 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009031 public int getCdmaSubscriptionMode(int subId) {
9032 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009033 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009034 mApp, subId, "getCdmaSubscriptionMode");
9035
9036 final long identity = Binder.clearCallingIdentity();
9037 try {
9038 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9039 } finally {
9040 Binder.restoreCallingIdentity(identity);
9041 }
9042 }
9043
9044 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009045 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9047 mApp, subId, "setCdmaSubscriptionMode");
9048
9049 final long identity = Binder.clearCallingIdentity();
9050 try {
9051 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9052 } finally {
9053 Binder.restoreCallingIdentity(identity);
9054 }
9055 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009056
sqianc5eccab2018-10-19 18:46:41 -07009057 @Override
sqian8c685422019-02-22 15:55:18 -08009058 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009059 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009061 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9062 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009063 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9064 }
9065 final long identity = Binder.clearCallingIdentity();
9066 try {
sqian854d44b2018-12-12 16:48:18 -08009067 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9068 for (Phone phone: PhoneFactory.getPhones()) {
9069 if (phone.getEmergencyNumberTracker() != null
9070 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9071 emergencyNumberListInternal.put(
9072 phone.getSubId(),
9073 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9074 }
sqian11b7a0e2018-12-05 18:48:28 -08009075 }
sqian854d44b2018-12-12 16:48:18 -08009076 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009077 } finally {
9078 Binder.restoreCallingIdentity(identity);
9079 }
sqianc5eccab2018-10-19 18:46:41 -07009080 }
9081
9082 @Override
sqian8c685422019-02-22 15:55:18 -08009083 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009084 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009085 if (!exactMatch) {
9086 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009087 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009088 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009089 }
9090 final long identity = Binder.clearCallingIdentity();
9091 try {
sqian854d44b2018-12-12 16:48:18 -08009092 for (Phone phone: PhoneFactory.getPhones()) {
9093 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009094 && phone.getEmergencyNumberTracker()
9095 .isEmergencyNumber(number, exactMatch)) {
9096 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009097 }
sqian11b7a0e2018-12-05 18:48:28 -08009098 }
9099 return false;
9100 } finally {
9101 Binder.restoreCallingIdentity(identity);
9102 }
9103 }
9104
sqianf4ca7ed2019-01-15 18:32:07 -08009105 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009106 * Start emergency callback mode for GsmCdmaPhone for testing.
9107 */
9108 @Override
9109 public void startEmergencyCallbackMode() {
9110 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9111 "startEmergencyCallbackMode");
9112 enforceModifyPermission();
9113 final long identity = Binder.clearCallingIdentity();
9114 try {
9115 for (Phone phone : PhoneFactory.getPhones()) {
9116 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9117 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9118 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9119 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9120 gsmCdmaPhone.obtainMessage(
9121 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9122 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9123 }
9124 }
9125 } finally {
9126 Binder.restoreCallingIdentity(identity);
9127 }
9128 }
9129
9130 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009131 * Update emergency number list for test mode.
9132 */
9133 @Override
9134 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9135 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9136 "updateEmergencyNumberListTestMode");
9137
9138 final long identity = Binder.clearCallingIdentity();
9139 try {
9140 for (Phone phone: PhoneFactory.getPhones()) {
9141 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9142 if (tracker != null) {
9143 tracker.executeEmergencyNumberTestModeCommand(action, num);
9144 }
9145 }
9146 } finally {
9147 Binder.restoreCallingIdentity(identity);
9148 }
9149 }
9150
9151 /**
9152 * Get the full emergency number list for test mode.
9153 */
9154 @Override
9155 public List<String> getEmergencyNumberListTestMode() {
9156 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9157 "getEmergencyNumberListTestMode");
9158
9159 final long identity = Binder.clearCallingIdentity();
9160 try {
9161 Set<String> emergencyNumbers = new HashSet<>();
9162 for (Phone phone: PhoneFactory.getPhones()) {
9163 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9164 if (tracker != null) {
9165 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9166 emergencyNumbers.add(num.getNumber());
9167 }
9168 }
9169 }
9170 return new ArrayList<>(emergencyNumbers);
9171 } finally {
9172 Binder.restoreCallingIdentity(identity);
9173 }
9174 }
9175
chen xud6b45bd2018-10-30 22:27:10 -07009176 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009177 public int getEmergencyNumberDbVersion(int subId) {
9178 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9179
9180 final long identity = Binder.clearCallingIdentity();
9181 try {
9182 final Phone phone = getPhone(subId);
9183 if (phone == null) {
9184 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9185 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9186 }
9187 return phone.getEmergencyNumberDbVersion();
9188 } finally {
9189 Binder.restoreCallingIdentity(identity);
9190 }
9191 }
9192
9193 @Override
9194 public void notifyOtaEmergencyNumberDbInstalled() {
9195 enforceModifyPermission();
9196
9197 final long identity = Binder.clearCallingIdentity();
9198 try {
9199 for (Phone phone: PhoneFactory.getPhones()) {
9200 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9201 if (tracker != null) {
9202 tracker.updateOtaEmergencyNumberDatabase();
9203 }
9204 }
9205 } finally {
9206 Binder.restoreCallingIdentity(identity);
9207 }
9208 }
9209
9210 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009211 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009212 enforceActiveEmergencySessionPermission();
9213
9214 final long identity = Binder.clearCallingIdentity();
9215 try {
9216 for (Phone phone: PhoneFactory.getPhones()) {
9217 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9218 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009219 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9220 }
9221 }
9222 } finally {
9223 Binder.restoreCallingIdentity(identity);
9224 }
9225 }
9226
9227 @Override
9228 public void resetOtaEmergencyNumberDbFilePath() {
9229 enforceActiveEmergencySessionPermission();
9230
9231 final long identity = Binder.clearCallingIdentity();
9232 try {
9233 for (Phone phone: PhoneFactory.getPhones()) {
9234 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9235 if (tracker != null) {
9236 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009237 }
9238 }
9239 } finally {
9240 Binder.restoreCallingIdentity(identity);
9241 }
9242 }
9243
9244 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009245 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9246 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9247 Phone phone = getPhone(subId);
9248 if (phone == null) {
9249 return null;
9250 }
9251 final long identity = Binder.clearCallingIdentity();
9252 try {
9253 UiccProfile profile = UiccController.getInstance()
9254 .getUiccProfileForPhone(phone.getPhoneId());
9255 if (profile != null) {
9256 return profile.getCertsFromCarrierPrivilegeAccessRules();
9257 }
9258 } finally {
9259 Binder.restoreCallingIdentity(identity);
9260 }
9261 return null;
9262 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009263
9264 /**
9265 * Enable or disable a modem stack.
9266 */
9267 @Override
9268 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9269 enforceModifyPermission();
9270
9271 final long identity = Binder.clearCallingIdentity();
9272 try {
9273 Phone phone = PhoneFactory.getPhone(slotIndex);
9274 if (phone == null) {
9275 return false;
9276 } else {
9277 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9278 }
9279 } finally {
9280 Binder.restoreCallingIdentity(identity);
9281 }
9282 }
Michelecea4cf22018-12-21 15:00:11 -08009283
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009284 /**
9285 * Whether a modem stack is enabled or not.
9286 */
9287 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009288 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9289 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009290 Phone phone = PhoneFactory.getPhone(slotIndex);
9291 if (phone == null) return false;
9292
9293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009294 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9295 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009296 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9297 }
9298
9299 final long identity = Binder.clearCallingIdentity();
9300 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009301 try {
9302 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9303 } catch (NoSuchElementException ex) {
9304 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9305 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009306 } finally {
9307 Binder.restoreCallingIdentity(identity);
9308 }
9309 }
9310
Michelecea4cf22018-12-21 15:00:11 -08009311 @Override
Michele0ea7d782019-03-19 14:58:42 -07009312 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009313 enforceModifyPermission();
9314
9315 final long identity = Binder.clearCallingIdentity();
9316 try {
9317 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009318 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009319 .commit();
9320 } finally {
9321 Binder.restoreCallingIdentity(identity);
9322 }
9323 }
9324
9325 @Override
Michele0ea7d782019-03-19 14:58:42 -07009326 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009327 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009328 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009329 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9330 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009331 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009332 }
Michelecea4cf22018-12-21 15:00:11 -08009333
9334 final long identity = Binder.clearCallingIdentity();
9335 try {
Michele0ea7d782019-03-19 14:58:42 -07009336 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009337 } finally {
9338 Binder.restoreCallingIdentity(identity);
9339 }
9340 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009341
Michele0ea7d782019-03-19 14:58:42 -07009342 @TelephonyManager.IsMultiSimSupportedResult
9343 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009344 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9345 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9346 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009347 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9348 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009349 }
9350 // Check if the hardware supports multisim functionality. If usage of multisim is not
9351 // supported by the modem, indicate that it is restricted.
9352 PhoneCapability staticCapability =
9353 mPhoneConfigurationManager.getStaticPhoneCapability();
9354 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009355 loge("isMultiSimSupportedInternal: no static configuration available");
9356 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009357 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009358 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009359 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9360 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009361 }
9362 // Check if support of multiple SIMs is restricted by carrier
9363 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009364 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009365 }
9366
Michele0ea7d782019-03-19 14:58:42 -07009367 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009368 }
9369
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009370 /**
9371 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009372 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9373 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9374 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009375 * @param numOfSims number of active sims we want to switch to
9376 */
9377 @Override
9378 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009379 if (numOfSims == 1) {
9380 enforceModifyPermission();
9381 } else {
9382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9383 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9384 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009385 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009386
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009387 try {
Michele30b57b22019-03-01 12:01:14 -08009388 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009389 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009390 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9391 return;
9392 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009393 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9394 } finally {
9395 Binder.restoreCallingIdentity(identity);
9396 }
9397 }
9398
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009399 @Override
9400 public boolean isApplicationOnUicc(int subId, int appType) {
9401 enforceReadPrivilegedPermission("isApplicationOnUicc");
9402 Phone phone = getPhone(subId);
9403 if (phone == null) {
9404 return false;
9405 }
9406 final long identity = Binder.clearCallingIdentity();
9407 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009408 UiccPort uiccPort = phone.getUiccPort();
9409 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009410 return false;
9411 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009412 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009413 if (uiccProfile == null) {
9414 return false;
9415 }
9416 if (TelephonyManager.APPTYPE_SIM <= appType
9417 && appType <= TelephonyManager.APPTYPE_ISIM) {
9418 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9419 }
9420 return false;
9421 } finally {
9422 Binder.restoreCallingIdentity(identity);
9423 }
9424 }
9425
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009426 /**
chen xub4baa772019-04-03 10:23:41 -07009427 * Get whether making changes to modem configurations will trigger reboot.
9428 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009429 */
9430 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009431 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9432 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009433 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009434 mApp, subId, callingPackage, callingFeatureId,
9435 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009436 return false;
9437 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009438 final long identity = Binder.clearCallingIdentity();
9439 try {
9440 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9441 } finally {
9442 Binder.restoreCallingIdentity(identity);
9443 }
9444 }
9445
Nathan Harold29f5f052019-02-15 13:41:57 -08009446 private void updateModemStateMetrics() {
9447 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9448 // TODO: check the state for each modem if the api is ready.
9449 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9450 }
9451
Pengquan Meng3889a572019-01-23 11:16:29 -08009452 @Override
9453 public int[] getSlotsMapping() {
9454 enforceReadPrivilegedPermission("getSlotsMapping");
9455
9456 final long identity = Binder.clearCallingIdentity();
9457 try {
9458 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9459 // All logical slots should have a mapping to a physical slot.
9460 int[] logicalSlotsMapping = new int[phoneCount];
9461 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9462 for (int i = 0; i < slotInfos.length; i++) {
9463 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9464 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9465 }
9466 }
9467 return logicalSlotsMapping;
9468 } finally {
9469 Binder.restoreCallingIdentity(identity);
9470 }
9471 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009472
9473 /**
9474 * Get the IRadio HAL Version
9475 */
9476 @Override
9477 public int getRadioHalVersion() {
9478 Phone phone = getDefaultPhone();
9479 if (phone == null) return -1;
9480 HalVersion hv = phone.getHalVersion();
9481 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9482 return hv.major * 100 + hv.minor;
9483 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009484
9485 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009486 * Get the current calling package name.
9487 * @return the current calling package name
9488 */
9489 @Override
9490 public String getCurrentPackageName() {
9491 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9492 }
9493
9494 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009495 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9496 * corresponding network requests on a subId.
9497 *
9498 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009499 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009500 * 2) APN is un-metered for this subscription, or
9501 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009502 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009503 *
9504 * @return whether data is allowed for a apn type.
9505 *
9506 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009507 */
9508 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009509 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009510 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9511 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009512
9513 // Now that all security checks passes, perform the operation as ourselves.
9514 final long identity = Binder.clearCallingIdentity();
9515 try {
9516 Phone phone = getPhone(subId);
9517 if (phone == null) return false;
9518
Jack Yu41407ee2019-05-13 16:54:09 -07009519 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009520 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9521 } finally {
9522 Binder.restoreCallingIdentity(identity);
9523 }
9524 }
9525
9526 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009527 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009528 enforceReadPrivilegedPermission("isApnMetered");
9529
9530 // Now that all security checks passes, perform the operation as ourselves.
9531 final long identity = Binder.clearCallingIdentity();
9532 try {
9533 Phone phone = getPhone(subId);
9534 if (phone == null) return true; // By default return true.
9535
Jack Yu41407ee2019-05-13 16:54:09 -07009536 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009537 } finally {
9538 Binder.restoreCallingIdentity(identity);
9539 }
9540 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009541
9542 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009543 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9544 int subscriptionId, IBooleanConsumer resultCallback) {
9545 enforceModifyPermission();
9546 long token = Binder.clearCallingIdentity();
9547 try {
9548 Phone phone = getPhone(subscriptionId);
9549 if (phone == null) {
9550 try {
9551 if (resultCallback != null) {
9552 resultCallback.accept(false);
9553 }
9554 } catch (RemoteException e) {
9555 // ignore
9556 }
9557 return;
9558 }
9559 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9560 Pair.create(specifiers, (x) -> {
9561 try {
9562 if (resultCallback != null) {
9563 resultCallback.accept(x);
9564 }
9565 } catch (RemoteException e) {
9566 // ignore
9567 }
9568 });
9569 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9570 } finally {
9571 Binder.restoreCallingIdentity(token);
9572 }
9573 }
9574
9575 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009576 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9577 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009578 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009579 mApp, subId, "getSystemSelectionChannels");
9580 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9581 final long identity = Binder.clearCallingIdentity();
9582 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009583 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9584 if (result instanceof IllegalStateException) {
9585 throw (IllegalStateException) result;
9586 }
9587 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009588 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9589 return specifiers;
9590 } finally {
9591 Binder.restoreCallingIdentity(identity);
9592 }
9593 }
9594
9595 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009596 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009597 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009598 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9599 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9600 if (iccRecords == null) {
9601 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9602 return false;
9603 }
9604 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9605 }
9606
9607 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009608 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9609 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009610 if (callingPackage == null) {
9611 callingPackage = getCurrentPackageName();
9612 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009613 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9614 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009615 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9616 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009617 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9618 }
9619 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9620 Intent intent = new Intent();
9621 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9622 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9623 // Bring up choose default SMS subscription dialog right now
9624 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9625 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9626 mApp.startActivity(intent);
9627 }
chen xud5ca2d52019-05-28 15:20:57 -07009628
9629 @Override
9630 public String getMmsUAProfUrl(int subId) {
9631 //TODO investigate if this API should require proper permission check in R b/133791609
9632 final long identity = Binder.clearCallingIdentity();
9633 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009634 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9635 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9636 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9637 return carrierUAProfUrl;
9638 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009639 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9640 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009641 } finally {
9642 Binder.restoreCallingIdentity(identity);
9643 }
9644 }
9645
9646 @Override
9647 public String getMmsUserAgent(int subId) {
9648 //TODO investigate if this API should require proper permission check in R b/133791609
9649 final long identity = Binder.clearCallingIdentity();
9650 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009651 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9652 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9653 if (!TextUtils.isEmpty(carrierUserAgent)) {
9654 return carrierUserAgent;
9655 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009656 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9657 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009658 } finally {
9659 Binder.restoreCallingIdentity(identity);
9660 }
9661 }
Jack Yub07d4972019-05-28 16:12:25 -07009662
9663 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009664 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9665 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009666
Jack Yub07d4972019-05-28 16:12:25 -07009667 final long identity = Binder.clearCallingIdentity();
9668 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009669 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009670 if (phone == null) return false;
9671
Hall Liua62f5da2020-09-25 10:42:19 -07009672 switch (policy) {
9673 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9674 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9675 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9676 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9677 default:
9678 throw new IllegalArgumentException(policy + " is not a valid policy");
9679 }
Jack Yub07d4972019-05-28 16:12:25 -07009680 } finally {
9681 Binder.restoreCallingIdentity(identity);
9682 }
9683 }
9684
9685 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009686 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009687 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009688 enforceModifyPermission();
9689
changbettyd5c246e2019-12-24 15:40:37 +08009690 final long identity = Binder.clearCallingIdentity();
9691 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009692 Phone phone = getPhone(subscriptionId);
9693 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009694
Hall Liua62f5da2020-09-25 10:42:19 -07009695 switch (policy) {
9696 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9697 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9698 break;
9699 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9700 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9701 break;
9702 default:
9703 throw new IllegalArgumentException(policy + " is not a valid policy");
9704 }
changbettyd5c246e2019-12-24 15:40:37 +08009705 } finally {
9706 Binder.restoreCallingIdentity(identity);
9707 }
9708 }
9709
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009710 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009711 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009712 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9713 * otherwise.
9714 */
9715 @Override
9716 public void setCepEnabled(boolean isCepEnabled) {
9717 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9718
9719 final long identity = Binder.clearCallingIdentity();
9720 try {
9721 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9722 for (Phone phone : PhoneFactory.getPhones()) {
9723 Phone defaultPhone = phone.getImsPhone();
9724 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9725 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9726 ImsPhoneCallTracker imsPhoneCallTracker =
9727 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9728 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9729 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9730 + imsPhone.getMsisdn());
9731 }
9732 }
9733 } finally {
9734 Binder.restoreCallingIdentity(identity);
9735 }
9736 }
allenwtsu46dcc572020-01-08 18:24:03 +08009737
9738 /**
9739 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9740 *
9741 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9742 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9743 * before being read.
9744 */
9745 @Override
9746 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9747 isCompressed) {
9748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9749 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009750 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9751 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9752 }
9753 if (!isImsAvailableOnDevice()) {
9754 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9755 "IMS not available on device.");
9756 }
9757
9758 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009759 try {
Hui Wang761a6682020-10-31 05:12:53 +00009760 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9761 } finally {
9762 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009763 }
9764 }
zoey chene02881a2019-12-30 16:11:23 +08009765
9766 @Override
9767 public boolean isIccLockEnabled(int subId) {
9768 enforceReadPrivilegedPermission("isIccLockEnabled");
9769
9770 // Now that all security checks passes, perform the operation as ourselves.
9771 final long identity = Binder.clearCallingIdentity();
9772 try {
9773 Phone phone = getPhone(subId);
9774 if (phone != null && phone.getIccCard() != null) {
9775 return phone.getIccCard().getIccLockEnabled();
9776 } else {
9777 return false;
9778 }
9779 } finally {
9780 Binder.restoreCallingIdentity(identity);
9781 }
9782 }
9783
9784 /**
9785 * Set the ICC pin lock enabled or disabled.
9786 *
9787 * @return an integer representing the status of IccLock enabled or disabled in the following
9788 * three cases:
9789 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9790 * successfully.
9791 * - Positive number and zero for remaining password attempts.
9792 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9793 *
9794 */
9795 @Override
9796 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9797 enforceModifyPermission();
9798
9799 Phone phone = getPhone(subId);
9800 if (phone == null) {
9801 return 0;
9802 }
9803 // Now that all security checks passes, perform the operation as ourselves.
9804 final long identity = Binder.clearCallingIdentity();
9805 try {
9806 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9807 new Pair<Boolean, String>(enabled, password), phone, null);
9808 return attemptsRemaining;
9809
9810 } catch (Exception e) {
9811 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9812 } finally {
9813 Binder.restoreCallingIdentity(identity);
9814 }
9815 return 0;
9816 }
9817
9818 /**
9819 * Change the ICC password used in ICC pin lock.
9820 *
9821 * @return an integer representing the status of IccLock changed in the following three cases:
9822 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9823 * - Positive number and zero for remaining password attempts.
9824 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9825 *
9826 */
9827 @Override
9828 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9829 enforceModifyPermission();
9830
9831 Phone phone = getPhone(subId);
9832 if (phone == null) {
9833 return 0;
9834 }
9835 // Now that all security checks passes, perform the operation as ourselves.
9836 final long identity = Binder.clearCallingIdentity();
9837 try {
9838 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9839 new Pair<String, String>(oldPassword, newPassword), phone, null);
9840 return attemptsRemaining;
9841
9842 } catch (Exception e) {
9843 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9844 } finally {
9845 Binder.restoreCallingIdentity(identity);
9846 }
9847 return 0;
9848 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009849
9850 /**
9851 * Request for receiving user activity notification
9852 */
9853 @Override
9854 public void requestUserActivityNotification() {
9855 if (!mNotifyUserActivity.get()
9856 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9857 mNotifyUserActivity.set(true);
9858 }
9859 }
9860
9861 /**
9862 * Called when userActivity is signalled in the power manager.
9863 * This is safe to call from any thread, with any window manager locks held or not.
9864 */
9865 @Override
9866 public void userActivity() {
9867 // ***************************************
9868 // * Inherited from PhoneWindowManager *
9869 // ***************************************
9870 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9871 // WITH ITS LOCKS HELD.
9872 //
9873 // This code must be VERY careful about the locks
9874 // it acquires.
9875 // In fact, the current code acquires way too many,
9876 // and probably has lurking deadlocks.
9877
9878 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9879 throw new SecurityException("Only the OS may call notifyUserActivity()");
9880 }
9881
9882 if (mNotifyUserActivity.getAndSet(false)) {
9883 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9884 USER_ACTIVITY_NOTIFICATION_DELAY);
9885 }
9886 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009887
9888 @Override
9889 public boolean canConnectTo5GInDsdsMode() {
9890 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9891 }
Jack Yud10cdd42020-09-28 20:28:01 -07009892
9893 @Override
9894 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9895 String callingFeatureId) {
9896 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9897 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9898 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9899 }
9900
9901 Phone phone = getPhone(subId);
9902 if (phone == null) {
9903 throw new RuntimeException("phone is not available");
9904 }
9905 // Now that all security checks passes, perform the operation as ourselves.
9906 final long identity = Binder.clearCallingIdentity();
9907 try {
9908 return phone.getEquivalentHomePlmns();
9909 } finally {
9910 Binder.restoreCallingIdentity(identity);
9911 }
9912 }
Daniel Bright59e67312020-11-13 11:49:37 -08009913
9914 @Override
9915 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009916 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9917 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009918 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009919 if (radioInterfaceCapabilities == null) {
9920 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009921 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009922 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009923 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009924
Hui Wang641e81c2020-10-12 12:14:23 -07009925 @Override
9926 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9927 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009928 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9929 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9930 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9931 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9932 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009933 if (DBG) {
9934 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9935 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9936 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9937 }
9938
9939 if (!SubscriptionManager.isValidSubscriptionId(subId)
9940 || appType < TelephonyManager.APPTYPE_UNKNOWN
9941 || appType > TelephonyManager.APPTYPE_ISIM
9942 || nafUrl == null || securityProtocol == null || callback == null) {
9943 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9944 if (callback != null) {
9945 try {
9946 callback.onAuthenticationFailure(
9947 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9948 } catch (RemoteException exception) {
9949 log("Fail to notify onAuthenticationFailure due to " + exception);
9950 }
9951 return;
9952 }
9953 }
9954
9955 final long token = Binder.clearCallingIdentity();
9956 try {
9957 getGbaManager(subId).bootstrapAuthenticationRequest(
9958 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9959 forceBootStrapping, callback));
9960 } finally {
9961 Binder.restoreCallingIdentity(token);
9962 }
9963 }
9964
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009965 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009966 * Attempts to set the radio power state for all phones for thermal reason.
9967 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009968 * requested radio power state will actually be set. See {@link
9969 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9970 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009971 * @param enable {@code true} if trying to turn radio on.
9972 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9973 * false}.
9974 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009975 private boolean setRadioPowerForThermal(boolean enable) {
9976 boolean isPhoneAvailable = false;
9977 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9978 Phone phone = PhoneFactory.getPhone(i);
9979 if (phone != null) {
9980 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9981 isPhoneAvailable = true;
9982 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009983 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009984
9985 // return true if successfully informed the phone object about the thermal radio power
9986 // request.
9987 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009988 }
9989
9990 private int handleDataThrottlingRequest(int subId,
9991 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009992 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9993 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9994 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9995 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9996 throw new IllegalArgumentException("modem does not support data throttling");
9997 }
9998
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009999 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10000 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010001 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010002 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10003 }
10004
10005 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10006
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010007 if (isDataThrottlingSupported) {
10008 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010009 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010010 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10011 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10012 } else if (thermalMitigationResult
10013 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010014 log("Modem likely does not support data throttling on secondary carrier. Data " +
10015 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10016 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010017 }
10018 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010019 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010020
10021 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010022 }
10023
Jack Nudelman644b91a2021-03-12 14:09:48 -080010024 private static List<String> getThermalMitigationAllowlist(Context context) {
10025 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10026 for (String pckg : context.getResources()
10027 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10028 sThermalMitigationAllowlistedPackages.add(pckg);
10029 }
10030 }
10031
10032 return sThermalMitigationAllowlistedPackages;
10033 }
10034
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010035 private boolean isAnyPhoneInEmergencyState() {
10036 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10037 if (tm.isInEmergencyCall()) {
10038 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10039 return true;
10040 }
10041 for (Phone phone : PhoneFactory.getPhones()) {
10042 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10043 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10044 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10045 + phone.isInEcm());
10046 return true;
10047 }
10048 }
10049
10050 return false;
10051 }
10052
Jack Nudelman644b91a2021-03-12 14:09:48 -080010053 /**
10054 * Used by shell commands to add an authorized package name for thermal mitigation.
10055 * @param packageName name of package to be allowlisted
10056 * @param context
10057 */
10058 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10059 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10060 sThermalMitigationAllowlistedPackages.add(packageName);
10061 }
10062
10063 /**
10064 * Used by shell commands to remove an authorized package name for thermal mitigation.
10065 * @param packageName name of package to remove from allowlist
10066 * @param context
10067 */
10068 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10069 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10070 sThermalMitigationAllowlistedPackages.remove(packageName);
10071 }
10072
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010073 /**
10074 * Thermal mitigation request to control functionalities at modem.
10075 *
10076 * @param subId the id of the subscription.
10077 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010078 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010079 *
10080 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10081 */
10082 @Override
10083 @ThermalMitigationResult
10084 public int sendThermalMitigationRequest(
10085 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010086 ThermalMitigationRequest thermalMitigationRequest,
10087 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010088 enforceModifyPermission();
10089
Jack Nudelman644b91a2021-03-12 14:09:48 -080010090 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10091 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10092 .contains(callingPackage)) {
10093 throw new SecurityException("Calling package must be configured in the device config. "
10094 + "calling package: " + callingPackage);
10095 }
10096
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010097 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10098 final long identity = Binder.clearCallingIdentity();
10099
10100 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10101 try {
10102 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10103 switch (thermalMitigationAction) {
10104 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10105 thermalMitigationResult =
10106 handleDataThrottlingRequest(subId,
10107 thermalMitigationRequest.getDataThrottlingRequest());
10108 break;
10109 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10110 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10111 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10112 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10113 }
10114
10115 // Ensure that radio is on. If not able to power on due to phone being
10116 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010117 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010118 thermalMitigationResult =
10119 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10120 break;
10121 }
10122
10123 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10124 false);
10125 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10126 break;
10127 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10128 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10129 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10130 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10131 }
10132
10133 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10134 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010135 Phone phone = getPhone(subId);
10136 if (phone == null) {
10137 thermalMitigationResult =
10138 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10139 break;
10140 }
10141
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010142 TelephonyConnectionService service =
10143 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010144 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010145 Log.e(LOG_TAG, "An emergency call is pending");
10146 thermalMitigationResult =
10147 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10148 break;
10149 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010150 thermalMitigationResult =
10151 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10152 break;
10153 }
10154 } else {
10155 thermalMitigationResult =
10156 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10157 break;
10158 }
10159
10160 // Turn radio off. If not able to power off due to phone being unavailable,
10161 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010162 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010163 thermalMitigationResult =
10164 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10165 break;
10166 }
10167 thermalMitigationResult =
10168 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10169 break;
10170 default:
10171 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10172 + "not exist. Requested action: " + thermalMitigationAction);
10173 }
10174 } catch (IllegalArgumentException e) {
10175 throw e;
10176 } catch (Exception e) {
10177 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10178 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10179 } finally {
10180 Binder.restoreCallingIdentity(identity);
10181 }
10182
10183 if (DBG) {
10184 log("thermalMitigationRequest returning with thermalMitigationResult: "
10185 + thermalMitigationResult);
10186 }
10187
10188 return thermalMitigationResult;
10189 }
Hui Wang641e81c2020-10-12 12:14:23 -070010190
10191 /**
10192 * Set the GbaService Package Name that Telephony will bind to.
10193 *
10194 * @param subId The sim that the GbaService is associated with.
10195 * @param packageName The name of the package to be replaced with.
10196 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10197 */
10198 @Override
10199 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10200 enforceModifyPermission();
10201
10202 final long identity = Binder.clearCallingIdentity();
10203 try {
10204 return getGbaManager(subId).overrideServicePackage(packageName);
10205 } finally {
10206 Binder.restoreCallingIdentity(identity);
10207 }
10208 }
10209
10210 /**
10211 * Return the package name of the currently bound GbaService.
10212 *
10213 * @param subId The sim that the GbaService is associated with.
10214 * @return the package name of the GbaService configuration, null if GBA is not supported.
10215 */
10216 @Override
10217 public String getBoundGbaService(int subId) {
10218 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10219
10220 final long identity = Binder.clearCallingIdentity();
10221 try {
10222 return getGbaManager(subId).getServicePackage();
10223 } finally {
10224 Binder.restoreCallingIdentity(identity);
10225 }
10226 }
10227
10228 /**
10229 * Set the release time for telephony to unbind GbaService.
10230 *
10231 * @param subId The sim that the GbaService is associated with.
10232 * @param interval The release time to unbind GbaService by millisecond.
10233 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10234 */
10235 @Override
10236 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10237 enforceModifyPermission();
10238
10239 final long identity = Binder.clearCallingIdentity();
10240 try {
10241 return getGbaManager(subId).overrideReleaseTime(interval);
10242 } finally {
10243 Binder.restoreCallingIdentity(identity);
10244 }
10245 }
10246
10247 /**
10248 * Return the release time for telephony to unbind GbaService.
10249 *
10250 * @param subId The sim that the GbaService is associated with.
10251 * @return The release time to unbind GbaService by millisecond.
10252 */
10253 @Override
10254 public int getGbaReleaseTime(int subId) {
10255 enforceReadPrivilegedPermission("getGbaReleaseTime");
10256
10257 final long identity = Binder.clearCallingIdentity();
10258 try {
10259 return getGbaManager(subId).getReleaseTime();
10260 } finally {
10261 Binder.restoreCallingIdentity(identity);
10262 }
10263 }
10264
10265 private GbaManager getGbaManager(int subId) {
10266 GbaManager instance = GbaManager.getInstance(subId);
10267 if (instance == null) {
10268 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10269 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10270 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10271 }
10272 return instance;
10273 }
Hui Wang761a6682020-10-31 05:12:53 +000010274
10275 /**
10276 * indicate whether the device and the carrier can support
10277 * RCS VoLTE single registration.
10278 */
10279 @Override
10280 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010281 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10282 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10283 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10284 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010285
10286 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10287 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10288 }
10289
10290 final long identity = Binder.clearCallingIdentity();
10291 try {
10292 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10293 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010294 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10295 if (isCapable != null) {
10296 return isCapable;
10297 }
Hui Wang761a6682020-10-31 05:12:53 +000010298 }
Hui Wang67af90e2021-06-04 16:57:15 -070010299 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10300 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010301 } finally {
10302 Binder.restoreCallingIdentity(identity);
10303 }
10304 }
10305
10306 /**
10307 * Register RCS provisioning callback.
10308 */
10309 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010310 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010311 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010312 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010313 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010314 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10315 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010316
10317 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10318 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10319 }
10320 if (!isImsAvailableOnDevice()) {
10321 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10322 "IMS not available on device.");
10323 }
10324
10325 final long identity = Binder.clearCallingIdentity();
10326 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010327 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010328 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010329 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10330 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010331 }
Hui Wang761a6682020-10-31 05:12:53 +000010332 } finally {
10333 Binder.restoreCallingIdentity(identity);
10334 }
10335 }
10336
10337 /**
10338 * Unregister RCS provisioning callback.
10339 */
10340 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010341 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010342 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010343 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010344 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010345 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10346 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010347
10348 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10349 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10350 }
10351 if (!isImsAvailableOnDevice()) {
10352 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10353 "IMS not available on device.");
10354 }
10355
10356 final long identity = Binder.clearCallingIdentity();
10357 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010358 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010359 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010360 } finally {
10361 Binder.restoreCallingIdentity(identity);
10362 }
10363 }
10364
10365 /**
10366 * trigger RCS reconfiguration.
10367 */
10368 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010369 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10370 "triggerRcsReconfiguration",
10371 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010372
10373 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10374 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10375 }
10376 if (!isImsAvailableOnDevice()) {
10377 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10378 "IMS not available on device.");
10379 }
10380
10381 final long identity = Binder.clearCallingIdentity();
10382 try {
10383 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10384 } finally {
10385 Binder.restoreCallingIdentity(identity);
10386 }
10387 }
10388
10389 /**
10390 * Provide the client configuration parameters of the RCS application.
10391 */
10392 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010393 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10394 "setRcsClientConfiguration",
10395 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010396
10397 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10398 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10399 }
10400 if (!isImsAvailableOnDevice()) {
10401 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10402 "IMS not available on device.");
10403 }
10404
10405 final long identity = Binder.clearCallingIdentity();
10406
10407 try {
10408 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10409 if (configBinder == null) {
10410 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010411 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10412 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010413 } else {
10414 configBinder.setRcsClientConfiguration(rcc);
10415 }
10416 } catch (RemoteException e) {
10417 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010418 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10419 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010420 } finally {
10421 Binder.restoreCallingIdentity(identity);
10422 }
10423 }
10424
10425 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010426 * Enables or disables the test mode for RCS VoLTE single registration.
10427 */
10428 @Override
10429 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10430 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10431 "setRcsSingleRegistrationTestModeEnabled");
10432
10433 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10434 }
10435
10436 /**
10437 * Gets the test mode for RCS VoLTE single registration.
10438 */
10439 @Override
10440 public boolean getRcsSingleRegistrationTestModeEnabled() {
10441 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10442 "getRcsSingleRegistrationTestModeEnabled");
10443
10444 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10445 }
10446
10447 /**
Hui Wang761a6682020-10-31 05:12:53 +000010448 * Overrides the config of RCS VoLTE single registration enabled for the device.
10449 */
10450 @Override
10451 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10452 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10453 "setDeviceSingleRegistrationEnabledOverride");
10454 enforceModifyPermission();
10455
10456 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10457 : Boolean.parseBoolean(enabledStr);
10458 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010459 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010460 }
10461
10462 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010463 * Sends a device to device communication message. Only usable via shell.
10464 * @param message message to send.
10465 * @param value message value.
10466 */
10467 @Override
10468 public void sendDeviceToDeviceMessage(int message, int value) {
10469 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010470 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010471 enforceModifyPermission();
10472
10473 final long identity = Binder.clearCallingIdentity();
10474 try {
10475 TelephonyConnectionService service =
10476 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10477 if (service == null) {
10478 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10479 return;
10480 }
10481 service.sendTestDeviceToDeviceMessage(message, value);
10482 } finally {
10483 Binder.restoreCallingIdentity(identity);
10484 }
10485 }
10486
Tyler Gunnbabbda02021-02-10 11:05:02 -080010487 /**
10488 * Sets the specified device to device transport active.
10489 * @param transport The transport to set active.
10490 */
10491 @Override
10492 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10493 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10494 "setActiveDeviceToDeviceTransport");
10495 enforceModifyPermission();
10496
10497 final long identity = Binder.clearCallingIdentity();
10498 try {
10499 TelephonyConnectionService service =
10500 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10501 if (service == null) {
10502 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10503 return;
10504 }
10505 service.setActiveDeviceToDeviceTransport(transport);
10506 } finally {
10507 Binder.restoreCallingIdentity(identity);
10508 }
10509 }
Tyler Gunn92479152021-01-20 16:30:10 -080010510
Tyler Gunnd4339262021-05-03 14:46:49 -070010511 @Override
10512 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10513 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10514 "setDeviceToDeviceForceEnabled");
10515
10516 final long identity = Binder.clearCallingIdentity();
10517 try {
10518 Arrays.stream(PhoneFactory.getPhones()).forEach(
10519 p -> {
10520 Phone thePhone = p.getImsPhone();
10521 if (thePhone != null && thePhone instanceof ImsPhone) {
10522 ImsPhone imsPhone = (ImsPhone) thePhone;
10523 CallTracker tracker = imsPhone.getCallTracker();
10524 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10525 ImsPhoneCallTracker imsPhoneCallTracker =
10526 (ImsPhoneCallTracker) tracker;
10527 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10528 }
10529 }
10530 }
10531 );
10532 } finally {
10533 Binder.restoreCallingIdentity(identity);
10534 }
10535 }
10536
Tyler Gunn92479152021-01-20 16:30:10 -080010537 /**
Hui Wang761a6682020-10-31 05:12:53 +000010538 * Gets the config of RCS VoLTE single registration enabled for the device.
10539 */
10540 @Override
10541 public boolean getDeviceSingleRegistrationEnabled() {
10542 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10543 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10544 }
10545
10546 /**
10547 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10548 */
10549 @Override
10550 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10551 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10552 "setCarrierSingleRegistrationEnabledOverride");
10553 enforceModifyPermission();
10554
10555 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10556 : Boolean.parseBoolean(enabledStr);
10557 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10558 subId, enabled);
10559 }
10560
10561 /**
10562 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10563 */
10564 @Override
10565 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10566 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10567 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10568 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010569
10570 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010571 * Overrides the ims feature validation result
10572 */
10573 @Override
10574 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10575 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10576 "setImsFeatureValidationOverride");
10577
10578 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10579 : Boolean.parseBoolean(enabledStr);
10580 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10581 subId, enabled);
10582 }
10583
10584 /**
10585 * Gets the ims feature validation override value
10586 */
10587 @Override
10588 public boolean getImsFeatureValidationOverride(int subId) {
10589 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10590 "getImsFeatureValidationOverride");
10591 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10592 }
10593
10594 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010595 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10596 * their mobile plan.
10597 */
10598 @Override
10599 public String getMobileProvisioningUrl() {
10600 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10601 final long identity = Binder.clearCallingIdentity();
10602 try {
10603 return getDefaultPhone().getMobileProvisioningUrl();
10604 } finally {
10605 Binder.restoreCallingIdentity(identity);
10606 }
10607 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010608
James.cf Linbcdf8b32021-01-14 16:44:13 +080010609 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010610 * Get the EAB contact from the EAB database.
10611 */
10612 @Override
10613 public String getContactFromEab(String contact) {
10614 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10615 enforceModifyPermission();
10616 final long identity = Binder.clearCallingIdentity();
10617 try {
10618 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10619 } finally {
10620 Binder.restoreCallingIdentity(identity);
10621 }
10622 }
10623
10624 /**
Calvin Pana1434322021-07-01 19:27:01 +080010625 * Get the EAB capability from the EAB database.
10626 */
10627 @Override
10628 public String getCapabilityFromEab(String contact) {
10629 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10630 enforceModifyPermission();
10631 final long identity = Binder.clearCallingIdentity();
10632 try {
10633 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10634 } finally {
10635 Binder.restoreCallingIdentity(identity);
10636 }
10637 }
10638
10639 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010640 * Remove the EAB contacts from the EAB database.
10641 */
10642 @Override
10643 public int removeContactFromEab(int subId, String contacts) {
10644 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10645 enforceModifyPermission();
10646 final long identity = Binder.clearCallingIdentity();
10647 try {
10648 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10649 } finally {
10650 Binder.restoreCallingIdentity(identity);
10651 }
10652 }
10653
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010654 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010655 public boolean getDeviceUceEnabled() {
10656 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10657 final long identity = Binder.clearCallingIdentity();
10658 try {
10659 return mApp.getDeviceUceEnabled();
10660 } finally {
10661 Binder.restoreCallingIdentity(identity);
10662 }
10663 }
10664
10665 @Override
10666 public void setDeviceUceEnabled(boolean isEnabled) {
10667 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10668 final long identity = Binder.clearCallingIdentity();
10669 try {
10670 mApp.setDeviceUceEnabled(isEnabled);
10671 } finally {
10672 Binder.restoreCallingIdentity(identity);
10673 }
10674 }
10675
Brad Ebinger14d467f2021-02-12 06:18:28 +000010676 /**
10677 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10678 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10679 */
10680 // Used for SHELL command only right now.
10681 @Override
10682 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10683 List<String> featureTags) {
10684 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10685 "addUceRegistrationOverrideShell");
10686 final long identity = Binder.clearCallingIdentity();
10687 try {
10688 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10689 new ArraySet<>(featureTags));
10690 } catch (ImsException e) {
10691 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10692 } finally {
10693 Binder.restoreCallingIdentity(identity);
10694 }
10695 }
10696
10697 /**
10698 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10699 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10700 */
10701 // Used for SHELL command only right now.
10702 @Override
10703 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10704 List<String> featureTags) {
10705 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10706 "removeUceRegistrationOverrideShell");
10707 final long identity = Binder.clearCallingIdentity();
10708 try {
10709 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10710 new ArraySet<>(featureTags));
10711 } catch (ImsException e) {
10712 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10713 } finally {
10714 Binder.restoreCallingIdentity(identity);
10715 }
10716 }
10717
10718 /**
10719 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10720 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10721 */
10722 // Used for SHELL command only right now.
10723 @Override
10724 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10725 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10726 "clearUceRegistrationOverrideShell");
10727 final long identity = Binder.clearCallingIdentity();
10728 try {
10729 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10730 } catch (ImsException e) {
10731 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10732 } finally {
10733 Binder.restoreCallingIdentity(identity);
10734 }
10735 }
10736
10737 /**
10738 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10739 */
10740 // Used for SHELL command only right now.
10741 @Override
10742 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10743 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10744 "getLatestRcsContactUceCapabilityShell");
10745 final long identity = Binder.clearCallingIdentity();
10746 try {
10747 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10748 } catch (ImsException e) {
10749 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10750 } finally {
10751 Binder.restoreCallingIdentity(identity);
10752 }
10753 }
10754
10755 /**
10756 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10757 * device does not have an active PUBLISH.
10758 */
10759 // Used for SHELL command only right now.
10760 @Override
10761 public String getLastUcePidfXmlShell(int subId) {
10762 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10763 final long identity = Binder.clearCallingIdentity();
10764 try {
10765 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10766 } catch (ImsException e) {
10767 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10768 } finally {
10769 Binder.restoreCallingIdentity(identity);
10770 }
10771 }
10772
James.cf Line8713a42021-04-29 16:04:26 +080010773 /**
10774 * Remove UCE requests cannot be sent to the network status.
10775 */
10776 // Used for SHELL command only right now.
10777 @Override
10778 public boolean removeUceRequestDisallowedStatus(int subId) {
10779 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10780 final long identity = Binder.clearCallingIdentity();
10781 try {
10782 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10783 } catch (ImsException e) {
10784 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10785 } finally {
10786 Binder.restoreCallingIdentity(identity);
10787 }
10788 }
10789
James.cf Lin18bb9002021-05-25 01:37:38 +080010790 /**
10791 * Remove UCE requests cannot be sent to the network status.
10792 */
10793 // Used for SHELL command only.
10794 @Override
10795 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10796 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10797 final long identity = Binder.clearCallingIdentity();
10798 try {
10799 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10800 } catch (ImsException e) {
10801 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10802 } finally {
10803 Binder.restoreCallingIdentity(identity);
10804 }
10805 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010806
James.cf Lin4b784aa2021-01-31 03:25:15 +080010807 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010808 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10809 String callingPackage) {
10810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10811 mApp, subId, "setSignalStrengthUpdateRequest");
10812
10813 final int callingUid = Binder.getCallingUid();
10814 // Verify that tha callingPackage belongs to the calling UID
10815 mApp.getSystemService(AppOpsManager.class)
10816 .checkPackage(callingUid, callingPackage);
10817
10818 validateSignalStrengthUpdateRequest(request, callingUid);
10819
10820 final long identity = Binder.clearCallingIdentity();
10821 try {
10822 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10823 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10824
10825 if (result instanceof IllegalStateException) {
10826 throw (IllegalStateException) result;
10827 }
10828 } finally {
10829 Binder.restoreCallingIdentity(identity);
10830 }
10831 }
10832
10833 @Override
10834 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10835 String callingPackage) {
10836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10837 mApp, subId, "clearSignalStrengthUpdateRequest");
10838
10839 final int callingUid = Binder.getCallingUid();
10840 // Verify that tha callingPackage belongs to the calling UID
10841 mApp.getSystemService(AppOpsManager.class)
10842 .checkPackage(callingUid, callingPackage);
10843
10844 final long identity = Binder.clearCallingIdentity();
10845 try {
10846 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10847 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10848
10849 if (result instanceof IllegalStateException) {
10850 throw (IllegalStateException) result;
10851 }
10852 } finally {
10853 Binder.restoreCallingIdentity(identity);
10854 }
10855 }
10856
10857 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10858 int callingUid) {
10859 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10860 // phone/system process do not have further restriction on request
10861 return;
10862 }
10863
10864 // Applications has restrictions on how to use the request:
10865 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10866 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10867 // This is not system caller which has been checked above
10868 throw new IllegalArgumentException(
10869 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10870 }
10871
10872 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10873 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10874 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10875 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10876 || info.isEnabled()) {
10877 throw new IllegalArgumentException(
10878 "Only system can set hide fields in SignalThresholdInfo");
10879 }
10880
10881 // Thresholds length for each RAN need in range. This has been validated in
10882 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10883 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10884 final int[] thresholds = info.getThresholds();
10885 Objects.requireNonNull(thresholds);
10886 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10887 || thresholds.length
10888 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10889 throw new IllegalArgumentException(
10890 "thresholds length is out of range: " + thresholds.length);
10891 }
10892 }
10893 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010894
10895 /**
10896 * Gets the current phone capability.
10897 *
10898 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10899 * @return the PhoneCapability which describes the data connection capability of modem.
10900 * It's used to evaluate possible phone config change, for example from single
10901 * SIM device to multi-SIM device.
10902 */
10903 @Override
10904 public PhoneCapability getPhoneCapability() {
10905 enforceReadPrivilegedPermission("getPhoneCapability");
10906 final long identity = Binder.clearCallingIdentity();
10907 try {
10908 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10909 } finally {
10910 Binder.restoreCallingIdentity(identity);
10911 }
10912 }
Michele Berionne5e411512020-11-13 02:36:59 +000010913
10914 /**
10915 * Prepare TelephonyManager for an unattended reboot. The reboot is
10916 * required to be done shortly after the API is invoked.
10917 */
10918 @Override
10919 @TelephonyManager.PrepareUnattendedRebootResult
10920 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010921 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000010922 enforceRebootPermission();
10923
10924 final long identity = Binder.clearCallingIdentity();
10925 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010926 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000010927 } finally {
10928 Binder.restoreCallingIdentity(identity);
10929 }
10930 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010931
10932 /**
10933 * Request to get the current slicing configuration including URSP rules and
10934 * NSSAIs (configured, allowed and rejected).
10935 *
10936 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10937 */
10938 @Override
10939 public void getSlicingConfig(ResultReceiver callback) {
10940 enforceReadPrivilegedPermission("getSlicingConfig");
10941
10942 final long identity = Binder.clearCallingIdentity();
10943 try {
10944 Phone phone = getDefaultPhone();
10945 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10946 } finally {
10947 Binder.restoreCallingIdentity(identity);
10948 }
10949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010950}