blob: b3ee8eb444914f543d43d9c99fe5375055987e80 [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;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000155import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700156import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800157import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800159import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700160import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700161import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700162import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700164import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800165import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700166import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700167import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700168import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700169import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800170import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800171import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700172import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700173import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700174import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800175import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800176import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800177import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700178import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800179import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700180import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800181import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700182import com.android.internal.telephony.imsphone.ImsPhone;
183import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800184import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700185import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700186import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800187import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700188import com.android.internal.telephony.uicc.IccUtils;
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) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001101 callForwardingInfo = new CallForwardingInfo(
1102 callForwardInfo.status
1103 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001104 callForwardInfo.reason,
1105 callForwardInfo.number,
1106 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001107 break;
1108 }
1109 }
1110 // Didn't find a call forward info for voice call.
1111 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001112 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1113 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001114 }
Hall Liu27d24262020-09-18 19:04:59 -07001115 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001116 } else {
1117 if (ar.result == null) {
1118 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1119 }
1120 if (ar.exception != null) {
1121 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1122 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001123 int errorCode = TelephonyManager
1124 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001125 if (ar.exception instanceof CommandException) {
1126 CommandException.Error error =
1127 ((CommandException) (ar.exception)).getCommandError();
1128 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001129 errorCode = TelephonyManager
1130 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001131 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001132 errorCode = TelephonyManager
1133 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001134 }
1135 }
Hall Liu27d24262020-09-18 19:04:59 -07001136 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001137 }
Shuo Qian4a594052020-01-23 11:59:30 -08001138 break;
Hall Liu27d24262020-09-18 19:04:59 -07001139 }
Shuo Qian4a594052020-01-23 11:59:30 -08001140
Hall Liu27d24262020-09-18 19:04:59 -07001141 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001142 request = (MainThreadRequest) msg.obj;
1143 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001144 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001145 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001146 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1147 request.argument).first;
1148 request.phone.setCallForwardingOption(
1149 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001150 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001151 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001152 callForwardingInfoToSet.getReason(),
1153 callForwardingInfoToSet.getNumber(),
1154 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1155 break;
Hall Liu27d24262020-09-18 19:04:59 -07001156 }
Shuo Qian4a594052020-01-23 11:59:30 -08001157
Hall Liu27d24262020-09-18 19:04:59 -07001158 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001159 ar = (AsyncResult) msg.obj;
1160 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001161 Consumer<Integer> callback =
1162 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1163 request.argument).second;
1164 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001165 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001166 int errorCode = TelephonyManager.CallForwardingInfoCallback
1167 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001168 if (ar.exception instanceof CommandException) {
1169 CommandException.Error error =
1170 ((CommandException) (ar.exception)).getCommandError();
1171 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001172 errorCode = TelephonyManager.CallForwardingInfoCallback
1173 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001174 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001175 errorCode = TelephonyManager.CallForwardingInfoCallback
1176 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001177 }
1178 }
1179 callback.accept(errorCode);
1180 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001181 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001182 }
Shuo Qian4a594052020-01-23 11:59:30 -08001183 break;
Hall Liu27d24262020-09-18 19:04:59 -07001184 }
Shuo Qian4a594052020-01-23 11:59:30 -08001185
Hall Liu27d24262020-09-18 19:04:59 -07001186 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001187 request = (MainThreadRequest) msg.obj;
1188 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1189 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1190 break;
Hall Liu27d24262020-09-18 19:04:59 -07001191 }
Shuo Qian4a594052020-01-23 11:59:30 -08001192
Hall Liu27d24262020-09-18 19:04:59 -07001193 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001194 ar = (AsyncResult) msg.obj;
1195 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001196 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001197 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1198 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001199 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001200 // Service Class is a bit mask per 3gpp 27.007.
1201 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001202 if (callForwardResults.length > 1
1203 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001204 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001205 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001206 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1207 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001208 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001209 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001210 }
1211 } else {
1212 if (ar.result == null) {
1213 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1214 }
1215 if (ar.exception != null) {
1216 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1217 }
1218 if (ar.exception instanceof CommandException) {
1219 CommandException.Error error =
1220 ((CommandException) (ar.exception)).getCommandError();
1221 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1222 callForwardingStatus =
1223 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1224 }
1225 }
1226 }
Hall Liu27d24262020-09-18 19:04:59 -07001227 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001228 break;
Hall Liu27d24262020-09-18 19:04:59 -07001229 }
Shuo Qian4a594052020-01-23 11:59:30 -08001230
Hall Liu27d24262020-09-18 19:04:59 -07001231 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001232 request = (MainThreadRequest) msg.obj;
1233 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001234 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1235 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001236 break;
Hall Liu27d24262020-09-18 19:04:59 -07001237 }
Shuo Qian4a594052020-01-23 11:59:30 -08001238
Hall Liu27d24262020-09-18 19:04:59 -07001239 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001240 ar = (AsyncResult) msg.obj;
1241 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001242 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1243 Consumer<Integer> callback =
1244 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1245 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001246 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001247 if (ar.exception instanceof CommandException) {
1248 CommandException.Error error =
1249 ((CommandException) (ar.exception)).getCommandError();
1250 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1251 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1252 } else {
1253 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1254 }
1255 } else {
1256 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1257 }
1258 } else {
1259 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1260 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001261 }
Shuo Qian4a594052020-01-23 11:59:30 -08001262 break;
Hall Liu27d24262020-09-18 19:04:59 -07001263 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001264 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1265 ar = (AsyncResult) msg.obj;
1266 request = (MainThreadRequest) ar.userObj;
1267 CellNetworkScanResult cellScanResult;
1268 if (ar.exception == null && ar.result != null) {
1269 cellScanResult = new CellNetworkScanResult(
1270 CellNetworkScanResult.STATUS_SUCCESS,
1271 (List<OperatorInfo>) ar.result);
1272 } else {
1273 if (ar.result == null) {
1274 loge("getCellNetworkScanResults: Empty response");
1275 }
1276 if (ar.exception != null) {
1277 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1278 }
1279 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1280 if (ar.exception instanceof CommandException) {
1281 CommandException.Error error =
1282 ((CommandException) (ar.exception)).getCommandError();
1283 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1284 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1285 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1286 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1287 }
1288 }
1289 cellScanResult = new CellNetworkScanResult(errorCode, null);
1290 }
1291 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001292 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001293 break;
1294
1295 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1296 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001297 ManualNetworkSelectionArgument selArg =
1298 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001299 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1300 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001301 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1302 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001303 break;
1304
1305 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001306 ar = (AsyncResult) msg.obj;
1307 request = (MainThreadRequest) ar.userObj;
1308 if (ar.exception == null) {
1309 request.result = true;
1310 } else {
1311 request.result = false;
1312 loge("setNetworkSelectionModeManual " + ar.exception);
1313 }
1314 notifyRequester(request);
1315 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001316 break;
1317
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001318 case CMD_GET_MODEM_ACTIVITY_INFO:
1319 request = (MainThreadRequest) msg.obj;
1320 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001321 if (defaultPhone != null) {
1322 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001323 } else {
1324 ResultReceiver result = (ResultReceiver) request.argument;
1325 Bundle bundle = new Bundle();
1326 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001327 new ModemActivityInfo(0, 0, 0,
1328 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001329 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001330 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001331 break;
1332
Hall Liud0f208c2020-10-14 16:54:44 -07001333 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001334 ar = (AsyncResult) msg.obj;
1335 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001336 ResultReceiver result = (ResultReceiver) request.argument;
1337
Hall Liud0f208c2020-10-14 16:54:44 -07001338 ModemActivityInfo ret = null;
1339 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001340 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001341 // Update the last modem activity info and the result of the request.
1342 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1343 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001344 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001345 int[] txTimeMs = info.getTransmitTimeMillis();
1346 int[] lastModemTxTimeMs = mLastModemActivityInfo
1347 .getTransmitTimeMillis();
1348 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1349 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1350 }
Hall Liu49656c02020-10-09 19:00:11 -07001351 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001352 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1353 + mLastModemActivityInfo.getSleepTimeMillis());
1354 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1355 + mLastModemActivityInfo.getIdleTimeMillis());
1356 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1357 mLastModemActivityInfo.setReceiveTimeMillis(
1358 info.getReceiveTimeMillis()
1359 + mLastModemActivityInfo.getReceiveTimeMillis());
1360 }
Hall Liu49656c02020-10-09 19:00:11 -07001361 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001362 mLastModemActivityInfo.getSleepTimeMillis(),
1363 mLastModemActivityInfo.getIdleTimeMillis(),
1364 mLastModemActivityInfo.getTransmitTimeMillis(),
1365 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001366 } else {
1367 if (ar.result == null) {
1368 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001369 error = TelephonyManager.ModemActivityInfoException
1370 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001371 } else if (ar.exception instanceof CommandException) {
1372 loge("queryModemActivityInfo: CommandException: " +
1373 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001374 error = TelephonyManager.ModemActivityInfoException
1375 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001376 } else {
1377 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001378 error = TelephonyManager.ModemActivityInfoException
1379 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001380 }
1381 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001382 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001383 if (ret != null) {
1384 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1385 } else {
1386 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1387 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001388 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001389 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001390 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001391 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001392
Meng Wang1a7c35a2016-05-05 20:56:15 -07001393 case CMD_SET_ALLOWED_CARRIERS:
1394 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001395 CarrierRestrictionRules argument =
1396 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001397 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001398 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001399 break;
1400
1401 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1402 ar = (AsyncResult) msg.obj;
1403 request = (MainThreadRequest) ar.userObj;
1404 if (ar.exception == null && ar.result != null) {
1405 request.result = ar.result;
1406 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001407 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1408 if (ar.exception instanceof CommandException) {
1409 loge("setAllowedCarriers: CommandException: " + ar.exception);
1410 CommandException.Error error =
1411 ((CommandException) (ar.exception)).getCommandError();
1412 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1413 request.result =
1414 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1415 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001416 } else {
1417 loge("setAllowedCarriers: Unknown exception");
1418 }
1419 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001420 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001421 break;
1422
1423 case CMD_GET_ALLOWED_CARRIERS:
1424 request = (MainThreadRequest) msg.obj;
1425 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001426 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001427 break;
1428
1429 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1430 ar = (AsyncResult) msg.obj;
1431 request = (MainThreadRequest) ar.userObj;
1432 if (ar.exception == null && ar.result != null) {
1433 request.result = ar.result;
1434 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001435 request.result = new IllegalStateException(
1436 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001437 if (ar.result == null) {
1438 loge("getAllowedCarriers: Empty response");
1439 } else if (ar.exception instanceof CommandException) {
1440 loge("getAllowedCarriers: CommandException: " +
1441 ar.exception);
1442 } else {
1443 loge("getAllowedCarriers: Unknown exception");
1444 }
1445 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001446 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001447 break;
1448
Nathan Haroldb3014052017-01-25 15:57:32 -08001449 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1450 ar = (AsyncResult) msg.obj;
1451 request = (MainThreadRequest) ar.userObj;
1452 if (ar.exception == null && ar.result != null) {
1453 request.result = ar.result;
1454 } else {
1455 request.result = new IllegalArgumentException(
1456 "Failed to retrieve Forbidden Plmns");
1457 if (ar.result == null) {
1458 loge("getForbiddenPlmns: Empty response");
1459 } else {
1460 loge("getForbiddenPlmns: Unknown exception");
1461 }
1462 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001463 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001464 break;
1465
1466 case CMD_GET_FORBIDDEN_PLMNS:
1467 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001468 uiccPort = getUiccPortFromRequest(request);
1469 if (uiccPort == null) {
1470 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001471 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001472 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001473 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001474 break;
1475 }
1476 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001477 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001478 if (uiccApp == null) {
1479 loge("getForbiddenPlmns() no app with specified type -- "
1480 + appType);
1481 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001482 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001483 break;
1484 } else {
1485 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1486 + " specified type -- " + appType);
1487 }
1488 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1489 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1490 onCompleted);
1491 break;
1492
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001493 case CMD_SWITCH_SLOTS:
1494 request = (MainThreadRequest) msg.obj;
1495 int[] physicalSlots = (int[]) request.argument;
1496 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1497 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1498 break;
1499
1500 case EVENT_SWITCH_SLOTS_DONE:
1501 ar = (AsyncResult) msg.obj;
1502 request = (MainThreadRequest) ar.userObj;
1503 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001504 notifyRequester(request);
1505 break;
1506 case CMD_GET_NETWORK_SELECTION_MODE:
1507 request = (MainThreadRequest) msg.obj;
1508 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1509 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1510 break;
1511
1512 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1513 ar = (AsyncResult) msg.obj;
1514 request = (MainThreadRequest) ar.userObj;
1515 if (ar.exception != null) {
1516 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1517 } else {
1518 int mode = ((int[]) ar.result)[0];
1519 if (mode == 0) {
1520 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1521 } else {
1522 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1523 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001524 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001525 notifyRequester(request);
1526 break;
1527 case CMD_GET_CDMA_ROAMING_MODE:
1528 request = (MainThreadRequest) msg.obj;
1529 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1530 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1531 break;
1532 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1533 ar = (AsyncResult) msg.obj;
1534 request = (MainThreadRequest) ar.userObj;
1535 if (ar.exception != null) {
1536 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1537 } else {
1538 request.result = ((int[]) ar.result)[0];
1539 }
1540 notifyRequester(request);
1541 break;
1542 case CMD_SET_CDMA_ROAMING_MODE:
1543 request = (MainThreadRequest) msg.obj;
1544 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1545 int mode = (int) request.argument;
1546 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1547 break;
1548 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1549 ar = (AsyncResult) msg.obj;
1550 request = (MainThreadRequest) ar.userObj;
1551 request.result = ar.exception == null;
1552 notifyRequester(request);
1553 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001554 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1555 request = (MainThreadRequest) msg.obj;
1556 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1557 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1558 break;
1559 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1560 ar = (AsyncResult) msg.obj;
1561 request = (MainThreadRequest) ar.userObj;
1562 if (ar.exception != null) {
1563 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1564 } else {
1565 request.result = ((int[]) ar.result)[0];
1566 }
1567 notifyRequester(request);
1568 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001569 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1570 request = (MainThreadRequest) msg.obj;
1571 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1572 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001573 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1574 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001575 break;
1576 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1577 ar = (AsyncResult) msg.obj;
1578 request = (MainThreadRequest) ar.userObj;
1579 request.result = ar.exception == null;
1580 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001581 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001582 case CMD_GET_ALL_CELL_INFO:
1583 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001584 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001585 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001586 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001587 case EVENT_GET_ALL_CELL_INFO_DONE:
1588 ar = (AsyncResult) msg.obj;
1589 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001590 // If a timeout occurs, the response will be null
1591 request.result = (ar.exception == null && ar.result != null)
1592 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001593 synchronized (request) {
1594 request.notifyAll();
1595 }
1596 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001597 case CMD_REQUEST_CELL_INFO_UPDATE:
1598 request = (MainThreadRequest) msg.obj;
1599 request.phone.requestCellInfoUpdate(request.workSource,
1600 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1601 break;
1602 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1603 ar = (AsyncResult) msg.obj;
1604 request = (MainThreadRequest) ar.userObj;
1605 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1606 try {
1607 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001608 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001609 cb.onError(
1610 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1611 ar.exception.getClass().getName(),
1612 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001613 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001614 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001615 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001616 } else {
1617 // use the result as returned
1618 cb.onCellInfo((List<CellInfo>) ar.result);
1619 }
1620 } catch (RemoteException re) {
1621 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1622 }
1623 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001624 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001625 request = (MainThreadRequest) msg.obj;
1626 WorkSource ws = (WorkSource) request.argument;
1627 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001628 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001629 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001630 }
1631 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001632 ar = (AsyncResult) msg.obj;
1633 request = (MainThreadRequest) ar.userObj;
1634 if (ar.exception == null) {
1635 request.result = ar.result;
1636 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001637 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001638 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001639 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001640 }
1641
1642 synchronized (request) {
1643 request.notifyAll();
1644 }
1645 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001646 }
chen xu6dac5ab2018-10-26 17:39:23 -07001647 case CMD_MODEM_REBOOT:
1648 request = (MainThreadRequest) msg.obj;
1649 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001650 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001651 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001652 case EVENT_CMD_MODEM_REBOOT_DONE:
1653 handleNullReturnEvent(msg, "rebootModem");
1654 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001655 case CMD_REQUEST_ENABLE_MODEM:
1656 request = (MainThreadRequest) msg.obj;
1657 boolean enable = (boolean) request.argument;
1658 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001659 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001660 PhoneConfigurationManager.getInstance()
1661 .enablePhone(request.phone, enable, onCompleted);
1662 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001663 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001664 ar = (AsyncResult) msg.obj;
1665 request = (MainThreadRequest) ar.userObj;
1666 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001667 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001668 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001669 if ((boolean) request.result) {
1670 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1671 updateModemStateMetrics();
1672 } else {
1673 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1674 + ar.exception);
1675 }
1676 notifyRequester(request);
1677 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001678 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001679 case CMD_GET_MODEM_STATUS:
1680 request = (MainThreadRequest) msg.obj;
1681 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1682 PhoneConfigurationManager.getInstance()
1683 .getPhoneStatusFromModem(request.phone, onCompleted);
1684 break;
1685 case EVENT_GET_MODEM_STATUS_DONE:
1686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
1688 int id = request.phone.getPhoneId();
1689 if (ar.exception == null && ar.result != null) {
1690 request.result = ar.result;
1691 //update the cache as modem status has changed
1692 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1693 (boolean) request.result);
1694 } else {
1695 // Return true if modem status cannot be retrieved. For most cases,
1696 // modem status is on. And for older version modems, GET_MODEM_STATUS
1697 // and disable modem are not supported. Modem is always on.
1698 // TODO: this should be fixed in R to support a third
1699 // status UNKNOWN b/131631629
1700 request.result = true;
1701 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1702 + ar.exception);
1703 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001704 notifyRequester(request);
1705 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001706 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1707 request = (MainThreadRequest) msg.obj;
1708 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1709 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1710 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1711 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1712 break;
1713 }
1714 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1715 ar = (AsyncResult) msg.obj;
1716 request = (MainThreadRequest) ar.userObj;
1717 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1718 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1719 args.second.accept(ar.exception == null);
1720 notifyRequester(request);
1721 break;
1722 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001723 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1724 request = (MainThreadRequest) msg.obj;
1725 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1726 Phone phone = getPhoneFromRequest(request);
1727 if (phone != null) {
1728 phone.getSystemSelectionChannels(onCompleted);
1729 } else {
1730 loge("getSystemSelectionChannels: No phone object");
1731 request.result = new ArrayList<RadioAccessSpecifier>();
1732 notifyRequester(request);
1733 }
1734 break;
1735 }
1736 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1737 ar = (AsyncResult) msg.obj;
1738 request = (MainThreadRequest) ar.userObj;
1739 if (ar.exception == null && ar.result != null) {
1740 request.result = ar.result;
1741 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001742 request.result = new IllegalStateException(
1743 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001744 if (ar.result == null) {
1745 loge("getSystemSelectionChannels: Empty response");
1746 } else {
1747 loge("getSystemSelectionChannels: Unknown exception");
1748 }
1749 }
1750 notifyRequester(request);
1751 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001752 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1753 ar = (AsyncResult) msg.obj;
1754 request = (MainThreadRequest) ar.userObj;
1755 if (ar.exception == null && ar.result != null) {
1756 request.result = ar.result;
1757 } else {
1758 request.result = -1;
1759 loge("Failed to set Forbidden Plmns");
1760 if (ar.result == null) {
1761 loge("setForbidenPlmns: Empty response");
1762 } else if (ar.exception != null) {
1763 loge("setForbiddenPlmns: Exception: " + ar.exception);
1764 request.result = -1;
1765 } else {
1766 loge("setForbiddenPlmns: Unknown exception");
1767 }
1768 }
1769 notifyRequester(request);
1770 break;
1771 case CMD_SET_FORBIDDEN_PLMNS:
1772 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001773 uiccPort = getUiccPortFromRequest(request);
1774 if (uiccPort == null) {
1775 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001776 request.result = -1;
1777 notifyRequester(request);
1778 break;
1779 }
1780 Pair<Integer, List<String>> setFplmnsArgs =
1781 (Pair<Integer, List<String>>) request.argument;
1782 appType = setFplmnsArgs.first;
1783 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001784 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001785 if (uiccApp == null) {
1786 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1787 request.result = -1;
1788 loge("Failed to get UICC App");
1789 notifyRequester(request);
1790 } else {
1791 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1792 ((SIMRecords) uiccApp.getIccRecords())
1793 .setForbiddenPlmns(onCompleted, fplmns);
1794 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001795 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001796 case CMD_ERASE_MODEM_CONFIG:
1797 request = (MainThreadRequest) msg.obj;
1798 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1799 defaultPhone.eraseModemConfig(onCompleted);
1800 break;
1801 case EVENT_ERASE_MODEM_CONFIG_DONE:
1802 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001803 break;
zoey chene02881a2019-12-30 16:11:23 +08001804
Kai Shif70f46f2021-03-03 13:59:46 -08001805 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1806 request = (MainThreadRequest) msg.obj;
1807 request.result = defaultPhone.eraseDataInSharedPreferences();
1808 notifyRequester(request);
1809 break;
1810
zoey chene02881a2019-12-30 16:11:23 +08001811 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1812 request = (MainThreadRequest) msg.obj;
1813 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1814 Pair<String, String> changed = (Pair<String, String>) request.argument;
1815 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1816 changed.first, changed.second, onCompleted);
1817 break;
1818 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1819 ar = (AsyncResult) msg.obj;
1820 request = (MainThreadRequest) ar.userObj;
1821 if (ar.exception == null) {
1822 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001823 // If the operation is successful, update the PIN storage
1824 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1825 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001826 UiccController.getInstance().getPinStorage()
1827 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001828 } else {
1829 request.result = msg.arg1;
1830 }
1831 notifyRequester(request);
1832 break;
1833
Michele Berionne5e411512020-11-13 02:36:59 +00001834 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001835 request = (MainThreadRequest) msg.obj;
1836 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1837 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1838 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1839 enabled.first, enabled.second, onCompleted);
1840 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001841 }
zoey chene02881a2019-12-30 16:11:23 +08001842 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1843 ar = (AsyncResult) msg.obj;
1844 request = (MainThreadRequest) ar.userObj;
1845 if (ar.exception == null) {
1846 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001847 // If the operation is successful, update the PIN storage
1848 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1849 int phoneId = getPhoneFromRequest(request).getPhoneId();
1850 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001851 UiccController.getInstance().getPinStorage()
1852 .storePin(enabled.second, 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);
Rambo Wang6568f172021-02-03 16:56:47 -08001982 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001983 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);
Rambo Wang6568f172021-02-03 16:56:47 -08002010 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002011 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) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002552 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002553 }
2554
Wink Saville9de0f752013-10-22 19:04:03 -07002555 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 }
2557 }
2558
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002559 /**
2560 * This method has been removed due to privacy and stability concerns.
2561 */
2562 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002564 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2565 return;
Wink Saville36469e72014-06-11 15:17:00 -07002566 }
2567
Nathan Harold1f889d82020-06-04 17:05:26 -07002568 @Override
2569 public void updateServiceLocationWithPackageName(String callingPackage) {
2570 mApp.getSystemService(AppOpsManager.class)
2571 .checkPackage(Binder.getCallingUid(), callingPackage);
2572
Nathan Haroldf096d982020-11-18 17:18:06 -08002573 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002574 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2575 // Callers targeting S have no business invoking this method.
2576 return;
2577 }
2578
2579 LocationAccessPolicy.LocationPermissionResult locationResult =
2580 LocationAccessPolicy.checkLocationPermission(mApp,
2581 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2582 .setCallingPackage(callingPackage)
2583 .setCallingFeatureId(null)
2584 .setCallingPid(Binder.getCallingPid())
2585 .setCallingUid(Binder.getCallingUid())
2586 .setMethod("updateServiceLocation")
2587 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2588 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2589 .build());
2590 // Apps that lack location permission have no business calling this method;
2591 // however, because no permission was declared in the public API, denials must
2592 // all be "soft".
2593 switch (locationResult) {
2594 case DENIED_HARD: /* fall through */
2595 case DENIED_SOFT:
2596 return;
2597 }
2598
2599 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 final long identity = Binder.clearCallingIdentity();
2601 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002602 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002604 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 }
2610
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002611 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002612 @Override
2613 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002614 return isRadioOnWithFeature(callingPackage, null);
2615 }
2616
2617
2618 @Override
2619 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2620 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2621 callingFeatureId);
2622 }
2623
2624 @Deprecated
2625 @Override
2626 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2627 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002628 }
2629
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002630 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002631 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2632 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002634 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002635 return false;
2636 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002637
2638 final long identity = Binder.clearCallingIdentity();
2639 try {
2640 return isRadioOnForSubscriber(subId);
2641 } finally {
2642 Binder.restoreCallingIdentity(identity);
2643 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002644 }
2645
2646 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647 final long identity = Binder.clearCallingIdentity();
2648 try {
2649 final Phone phone = getPhone(subId);
2650 if (phone != null) {
2651 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2652 } else {
2653 return false;
2654 }
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 }
2659
2660 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002661 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 }
Wink Saville36469e72014-06-11 15:17:00 -07002663
Wink Savilleb564aae2014-10-23 10:18:09 -07002664 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002666
2667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 final Phone phone = getPhone(subId);
2670 if (phone != null) {
2671 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2672 }
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002675 }
Wink Saville36469e72014-06-11 15:17:00 -07002676 }
2677
2678 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002679 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002680 }
2681
Wink Savilleb564aae2014-10-23 10:18:09 -07002682 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
2687 final Phone phone = getPhone(subId);
2688 if (phone == null) {
2689 return false;
2690 }
2691 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2692 toggleRadioOnOffForSubscriber(subId);
2693 }
2694 return true;
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
Wink Saville36469e72014-06-11 15:17:00 -07002699
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002700 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002701 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002702 /*
2703 * If any of the Radios are available, it will need to be
2704 * shutdown. So return true if any Radio is available.
2705 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002706 final long identity = Binder.clearCallingIdentity();
2707 try {
2708 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2709 Phone phone = PhoneFactory.getPhone(i);
2710 if (phone != null && phone.isRadioAvailable()) return true;
2711 }
2712 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2713 return false;
2714 } finally {
2715 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002716 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002717 }
2718
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002720 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721 enforceModifyPermission();
2722
2723 final long identity = Binder.clearCallingIdentity();
2724 try {
2725 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2726 logv("Shutting down Phone " + i);
2727 shutdownRadioUsingPhoneId(i);
2728 }
2729 } finally {
2730 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002731 }
2732 }
2733
2734 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002735 Phone phone = PhoneFactory.getPhone(phoneId);
2736 if (phone != null && phone.isRadioAvailable()) {
2737 phone.shutdownRadio();
2738 }
2739 }
2740
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002742 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002743
2744 final long identity = Binder.clearCallingIdentity();
2745 try {
2746 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2747 if (defaultPhone != null) {
2748 defaultPhone.setRadioPower(turnOn);
2749 return true;
2750 } else {
2751 loge("There's no default phone.");
2752 return false;
2753 }
2754 } finally {
2755 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002756 }
Wink Saville36469e72014-06-11 15:17:00 -07002757 }
2758
Wink Savilleb564aae2014-10-23 10:18:09 -07002759 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002761
2762 final long identity = Binder.clearCallingIdentity();
2763 try {
2764 final Phone phone = getPhone(subId);
2765 if (phone != null) {
2766 phone.setRadioPower(turnOn);
2767 return true;
2768 } else {
2769 return false;
2770 }
2771 } finally {
2772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 }
2775
Wink Saville36469e72014-06-11 15:17:00 -07002776 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002777 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 public boolean enableDataConnectivity() {
2779 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780
2781 final long identity = Binder.clearCallingIdentity();
2782 try {
2783 int subId = mSubscriptionController.getDefaultDataSubId();
2784 final Phone phone = getPhone(subId);
2785 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002786 phone.getDataEnabledSettings().setDataEnabled(
2787 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788 return true;
2789 } else {
2790 return false;
2791 }
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002795 }
2796
Wink Saville36469e72014-06-11 15:17:00 -07002797 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002798 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002799 public boolean disableDataConnectivity() {
2800 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801
2802 final long identity = Binder.clearCallingIdentity();
2803 try {
2804 int subId = mSubscriptionController.getDefaultDataSubId();
2805 final Phone phone = getPhone(subId);
2806 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002807 phone.getDataEnabledSettings().setDataEnabled(
2808 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002809 return true;
2810 } else {
2811 return false;
2812 }
2813 } finally {
2814 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002816 }
2817
Sanket Padawe356d7632015-06-22 14:03:32 -07002818 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002819 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 final Phone phone = getPhone(subId);
2823 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002824 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825 } else {
2826 return false;
2827 }
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 }
2832
2833 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002834 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002835 }
2836
pkanwarae03a6b2016-11-06 20:37:09 -08002837 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838 enforceCallPermission();
2839
2840 final long identity = Binder.clearCallingIdentity();
2841 try {
2842 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2843 return;
2844 }
2845 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2846 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2847 } finally {
2848 Binder.restoreCallingIdentity(identity);
2849 }
pkanwar32d516d2016-10-14 19:37:38 -07002850 };
2851
Wink Savilleb564aae2014-10-23 10:18:09 -07002852 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002853 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854
2855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2858 return false;
2859 }
2860 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002863 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002864 }
2865
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002866 /**
2867 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2868 * tag on getCallState Binder call.
2869 */
2870 @Deprecated
2871 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002873 if (CompatChanges.isChangeEnabled(
2874 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2875 Binder.getCallingUid())) {
2876 // Do not allow this API to be called on API version 31+, it should only be
2877 // called on old apps using this Binder call directly.
2878 throw new SecurityException("This method can only be used for applications "
2879 + "targeting API version 30 or less.");
2880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881 final long identity = Binder.clearCallingIdentity();
2882 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002883 Phone phone = getPhone(getDefaultSubscription());
2884 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2885 PhoneConstantConversions.convertCallState(phone.getState());
2886 } finally {
2887 Binder.restoreCallingIdentity(identity);
2888 }
2889 }
2890
2891 @Override
2892 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2893 if (CompatChanges.isChangeEnabled(
2894 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2895 Binder.getCallingUid())) {
2896 // Check READ_PHONE_STATE for API version 31+
2897 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2898 featureId, "getCallStateForSubscription")) {
2899 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2900 + "targeting API level 31+.");
2901 }
2902 }
2903 final long identity = Binder.clearCallingIdentity();
2904 try {
2905 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2907 PhoneConstantConversions.convertCallState(phone.getState());
2908 } finally {
2909 Binder.restoreCallingIdentity(identity);
2910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002911 }
2912
Sanket Padawe356d7632015-06-22 14:03:32 -07002913 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002914 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002915 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2916 }
2917
2918 @Override
2919 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920 final long identity = Binder.clearCallingIdentity();
2921 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002922 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923 if (phone != null) {
2924 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2925 } else {
2926 return PhoneConstantConversions.convertDataState(
2927 PhoneConstants.DataState.DISCONNECTED);
2928 }
2929 } finally {
2930 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002931 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002932 }
2933
Sanket Padawe356d7632015-06-22 14:03:32 -07002934 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002935 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002936 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2937 }
2938
2939 @Override
2940 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 final long identity = Binder.clearCallingIdentity();
2942 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002943 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002944 if (phone != null) {
2945 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2946 } else {
2947 return TelephonyManager.DATA_ACTIVITY_NONE;
2948 }
2949 } finally {
2950 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002952 }
2953
2954 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002955 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002956 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002957 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002958
2959 LocationAccessPolicy.LocationPermissionResult locationResult =
2960 LocationAccessPolicy.checkLocationPermission(mApp,
2961 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2962 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002963 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002964 .setCallingPid(Binder.getCallingPid())
2965 .setCallingUid(Binder.getCallingUid())
2966 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002967 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002968 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2969 .build());
2970 switch (locationResult) {
2971 case DENIED_HARD:
2972 throw new SecurityException("Not allowed to access cell location");
2973 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002974 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2975 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002976 }
2977
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002978 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002982 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002983 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002984 } finally {
2985 Binder.restoreCallingIdentity(identity);
2986 }
Svetoslav64fad262015-04-14 14:35:21 -07002987 }
2988
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002989 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002990 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002991 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2992 // registered cell info, so return a NULL country instead.
2993 final long identity = Binder.clearCallingIdentity();
2994 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002995 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2996 // Get default phone in this case.
2997 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2998 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002999 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003001 if (phone == null) return "";
3002 ServiceStateTracker sst = phone.getServiceStateTracker();
3003 if (sst == null) return "";
3004 LocaleTracker lt = sst.getLocaleTracker();
3005 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003006 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003007 } finally {
3008 Binder.restoreCallingIdentity(identity);
3009 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003010 }
3011
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003012 /**
3013 * This method was removed due to potential issues caused by performing partial
3014 * updates of service state, and lack of a credible use case.
3015 *
3016 * This has the ability to break the telephony implementation by disabling notification of
3017 * changes in device connectivity. DO NOT USE THIS!
3018 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003019 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020 public void enableLocationUpdates() {
3021 mApp.enforceCallingOrSelfPermission(
3022 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003023 }
3024
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003025 /**
3026 * This method was removed due to potential issues caused by performing partial
3027 * updates of service state, and lack of a credible use case.
3028 *
3029 * This has the ability to break the telephony implementation by disabling notification of
3030 * changes in device connectivity. DO NOT USE THIS!
3031 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003032 @Override
3033 public void disableLocationUpdates() {
3034 mApp.enforceCallingOrSelfPermission(
3035 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003036 }
3037
3038 @Override
3039 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003040 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3041 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003042 try {
3043 mApp.getSystemService(AppOpsManager.class)
3044 .checkPackage(Binder.getCallingUid(), callingPackage);
3045 } catch (SecurityException e) {
3046 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3047 throw e;
3048 }
3049
Nathan Haroldf096d982020-11-18 17:18:06 -08003050 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003051 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3052 throw new SecurityException(
3053 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3054 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003055
Jordan Liu1617b712019-07-10 15:06:26 -07003056 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003057 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3058 return null;
3059 }
Svetoslav64fad262015-04-14 14:35:21 -07003060
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003061 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003062
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003063 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003064 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003065
Nathan Haroldf180aac2018-06-01 18:43:55 -07003066 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3067 for (CellInfo ci : info) {
3068 if (ci instanceof CellInfoGsm) {
3069 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3070 } else if (ci instanceof CellInfoWcdma) {
3071 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3072 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003073 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003074 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003075 }
3076
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003077 private List<CellInfo> getCachedCellInfo() {
3078 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3079 for (Phone phone : PhoneFactory.getPhones()) {
3080 List<CellInfo> info = phone.getAllCellInfo();
3081 if (info != null) cellInfos.addAll(info);
3082 }
3083 return cellInfos;
3084 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003085
3086 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003087 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003088 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003089 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003090
3091 LocationAccessPolicy.LocationPermissionResult locationResult =
3092 LocationAccessPolicy.checkLocationPermission(mApp,
3093 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3094 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003095 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003096 .setCallingPid(Binder.getCallingPid())
3097 .setCallingUid(Binder.getCallingUid())
3098 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003099 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003100 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3101 .build());
3102 switch (locationResult) {
3103 case DENIED_HARD:
3104 throw new SecurityException("Not allowed to access cell info");
3105 case DENIED_SOFT:
3106 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003107 }
3108
Nathan Haroldf096d982020-11-18 17:18:06 -08003109 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003110 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3111 return getCachedCellInfo();
3112 }
3113
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003114 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003115 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116 final long identity = Binder.clearCallingIdentity();
3117 try {
3118 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3119 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003120 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003121 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003122 if (info != null) cellInfos.addAll(info);
3123 }
3124 return cellInfos;
3125 } finally {
3126 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003127 }
3128 }
3129
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003130 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003131 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3132 String callingFeatureId) {
3133 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3134 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003135 }
3136
3137 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003138 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3139 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003140 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003141 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003142 }
3143
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003144 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3145 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003146 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003147 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003148
3149 LocationAccessPolicy.LocationPermissionResult locationResult =
3150 LocationAccessPolicy.checkLocationPermission(mApp,
3151 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3152 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003153 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003154 .setCallingPid(Binder.getCallingPid())
3155 .setCallingUid(Binder.getCallingUid())
3156 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003157 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3158 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003159 .build());
3160 switch (locationResult) {
3161 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003162 if (TelephonyPermissions
3163 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003164 // Safetynet logging for b/154934934
3165 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3166 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003167 throw new SecurityException("Not allowed to access cell info");
3168 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003169 if (TelephonyPermissions
3170 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003171 // Safetynet logging for b/154934934
3172 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3173 }
Nathan Harold5320c422019-05-09 10:26:08 -07003174 try {
3175 cb.onCellInfo(new ArrayList<CellInfo>());
3176 } catch (RemoteException re) {
3177 // Drop without consequences
3178 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003179 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003180 }
3181
Nathan Harolda939a962019-05-09 10:13:47 -07003182
3183 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003184 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3185
3186 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3187 }
3188
3189 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003190 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003191 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003192 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193
3194 final long identity = Binder.clearCallingIdentity();
3195 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003196 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197 } finally {
3198 Binder.restoreCallingIdentity(identity);
3199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 }
3201
Shishir Agrawala9f32182016-04-12 12:00:16 -07003202 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003203 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003204 Phone phone = PhoneFactory.getPhone(slotIndex);
3205 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003206 return null;
3207 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003208 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003209 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003210 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003211 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003212 return null;
3213 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214
3215 final long identity = Binder.clearCallingIdentity();
3216 try {
3217 return phone.getImei();
3218 } finally {
3219 Binder.restoreCallingIdentity(identity);
3220 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003221 }
3222
3223 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003224 public String getTypeAllocationCodeForSlot(int slotIndex) {
3225 Phone phone = PhoneFactory.getPhone(slotIndex);
3226 String tac = null;
3227 if (phone != null) {
3228 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003229 try {
3230 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3231 } catch (IndexOutOfBoundsException e) {
3232 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3233 return null;
3234 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003235 }
3236 return tac;
3237 }
3238
3239 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003240 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003241 try {
3242 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3243 } catch (SecurityException se) {
3244 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3245 throw new SecurityException("Package " + callingPackage + " does not belong to "
3246 + Binder.getCallingUid());
3247 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003248 Phone phone = PhoneFactory.getPhone(slotIndex);
3249 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003250 return null;
3251 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003252
Jeff Davidson913390f2018-02-23 17:11:49 -08003253 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003254 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003255 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003256 return null;
3257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003258
3259 final long identity = Binder.clearCallingIdentity();
3260 try {
3261 return phone.getMeid();
3262 } finally {
3263 Binder.restoreCallingIdentity(identity);
3264 }
Jack Yu2af8d712017-03-15 17:14:14 -07003265 }
3266
3267 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003268 public String getManufacturerCodeForSlot(int slotIndex) {
3269 Phone phone = PhoneFactory.getPhone(slotIndex);
3270 String manufacturerCode = null;
3271 if (phone != null) {
3272 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003273 try {
3274 manufacturerCode =
3275 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3276 } catch (IndexOutOfBoundsException e) {
3277 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3278 return null;
3279 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003280 }
3281 return manufacturerCode;
3282 }
3283
3284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003285 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3286 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003287 Phone phone = PhoneFactory.getPhone(slotIndex);
3288 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003289 return null;
3290 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003291 int subId = phone.getSubId();
3292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003293 mApp, subId, callingPackage, callingFeatureId,
3294 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003295 return null;
3296 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003297
3298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 return phone.getDeviceSvn();
3301 } finally {
3302 Binder.restoreCallingIdentity(identity);
3303 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003304 }
3305
fionaxu43304da2017-11-27 22:51:16 -08003306 @Override
3307 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003308 final long identity = Binder.clearCallingIdentity();
3309 try {
3310 final Phone phone = getPhone(subId);
3311 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3312 } finally {
3313 Binder.restoreCallingIdentity(identity);
3314 }
fionaxu43304da2017-11-27 22:51:16 -08003315 }
3316
3317 @Override
3318 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003319 final long identity = Binder.clearCallingIdentity();
3320 try {
3321 final Phone phone = getPhone(subId);
3322 return phone == null ? null : phone.getCarrierName();
3323 } finally {
3324 Binder.restoreCallingIdentity(identity);
3325 }
fionaxu43304da2017-11-27 22:51:16 -08003326 }
3327
calvinpanffe225e2018-11-01 19:43:06 +08003328 @Override
chen xu0026ca62019-03-06 15:28:50 -08003329 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003330 final long identity = Binder.clearCallingIdentity();
3331 try {
3332 final Phone phone = getPhone(subId);
3333 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003334 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
3338 }
3339
3340 @Override
chen xu0026ca62019-03-06 15:28:50 -08003341 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003345 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003346 } finally {
3347 Binder.restoreCallingIdentity(identity);
3348 }
3349 }
3350
chen xu651eec72018-11-11 19:03:44 -08003351 @Override
chen xu864e11c2018-12-06 22:10:03 -08003352 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3353 if (!isSubscriptionMccMnc) {
3354 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3355 }
chen xu651eec72018-11-11 19:03:44 -08003356 final Phone phone = PhoneFactory.getPhone(slotIndex);
3357 if (phone == null) {
3358 return TelephonyManager.UNKNOWN_CARRIER_ID;
3359 }
3360 final long identity = Binder.clearCallingIdentity();
3361 try {
3362 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3363 } finally {
3364 Binder.restoreCallingIdentity(identity);
3365 }
3366 }
3367
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003368 //
3369 // Internal helper methods.
3370 //
3371
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003372 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003373 * Make sure the caller is the calling package itself
3374 *
3375 * @throws SecurityException if the caller is not the calling package
3376 */
3377 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3378 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003379 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3380 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003381 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003382 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003383 } catch (PackageManager.NameNotFoundException e) {
3384 // packageUid is -1
3385 }
3386 if (packageUid != callingUid) {
3387 throw new SecurityException(message + ": Package " + callingPackage
3388 + " does not belong to " + callingUid);
3389 }
3390 }
3391
3392 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003393 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3394 *
3395 * @throws SecurityException if the caller does not have the required permission
3396 */
3397 private void enforceModifyPermission() {
3398 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3399 }
3400
Shuo Qiancd19c462020-01-16 20:51:11 -08003401 /**
3402 * Make sure the caller is system.
3403 *
3404 * @throws SecurityException if the caller is not system.
3405 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003406 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003407 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3408 throw new SecurityException("Caller must be system");
3409 }
3410 }
3411
Shuo Qian3b6ee772019-11-13 17:43:31 -08003412 private void enforceActiveEmergencySessionPermission() {
3413 mApp.enforceCallingOrSelfPermission(
3414 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3415 }
3416
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003417 /**
3418 * Make sure the caller has the CALL_PHONE permission.
3419 *
3420 * @throws SecurityException if the caller does not have the required permission
3421 */
3422 private void enforceCallPermission() {
3423 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3424 }
3425
paulhu5a773602019-08-23 19:17:33 +08003426 private void enforceSettingsPermission() {
3427 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003428 }
3429
Michele Berionne5e411512020-11-13 02:36:59 +00003430 private void enforceRebootPermission() {
3431 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3432 }
3433
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003434 private String createTelUrl(String number) {
3435 if (TextUtils.isEmpty(number)) {
3436 return null;
3437 }
3438
Jake Hambye994d462014-02-03 13:10:13 -08003439 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003440 }
3441
Ihab Awadf9e92732013-12-05 18:02:52 -08003442 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003443 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3444 }
3445
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003446 private static void logv(String msg) {
3447 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3448 }
3449
Ihab Awadf9e92732013-12-05 18:02:52 -08003450 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003451 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3452 }
3453
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003454 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003456 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003457 }
3458
Sanket Padawe356d7632015-06-22 14:03:32 -07003459 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003460 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 final Phone phone = PhoneFactory.getPhone(slotIndex);
3464 if (phone == null) {
3465 return PhoneConstants.PHONE_TYPE_NONE;
3466 } else {
3467 return phone.getPhoneType();
3468 }
3469 } finally {
3470 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003471 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003472 }
3473
3474 /**
3475 * Returns the CDMA ERI icon index to display
3476 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003477 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003478 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3479 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3480 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003481 }
3482
Sanket Padawe356d7632015-06-22 14:03:32 -07003483 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003484 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3485 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003486 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003487 mApp, subId, callingPackage, callingFeatureId,
3488 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003489 return -1;
3490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003491
3492 final long identity = Binder.clearCallingIdentity();
3493 try {
3494 final Phone phone = getPhone(subId);
3495 if (phone != null) {
3496 return phone.getCdmaEriIconIndex();
3497 } else {
3498 return -1;
3499 }
3500 } finally {
3501 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003502 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003503 }
3504
3505 /**
3506 * Returns the CDMA ERI icon mode,
3507 * 0 - ON
3508 * 1 - FLASHING
3509 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003510 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003511 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3512 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3513 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003514 }
3515
Sanket Padawe356d7632015-06-22 14:03:32 -07003516 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003517 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3518 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003519 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003520 mApp, subId, callingPackage, callingFeatureId,
3521 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003522 return -1;
3523 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003524
3525 final long identity = Binder.clearCallingIdentity();
3526 try {
3527 final Phone phone = getPhone(subId);
3528 if (phone != null) {
3529 return phone.getCdmaEriIconMode();
3530 } else {
3531 return -1;
3532 }
3533 } finally {
3534 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003536 }
3537
3538 /**
3539 * Returns the CDMA ERI text,
3540 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003541 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003542 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3543 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3544 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003545 }
3546
Sanket Padawe356d7632015-06-22 14:03:32 -07003547 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003548 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3549 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003550 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003551 mApp, subId, callingPackage, callingFeatureId,
3552 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003553 return null;
3554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003555
3556 final long identity = Binder.clearCallingIdentity();
3557 try {
3558 final Phone phone = getPhone(subId);
3559 if (phone != null) {
3560 return phone.getCdmaEriText();
3561 } else {
3562 return null;
3563 }
3564 } finally {
3565 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003567 }
3568
3569 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003570 * Returns the CDMA MDN.
3571 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003572 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003573 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3575 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576
3577 final long identity = Binder.clearCallingIdentity();
3578 try {
3579 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003580 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581 return phone.getLine1Number();
3582 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003583 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003584 return null;
3585 }
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003588 }
3589 }
3590
3591 /**
3592 * Returns the CDMA MIN.
3593 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003594 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003595 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3597 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598
3599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 final Phone phone = getPhone(subId);
3602 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3603 return phone.getCdmaMin();
3604 } else {
3605 return null;
3606 }
3607 } finally {
3608 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003609 }
3610 }
3611
Hall Liud892bec2018-11-30 14:51:45 -08003612 @Override
3613 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3614 INumberVerificationCallback callback, String callingPackage) {
3615 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3616 != PERMISSION_GRANTED) {
3617 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3618 }
3619 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3620
3621 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3622 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003623 throw new SecurityException("Calling package must be configured in the device config: "
3624 + "calling package: " + callingPackage
3625 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003626 }
3627
3628 if (range == null) {
3629 throw new NullPointerException("Range must be non-null");
3630 }
3631
3632 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003633 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003634
3635 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3636 }
3637
Junda Liuca05d5d2014-08-14 22:36:34 -07003638 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003639 * Returns true if CDMA provisioning needs to run.
3640 */
3641 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003642 final long identity = Binder.clearCallingIdentity();
3643 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003644 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003645 } finally {
3646 Binder.restoreCallingIdentity(identity);
3647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003648 }
3649
3650 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003651 * Sets the voice mail number of a given subId.
3652 */
3653 @Override
3654 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003655 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3656 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657
3658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3661 new Pair<String, String>(alphaTag, number), new Integer(subId));
3662 return success;
3663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003666 }
3667
Ta-wei Yen87c49842016-05-13 21:19:52 -07003668 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003669 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3670 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003671 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3672 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003673 if (!TextUtils.equals(callingPackage, systemDialer)) {
3674 throw new SecurityException("caller must be system dialer");
3675 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003676
3677 final long identity = Binder.clearCallingIdentity();
3678 try {
3679 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3680 if (phoneAccountHandle == null) {
3681 return null;
3682 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003683 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003684 } finally {
3685 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003686 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003687 }
3688
3689 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003690 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3691 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003692 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003694 mApp, subId, callingPackage, callingFeatureId,
3695 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003696 return null;
3697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003698
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003699 final long identity = Binder.clearCallingIdentity();
3700 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003701 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003702 } finally {
3703 Binder.restoreCallingIdentity(identity);
3704 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003705 }
3706
3707 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003708 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3709 VisualVoicemailSmsFilterSettings settings) {
3710 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003711
3712 final long identity = Binder.clearCallingIdentity();
3713 try {
3714 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003715 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003719 }
3720
3721 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003722 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3723 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724
3725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003728 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729 } finally {
3730 Binder.restoreCallingIdentity(identity);
3731 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003732 }
3733
3734 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003735 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3736 String callingPackage, int subId) {
3737 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003738
3739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003742 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743 } finally {
3744 Binder.restoreCallingIdentity(identity);
3745 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003746 }
3747
3748 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003749 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003750 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751
3752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003755 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003756 } finally {
3757 Binder.restoreCallingIdentity(identity);
3758 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003759 }
3760
3761 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003762 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3763 String callingAttributionTag, int subId, String number, int port, String text,
3764 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003765 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003766 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003767 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003768 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003769 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3770 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003771 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003772
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003773 /**
fionaxu0152e512016-11-14 13:36:14 -08003774 * Sets the voice activation state of a given subId.
3775 */
3776 @Override
3777 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3779 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003780
3781 final long identity = Binder.clearCallingIdentity();
3782 try {
3783 final Phone phone = getPhone(subId);
3784 if (phone != null) {
3785 phone.setVoiceActivationState(activationState);
3786 } else {
3787 loge("setVoiceActivationState fails with invalid subId: " + subId);
3788 }
3789 } finally {
3790 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003791 }
3792 }
3793
3794 /**
3795 * Sets the data activation state of a given subId.
3796 */
3797 @Override
3798 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3800 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003801
3802 final long identity = Binder.clearCallingIdentity();
3803 try {
3804 final Phone phone = getPhone(subId);
3805 if (phone != null) {
3806 phone.setDataActivationState(activationState);
3807 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003808 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809 }
3810 } finally {
3811 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003812 }
3813 }
3814
3815 /**
3816 * Returns the voice activation state of a given subId.
3817 */
3818 @Override
3819 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003820 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003821
fionaxu0152e512016-11-14 13:36:14 -08003822 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003823 final long identity = Binder.clearCallingIdentity();
3824 try {
3825 if (phone != null) {
3826 return phone.getVoiceActivationState();
3827 } else {
3828 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3829 }
3830 } finally {
3831 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003832 }
3833 }
3834
3835 /**
3836 * Returns the data activation state of a given subId.
3837 */
3838 @Override
3839 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003840 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003841
fionaxu0152e512016-11-14 13:36:14 -08003842 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003843 final long identity = Binder.clearCallingIdentity();
3844 try {
3845 if (phone != null) {
3846 return phone.getDataActivationState();
3847 } else {
3848 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3849 }
3850 } finally {
3851 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003852 }
3853 }
3854
3855 /**
Wink Saville36469e72014-06-11 15:17:00 -07003856 * Returns the unread count of voicemails for a subId
3857 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003858 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003859 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3860 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003862 mApp, subId, callingPackage, callingFeatureId,
3863 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003864 return 0;
3865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 final Phone phone = getPhone(subId);
3869 if (phone != null) {
3870 return phone.getVoiceMessageCount();
3871 } else {
3872 return 0;
3873 }
3874 } finally {
3875 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003877 }
3878
3879 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003880 * returns true, if the device is in a state where both voice and data
3881 * are supported simultaneously. This can change based on location or network condition.
3882 */
3883 @Override
3884 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003885 final long identity = Binder.clearCallingIdentity();
3886 try {
3887 final Phone phone = getPhone(subId);
3888 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3889 } finally {
3890 Binder.restoreCallingIdentity(identity);
3891 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003892 }
3893
3894 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003895 * Send the dialer code if called from the current default dialer or the caller has
3896 * carrier privilege.
3897 * @param inputCode The dialer code to send
3898 */
3899 @Override
3900 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003901 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003902 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003903 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3904 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003905 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003906 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003907 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003908 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909
3910 final long identity = Binder.clearCallingIdentity();
3911 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003912 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913 } finally {
3914 Binder.restoreCallingIdentity(identity);
3915 }
fionaxu235cc5e2017-03-06 22:25:57 -08003916 }
3917
Pengquan Menga1bb6272018-09-06 09:59:22 -07003918 @Override
3919 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003920 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003921 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003922 mApp, subId, "getNetworkSelectionMode");
3923 final long identity = Binder.clearCallingIdentity();
3924 try {
3925 if (!isActiveSubscription(subId)) {
3926 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3927 }
3928 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3929 } finally {
3930 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003931 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003932 }
3933
Brad Ebinger35c841c2018-10-01 10:40:55 -07003934 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003935 public boolean isInEmergencySmsMode() {
3936 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3937 final long identity = Binder.clearCallingIdentity();
3938 try {
3939 for (Phone phone : PhoneFactory.getPhones()) {
3940 if (phone.isInEmergencySmsMode()) {
3941 return true;
3942 }
3943 }
3944 } finally {
3945 Binder.restoreCallingIdentity(identity);
3946 }
3947 return false;
3948 }
3949
shilu366312e2019-12-17 09:28:10 -08003950 /**
3951 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3952 * @param subId The subscription to use to check the configuration.
3953 * @param c The callback that will be used to send the result.
3954 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003955 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003956 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3957 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003958 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003959 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003960
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003961 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3962 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3963 "IMS not available on device.");
3964 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003965 final long token = Binder.clearCallingIdentity();
3966 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003967 int slotId = getSlotIndexOrException(subId);
3968 verifyImsMmTelConfiguredOrThrow(slotId);
3969 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003970 } catch (ImsException e) {
3971 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 } finally {
3973 Binder.restoreCallingIdentity(token);
3974 }
3975 }
3976
shilu366312e2019-12-17 09:28:10 -08003977 /**
3978 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3979 * @param subId The subscription to use to check the configuration.
3980 * @param c The callback that will be used to send the result.
3981 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003983 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003984 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003985 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003986 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3987 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3988 }
Meng Wangafbc5852019-09-19 17:37:13 -07003989 final long token = Binder.clearCallingIdentity();
3990 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003991 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3992 .removeRegistrationCallbackForSubscription(c, subId);
3993 } catch (ImsException e) {
3994 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3995 + "is inactive, ignoring unregister.");
3996 // If the subscription is no longer active, just return, since the callback
3997 // will already have been removed internally.
3998 } finally {
3999 Binder.restoreCallingIdentity(token);
4000 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 }
4002
Brad Ebingera34a6c22019-10-22 17:36:18 -07004003 /**
4004 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4005 */
4006 @Override
4007 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4008 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4009 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4010 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4011 "IMS not available on device.");
4012 }
4013 final long token = Binder.clearCallingIdentity();
4014 try {
4015 Phone phone = getPhone(subId);
4016 if (phone == null) {
4017 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4018 + subId + "'");
4019 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4020 }
4021 phone.getImsRegistrationState(regState -> {
4022 try {
4023 consumer.accept((regState == null)
4024 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4025 } catch (RemoteException e) {
4026 // Ignore if the remote process is no longer available to call back.
4027 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4028 }
4029 });
4030 } finally {
4031 Binder.restoreCallingIdentity(token);
4032 }
4033 }
4034
4035 /**
4036 * Get the transport type for the IMS service registration state.
4037 */
4038 @Override
4039 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004040 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004041 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004042 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4043 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4044 "IMS not available on device.");
4045 }
4046 final long token = Binder.clearCallingIdentity();
4047 try {
4048 Phone phone = getPhone(subId);
4049 if (phone == null) {
4050 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4051 + subId + "'");
4052 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4053 }
4054 phone.getImsRegistrationTech(regTech -> {
4055 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4056 int regTechConverted = (regTech == null)
4057 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4058 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4059 regTechConverted);
4060 try {
4061 consumer.accept(regTechConverted);
4062 } catch (RemoteException e) {
4063 // Ignore if the remote process is no longer available to call back.
4064 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4065 }
4066 });
4067 } finally {
4068 Binder.restoreCallingIdentity(token);
4069 }
4070 }
4071
shilu366312e2019-12-17 09:28:10 -08004072 /**
4073 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4074 * @param subId The subscription to use to check the configuration.
4075 * @param c The callback that will be used to send the result.
4076 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004077 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004078 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4079 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004080 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004081 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004082 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4083 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4084 "IMS not available on device.");
4085 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 final long token = Binder.clearCallingIdentity();
4087 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004088 int slotId = getSlotIndexOrException(subId);
4089 verifyImsMmTelConfiguredOrThrow(slotId);
4090 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004091 } catch (ImsException e) {
4092 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004093 } finally {
4094 Binder.restoreCallingIdentity(token);
4095 }
4096 }
4097
shilu366312e2019-12-17 09:28:10 -08004098 /**
4099 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4100 * @param subId The subscription to use to check the configuration.
4101 * @param c The callback that will be used to send the result.
4102 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004104 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004105 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004106 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004107 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4108 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4109 }
Meng Wangafbc5852019-09-19 17:37:13 -07004110
4111 final long token = Binder.clearCallingIdentity();
4112 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004113 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004114 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004115 } catch (ImsException e) {
4116 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4117 + "is inactive, ignoring unregister.");
4118 // If the subscription is no longer active, just return, since the callback
4119 // will already have been removed internally.
4120 } finally {
4121 Binder.restoreCallingIdentity(token);
4122 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 }
4124
4125 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004126 public boolean isCapable(int subId, int capability, int regTech) {
4127 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004128 final long token = Binder.clearCallingIdentity();
4129 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004130 int slotId = getSlotIndexOrException(subId);
4131 verifyImsMmTelConfiguredOrThrow(slotId);
4132 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004133 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4135 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004136 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004137 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4138 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 } finally {
4140 Binder.restoreCallingIdentity(token);
4141 }
4142 }
4143
4144 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004145 public boolean isAvailable(int subId, int capability, int regTech) {
4146 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004147 final long token = Binder.clearCallingIdentity();
4148 try {
4149 Phone phone = getPhone(subId);
4150 if (phone == null) return false;
4151 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004152 } catch (com.android.ims.ImsException e) {
4153 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4154 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 } finally {
4156 Binder.restoreCallingIdentity(token);
4157 }
4158 }
4159
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004160 /**
4161 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4162 * subscription.
4163 * @param subId The subscription to use to check the configuration.
4164 * @param callback The callback that will be used to send the result.
4165 * @param capability The MmTelFeature capability that will be used to send the result.
4166 * @param transportType The transport type of the MmTelFeature capability.
4167 */
4168 @Override
4169 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4170 int transportType) {
4171 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4172 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4173 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4174 "IMS not available on device.");
4175 }
4176 final long token = Binder.clearCallingIdentity();
4177 try {
4178 int slotId = getSlotIndex(subId);
4179 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4180 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4181 + subId + "'");
4182 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4183 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004184 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004185 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4186 transportType, aBoolean -> {
4187 try {
4188 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4189 } catch (RemoteException e) {
4190 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4191 + "running. Ignore");
4192 }
4193 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004194 } catch (ImsException e) {
4195 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004196 } finally {
4197 Binder.restoreCallingIdentity(token);
4198 }
4199 }
4200
shilu366312e2019-12-17 09:28:10 -08004201 /**
4202 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4203 * @param subId The subscription to use to check the configuration.
4204 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004205 @Override
4206 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004207 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004208 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004209
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 final long token = Binder.clearCallingIdentity();
4211 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004212 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004213 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004214 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004215 } catch (ImsException e) {
4216 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004217 } finally {
4218 Binder.restoreCallingIdentity(token);
4219 }
4220 }
4221
4222 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004223 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004224 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004225 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004226 final long identity = Binder.clearCallingIdentity();
4227 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004228 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004229 // This setting doesn't require an active ImsService connection, so do not verify. The
4230 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004231 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004232 } catch (ImsException e) {
4233 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 } finally {
4235 Binder.restoreCallingIdentity(identity);
4236 }
4237 }
4238
shilu366312e2019-12-17 09:28:10 -08004239 /**
4240 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4241 * @param subId The subscription to use to check the configuration.
4242 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004243 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004244 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004245 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004246 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004247 final long identity = Binder.clearCallingIdentity();
4248 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004249 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004250 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004251 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004252 } catch (ImsException e) {
4253 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004254 } finally {
4255 Binder.restoreCallingIdentity(identity);
4256 }
4257 }
4258
4259 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004260 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004262 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004263 final long identity = Binder.clearCallingIdentity();
4264 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004265 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004266 // This setting doesn't require an active ImsService connection, so do not verify. The
4267 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004268 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004269 } catch (ImsException e) {
4270 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 } finally {
4272 Binder.restoreCallingIdentity(identity);
4273 }
4274 }
4275
shilu366312e2019-12-17 09:28:10 -08004276 /**
4277 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4278 * @param subId The subscription to use to check the configuration.
4279 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004280 @Override
4281 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004282 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004283 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 final long identity = Binder.clearCallingIdentity();
4285 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004286 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004287 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004288 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004289 } catch (ImsException e) {
4290 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 } finally {
4292 Binder.restoreCallingIdentity(identity);
4293 }
4294 }
4295
4296 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004297 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004299 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004300 final long identity = Binder.clearCallingIdentity();
4301 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004302 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004303 // This setting doesn't require an active ImsService connection, so do not verify. The
4304 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004305 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004306 } catch (ImsException e) {
4307 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004308 } finally {
4309 Binder.restoreCallingIdentity(identity);
4310 }
4311 }
4312
shilu366312e2019-12-17 09:28:10 -08004313 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004314 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4315 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4316 * @param subId The subscription to use to check the configuration.
4317 */
4318 @Override
4319 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004320 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004321 mApp, subId, "isCrossSimCallingEnabledByUser");
4322 final long identity = Binder.clearCallingIdentity();
4323 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004324 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004325 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004326 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004327 } catch (ImsException e) {
4328 throw new ServiceSpecificException(e.getCode());
4329 } finally {
4330 Binder.restoreCallingIdentity(identity);
4331 }
4332 }
4333
4334 /**
4335 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4336 * Requires MODIFY_PHONE_STATE permission.
4337 * @param subId The subscription to use to check the configuration.
4338 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4339 * false otherwise
4340 */
4341 @Override
4342 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4344 "setCrossSimCallingEnabled");
4345 final long identity = Binder.clearCallingIdentity();
4346 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004347 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004348 // This setting doesn't require an active ImsService connection, so do not verify. The
4349 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004350 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004351 } catch (ImsException e) {
4352 throw new ServiceSpecificException(e.getCode());
4353 } finally {
4354 Binder.restoreCallingIdentity(identity);
4355 }
4356 }
4357
4358 /**
shilu366312e2019-12-17 09:28:10 -08004359 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4360 * @param subId The subscription to use to check the configuration.
4361 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004362 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004363
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004365 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004366 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 final long identity = Binder.clearCallingIdentity();
4368 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004369 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004370 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004371 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004372 } catch (ImsException e) {
4373 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 } finally {
4375 Binder.restoreCallingIdentity(identity);
4376 }
4377 }
4378
4379 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004380 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004382 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004383 final long identity = Binder.clearCallingIdentity();
4384 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004385 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004386 // This setting doesn't require an active ImsService connection, so do not verify. The
4387 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004388 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004389 } catch (ImsException e) {
4390 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 } finally {
4392 Binder.restoreCallingIdentity(identity);
4393 }
4394 }
4395
4396 @Override
4397 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4399 "setVoWiFiNonPersistent");
4400 final long identity = Binder.clearCallingIdentity();
4401 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004402 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004403 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004404 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004405 } catch (ImsException e) {
4406 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
4410 }
4411
shilu366312e2019-12-17 09:28:10 -08004412 /**
4413 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4414 * @param subId The subscription to use to check the configuration.
4415 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004416 @Override
4417 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004418 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004419 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004420 final long identity = Binder.clearCallingIdentity();
4421 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004422 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004423 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004424 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004425 } catch (ImsException e) {
4426 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
4430 }
4431
4432 @Override
4433 public void setVoWiFiModeSetting(int subId, int mode) {
4434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4435 "setVoWiFiModeSetting");
4436 final long identity = Binder.clearCallingIdentity();
4437 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004438 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004439 // This setting doesn't require an active ImsService connection, so do not verify. The
4440 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004441 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004442 } catch (ImsException e) {
4443 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004444 } finally {
4445 Binder.restoreCallingIdentity(identity);
4446 }
4447 }
4448
4449 @Override
4450 public int getVoWiFiRoamingModeSetting(int subId) {
4451 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4452 final long identity = Binder.clearCallingIdentity();
4453 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004454 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004455 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004456 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004457 } catch (ImsException e) {
4458 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004459 } finally {
4460 Binder.restoreCallingIdentity(identity);
4461 }
4462 }
4463
4464 @Override
4465 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4467 "setVoWiFiRoamingModeSetting");
4468 final long identity = Binder.clearCallingIdentity();
4469 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004470 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004471 // This setting doesn't require an active ImsService connection, so do not verify. The
4472 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004473 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004474 } catch (ImsException e) {
4475 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004476 } finally {
4477 Binder.restoreCallingIdentity(identity);
4478 }
4479 }
4480
4481 @Override
4482 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4484 "setRttCapabilityEnabled");
4485 final long identity = Binder.clearCallingIdentity();
4486 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004487 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004488 // This setting doesn't require an active ImsService connection, so do not verify. The
4489 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004490 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004491 } catch (ImsException e) {
4492 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 } finally {
4494 Binder.restoreCallingIdentity(identity);
4495 }
4496 }
4497
shilu366312e2019-12-17 09:28:10 -08004498 /**
4499 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4500 * @param subId The subscription to use to check the configuration.
4501 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004502 @Override
4503 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004504 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004505 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004506 final long identity = Binder.clearCallingIdentity();
4507 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004508 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004509 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004510 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004511 } catch (ImsException e) {
4512 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
4516 }
4517
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004518 @Override
4519 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4520 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4521 final long identity = Binder.clearCallingIdentity();
4522 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004523 if (!isImsAvailableOnDevice()) {
4524 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4525 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004526 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004527 int slotId = getSlotIndexOrException(subId);
4528 verifyImsMmTelConfiguredOrThrow(slotId);
4529 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004530 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004531 } catch (ImsException e) {
4532 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004533 } finally {
4534 Binder.restoreCallingIdentity(identity);
4535 }
4536 }
4537
4538 @Override
4539 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4540 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4541 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004542 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4543 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4544 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004545 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004546 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004547 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004548 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004549 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4550 + "is inactive, ignoring unregister.");
4551 // If the subscription is no longer active, just return, since the callback will already
4552 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004553 } finally {
4554 Binder.restoreCallingIdentity(identity);
4555 }
4556 }
4557
allenwtsu99c623b2020-01-03 18:24:23 +08004558
4559 private void checkModifyPhoneStatePermission(int subId, String message) {
4560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4561 message);
4562 }
4563
4564 private boolean isImsProvisioningRequired(int subId, int capability,
4565 boolean isMmtelCapability) {
4566 Phone phone = getPhone(subId);
4567 if (phone == null) {
4568 loge("phone instance null for subid " + subId);
4569 return false;
4570 }
4571 if (isMmtelCapability) {
4572 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4573 return false;
4574 }
4575 } else {
4576 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4577 return false;
4578 }
4579 }
4580 return true;
4581 }
4582
4583 @Override
4584 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4585 boolean isProvisioned) {
4586 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4587
4588 final long identity = Binder.clearCallingIdentity();
4589 try {
4590 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4591 if (!isImsProvisioningRequired(subId, capability, false)) {
4592 return;
4593 }
4594
4595 // this capability requires provisioning, route to the correct API.
4596 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4597 switch (capability) {
4598 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4599 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4600 ims.setEabProvisioned(isProvisioned);
4601 break;
4602 default: {
4603 throw new IllegalArgumentException("Tried to set provisioning for "
4604 + "rcs capability '" + capability + "', which does not require "
4605 + "provisioning.");
4606 }
4607 }
4608 } finally {
4609 Binder.restoreCallingIdentity(identity);
4610 }
4611
4612 }
4613
4614
4615 @Override
4616 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4617 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4618 final long identity = Binder.clearCallingIdentity();
4619 try {
4620 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4621 if (!isImsProvisioningRequired(subId, capability, false)) {
4622 return true;
4623 }
4624
4625 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4626 switch (capability) {
4627 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4628 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4629 return ims.isEabProvisionedOnDevice();
4630
4631 default: {
4632 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4633 + "capability '" + capability + "', which does not require "
4634 + "provisioning.");
4635 }
4636 }
4637
4638 } finally {
4639 Binder.restoreCallingIdentity(identity);
4640 }
4641 }
4642
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004643 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004644 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4645 boolean isProvisioned) {
4646 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004647 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4648 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4649 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004650 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4651 }
allenwtsu99c623b2020-01-03 18:24:23 +08004652 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004653 final long identity = Binder.clearCallingIdentity();
4654 try {
4655 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004656 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004657 return;
4658 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004659 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4660 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4661 loge("setImsProvisioningStatusForCapability: called for technology that does "
4662 + "not support provisioning - " + tech);
4663 return;
4664 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004665
4666 // this capability requires provisioning, route to the correct API.
4667 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4668 switch (capability) {
4669 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4670 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4671 ims.setVolteProvisioned(isProvisioned);
4672 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4673 ims.setWfcProvisioned(isProvisioned);
4674 }
4675 break;
4676 }
4677 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4678 // There is currently no difference in VT provisioning type.
4679 ims.setVtProvisioned(isProvisioned);
4680 break;
4681 }
4682 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4683 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4684 // change the capability of the feature instead if needed.
4685 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4686 == isProvisioned) {
4687 // No change in provisioning.
4688 return;
4689 }
4690 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4691 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004692 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004693 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004694 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4695 + ", Exception" + e.getMessage());
4696 }
4697 break;
4698 }
4699 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004700 throw new IllegalArgumentException("Tried to set provisioning for "
4701 + "MmTel capability '" + capability + "', which does not require "
4702 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004703 }
4704 }
4705
4706 } finally {
4707 Binder.restoreCallingIdentity(identity);
4708 }
4709 }
4710
4711 @Override
4712 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4713 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004714 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4715 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4716 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004717 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4718 }
4719 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4720 final long identity = Binder.clearCallingIdentity();
4721 try {
4722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004723 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004724 return true;
4725 }
4726
Brad Ebinger0d79c572021-04-17 15:20:49 -07004727 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4728 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4729 loge("getImsProvisioningStatusForCapability: called for technology that does "
4730 + "not support provisioning - " + tech);
4731 return true;
4732 }
4733
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004734 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4735 switch (capability) {
4736 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4737 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4738 return ims.isVolteProvisionedOnDevice();
4739 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4740 return ims.isWfcProvisionedOnDevice();
4741 }
4742 // This should never happen, since we are checking tech above to make sure it
4743 // is either LTE or IWLAN.
4744 throw new IllegalArgumentException("Invalid radio technology for voice "
4745 + "capability.");
4746 }
4747 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4748 // There is currently no difference in VT provisioning type.
4749 return ims.isVtProvisionedOnDevice();
4750 }
4751 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4752 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4753 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4754 }
4755 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004756 throw new IllegalArgumentException(
4757 "Tried to get provisioning for MmTel capability '" + capability
4758 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004759 }
4760 }
4761
4762 } finally {
4763 Binder.restoreCallingIdentity(identity);
4764 }
4765 }
4766
4767 @Override
4768 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4769 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4770 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4771 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4772 }
4773 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4774 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4775 return (provisionedBits & capability) > 0;
4776 }
4777
4778 @Override
4779 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4780 boolean isProvisioned) {
4781 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4782 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4783 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4784 }
4785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4786 "setProvisioningStatusForCapability");
4787 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4788 // If the current provisioning status for capability already matches isProvisioned,
4789 // do nothing.
4790 if (((provisionedBits & capability) > 0) == isProvisioned) {
4791 return;
4792 }
4793 if (isProvisioned) {
4794 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4795 } else {
4796 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4797 }
4798 }
4799
4800 /**
4801 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4802 * technology. The bitfield should mirror the bitfield defined by
4803 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4804 */
4805 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4806 String key = getMmTelProvisioningKey(subId, tech);
4807 // Default is no capabilities are provisioned.
4808 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4809 }
4810
4811 /**
4812 * Sets the MmTel capability provisioning bitfield (defined by
4813 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4814 * technology specified.
4815 *
4816 * Note: This is a synchronous command and should not be called on UI thread.
4817 */
4818 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4819 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4820 String key = getMmTelProvisioningKey(subId, tech);
4821 editor.putInt(key, newField);
4822 editor.commit();
4823 }
4824
4825 private static String getMmTelProvisioningKey(int subId, int tech) {
4826 // resulting key is provision_ims_mmtel_{subId}_{tech}
4827 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4828 }
4829
4830 /**
4831 * Query CarrierConfig to see if the specified capability requires provisioning for the
4832 * carrier associated with the subscription id.
4833 */
4834 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4835 int capability) {
4836 CarrierConfigManager configManager = new CarrierConfigManager(context);
4837 PersistableBundle c = configManager.getConfigForSubId(subId);
4838 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004839 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004840 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4841 false);
4842 boolean requireVoiceVtProvisioning = c.getBoolean(
4843 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4844
4845 // First check to make sure that the capability requires provisioning.
4846 switch (capability) {
4847 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4848 // intentional fallthrough
4849 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4850 if (requireVoiceVtProvisioning) {
4851 // Voice and Video requires provisioning
4852 return true;
4853 }
4854 break;
4855 }
4856 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4857 if (requireUtProvisioning) {
4858 // UT requires provisioning
4859 return true;
4860 }
4861 break;
4862 }
4863 }
4864 return false;
4865 }
4866
allenwtsu99c623b2020-01-03 18:24:23 +08004867 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4868 int capability) {
4869 CarrierConfigManager configManager = new CarrierConfigManager(context);
4870 PersistableBundle c = configManager.getConfigForSubId(subId);
4871
4872 boolean requireRcsProvisioning = c.getBoolean(
4873 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4874
4875 // First check to make sure that the capability requires provisioning.
4876 switch (capability) {
4877 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4878 // intentional fallthrough
4879 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4880 if (requireRcsProvisioning) {
4881 // OPTION or PRESENCE requires provisioning
4882 return true;
4883 }
4884 break;
4885 }
4886 }
4887 return false;
4888 }
4889
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004890 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004891 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004892 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4893 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4894 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004895 enforceReadPrivilegedPermission("getImsProvisioningInt");
4896 final long identity = Binder.clearCallingIdentity();
4897 try {
4898 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004899 int slotId = getSlotIndex(subId);
4900 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4901 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4902 + subId + "' for key:" + key);
4903 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4904 }
calvinpanb5a34062021-02-08 19:59:36 +08004905 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004906 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004907 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4908 + subId + "' for key:" + key);
4909 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004910 } finally {
4911 Binder.restoreCallingIdentity(identity);
4912 }
4913 }
4914
4915 @Override
4916 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4918 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4919 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004920 enforceReadPrivilegedPermission("getImsProvisioningString");
4921 final long identity = Binder.clearCallingIdentity();
4922 try {
4923 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004924 int slotId = getSlotIndex(subId);
4925 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4926 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4927 + subId + "' for key:" + key);
4928 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4929 }
calvinpanb5a34062021-02-08 19:59:36 +08004930 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004931 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004932 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4933 + subId + "' for key:" + key);
4934 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004935 } finally {
4936 Binder.restoreCallingIdentity(identity);
4937 }
4938 }
4939
4940 @Override
4941 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004942 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4943 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4944 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4946 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004947 final long identity = Binder.clearCallingIdentity();
4948 try {
4949 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004950 int slotId = getSlotIndex(subId);
4951 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4952 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4953 + subId + "' for key:" + key);
4954 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4955 }
calvinpanb5a34062021-02-08 19:59:36 +08004956 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4957 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004958 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004959 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004960 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004961 } finally {
4962 Binder.restoreCallingIdentity(identity);
4963 }
4964 }
4965
4966 @Override
4967 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004968 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4969 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4970 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4972 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004973 final long identity = Binder.clearCallingIdentity();
4974 try {
4975 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004976 int slotId = getSlotIndex(subId);
4977 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4978 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4979 + subId + "' for key:" + key);
4980 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4981 }
calvinpanb5a34062021-02-08 19:59:36 +08004982 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4983 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004984 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004985 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004986 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004987 } finally {
4988 Binder.restoreCallingIdentity(identity);
4989 }
4990 }
4991
Brad Ebinger919631e2021-06-02 17:46:35 -07004992 /**
4993 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4994 * for the given slot ID or no ImsResolver instance has been created.
4995 * @param slotId The slot ID that the IMS service is created for.
4996 * @throws ImsException If there is no ImsService configured for this slot.
4997 */
4998 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4999 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5000 ImsFeature.FEATURE_MMTEL)) {
5001 throw new ImsException("This subscription does not support MMTEL over IMS",
5002 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5003 }
5004 }
5005
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005006 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005007 int slotId = SubscriptionManager.getSlotIndex(subId);
5008 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005009 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5010 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005011 }
5012 return slotId;
5013 }
5014
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005015 private int getSlotIndex(int subId) {
5016 int slotId = SubscriptionManager.getSlotIndex(subId);
5017 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5018 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5019 }
5020 return slotId;
5021 }
5022
Wink Saville36469e72014-06-11 15:17:00 -07005023 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005024 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005025 */
5026 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005027 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5028 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005029 try {
5030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5031 } catch (SecurityException se) {
5032 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5033 throw new SecurityException("Package " + callingPackage + " does not belong to "
5034 + Binder.getCallingUid());
5035 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005036 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005037 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005038 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005039 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005040 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005041 mApp, subId, callingPackage, callingFeatureId,
5042 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005043 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5044 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 final long identity = Binder.clearCallingIdentity();
5047 try {
5048 final Phone phone = getPhone(subId);
5049 if (phone != null) {
5050 return phone.getServiceState().getDataNetworkType();
5051 } else {
5052 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5053 }
5054 } finally {
5055 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005056 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005057 }
5058
5059 /**
5060 * Returns the data network type
5061 */
5062 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005063 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005064 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5065 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005066 }
5067
5068 /**
5069 * Returns the data network type for a subId
5070 */
5071 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005072 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5073 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005075 mApp, subId, callingPackage, callingFeatureId,
5076 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005077 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5078 }
5079
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 final long identity = Binder.clearCallingIdentity();
5081 try {
5082 final Phone phone = getPhone(subId);
5083 if (phone != null) {
5084 return phone.getServiceState().getDataNetworkType();
5085 } else {
5086 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5087 }
5088 } finally {
5089 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005091 }
5092
5093 /**
Wink Saville36469e72014-06-11 15:17:00 -07005094 * Returns the Voice network type for a subId
5095 */
5096 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005097 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5098 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005100 mApp, subId, callingPackage, callingFeatureId,
5101 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005102 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5103 }
5104
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105 final long identity = Binder.clearCallingIdentity();
5106 try {
5107 final Phone phone = getPhone(subId);
5108 if (phone != null) {
5109 return phone.getServiceState().getVoiceNetworkType();
5110 } else {
5111 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5112 }
5113 } finally {
5114 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005115 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005116 }
5117
5118 /**
5119 * @return true if a ICC card is present
5120 */
5121 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005122 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005123 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5124 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005125 }
5126
5127 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005128 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005129 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005130 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005131 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132 final long identity = Binder.clearCallingIdentity();
5133 try {
5134 final Phone phone = PhoneFactory.getPhone(slotIndex);
5135 if (phone != null) {
5136 return phone.getIccCard().hasIccCard();
5137 } else {
5138 return false;
5139 }
5140 } finally {
5141 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005143 }
5144
5145 /**
5146 * Return if the current radio is LTE on CDMA. This
5147 * is a tri-state return value as for a period of time
5148 * the mode may be unknown.
5149 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005150 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005151 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005152 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005153 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005154 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005155 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5156 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5157 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005158 }
5159
Sanket Padawe356d7632015-06-22 14:03:32 -07005160 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005161 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5162 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005163 try {
5164 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5165 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005166 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5167 }
5168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005169 final long identity = Binder.clearCallingIdentity();
5170 try {
5171 final Phone phone = getPhone(subId);
5172 if (phone == null) {
5173 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5174 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005175 return TelephonyProperties.lte_on_cdma_device()
5176 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177 }
5178 } finally {
5179 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005180 }
Wink Saville36469e72014-06-11 15:17:00 -07005181 }
5182
Wink Saville36469e72014-06-11 15:17:00 -07005183 /**
5184 * {@hide}
5185 * Returns Default subId, 0 in the case of single standby.
5186 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005187 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005188 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005189 }
5190
Shishir Agrawala9f32182016-04-12 12:00:16 -07005191 private int getSlotForDefaultSubscription() {
5192 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5193 }
5194
Wink Savilleb564aae2014-10-23 10:18:09 -07005195 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005196 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005197 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005198
Pengquan Menge92a50d2018-09-21 15:54:48 -07005199 private boolean isActiveSubscription(int subId) {
5200 return mSubscriptionController.isActiveSubId(subId);
5201 }
5202
Ihab Awadf2177b72013-11-25 13:33:23 -08005203 /**
5204 * @see android.telephony.TelephonyManager.WifiCallingChoices
5205 */
5206 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 final long identity = Binder.clearCallingIdentity();
5208 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005209 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5211 getWhenToMakeWifiCallsDefaultPreference());
5212 } finally {
5213 Binder.restoreCallingIdentity(identity);
5214 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005215 }
5216
5217 /**
5218 * @see android.telephony.TelephonyManager.WifiCallingChoices
5219 */
5220 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 final long identity = Binder.clearCallingIdentity();
5222 try {
5223 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005224 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5226 } finally {
5227 Binder.restoreCallingIdentity(identity);
5228 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005229 }
5230
Sailesh Nepald1e68152013-12-12 19:08:02 -08005231 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005232 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005233 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005234 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005235
Jordan Liu4c733742019-02-28 12:03:40 -08005236 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5237 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5238 if (phoneId == -1) {
5239 throw new IllegalArgumentException("Given slot index: " + slotIndex
5240 + " does not correspond to an active phone");
5241 }
5242 return PhoneFactory.getPhone(phoneId);
5243 }
5244
Shishir Agrawal566b7612013-10-28 14:41:00 -07005245 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005246 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5247 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5249 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005251 if (DBG) {
5252 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5253 }
5254 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5255 p2);
5256 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005257
Jordan Liu4c733742019-02-28 12:03:40 -08005258
5259 @Override
5260 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5261 int slotIndex, String callingPackage, String aid, int p2) {
5262 enforceModifyPermission();
5263 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5264 if (DBG) {
5265 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5266 }
5267 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5268 callingPackage, aid, p2);
5269 }
5270
5271 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5272 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 final long identity = Binder.clearCallingIdentity();
5274 try {
5275 if (TextUtils.equals(ISDR_AID, aid)) {
5276 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005277 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5278 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 if (bestComponent == null
5280 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5281 loge("The calling package is not allowed to access ISD-R.");
5282 throw new SecurityException(
5283 "The calling package is not allowed to access ISD-R.");
5284 }
Derek Tan740e1672017-06-27 14:56:27 -07005285 }
Derek Tan740e1672017-06-27 14:56:27 -07005286
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005288 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5289 null /* workSource */);
5290 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 return response;
5292 } finally {
5293 Binder.restoreCallingIdentity(identity);
5294 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005295 }
5296
5297 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005298 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5300 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005301 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5302 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5303 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005304
Jordan Liu4c733742019-02-28 12:03:40 -08005305 @Override
5306 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5307 enforceModifyPermission();
5308 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5309 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5310 channel);
5311 }
5312
5313 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005314 final long identity = Binder.clearCallingIdentity();
5315 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005316 if (channel < 0) {
5317 return false;
5318 }
Jordan Liu4c733742019-02-28 12:03:40 -08005319 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5320 null /* workSource */);
5321 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322 return success;
5323 } finally {
5324 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005325 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005326 }
5327
5328 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005329 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005330 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5332 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005333 if (DBG) {
5334 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5335 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5336 + p3 + " data=" + data);
5337 }
5338 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5339 command, p1, p2, p3, data);
5340 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005341
Jordan Liu4c733742019-02-28 12:03:40 -08005342 @Override
5343 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5344 int command, int p1, int p2, int p3, String data) {
5345 enforceModifyPermission();
5346 if (DBG) {
5347 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5348 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5349 + p3 + " data=" + data);
5350 }
5351 return iccTransmitApduLogicalChannelWithPermission(
5352 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5353 data);
5354 }
5355
5356 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5357 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 final long identity = Binder.clearCallingIdentity();
5359 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005360 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 return "";
5362 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005365 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5366 null /* workSource */);
5367 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 // Append the returned status code to the end of the response payload.
5370 String s = Integer.toHexString(
5371 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5372 if (response.payload != null) {
5373 s = IccUtils.bytesToHexString(response.payload) + s;
5374 }
5375 return s;
5376 } finally {
5377 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005378 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005379 }
Jake Hambye994d462014-02-03 13:10:13 -08005380
Evan Charltonc66da362014-05-16 14:06:40 -07005381 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005382 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5383 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5385 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005387 if (DBG) {
5388 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5389 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5390 }
5391 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5392 cla, command, p1, p2, p3, data);
5393 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005394
Jordan Liu4c733742019-02-28 12:03:40 -08005395 @Override
5396 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5397 int command, int p1, int p2, int p3, String data) {
5398 enforceModifyPermission();
5399 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5400 if (DBG) {
5401 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5402 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5403 + " data=" + data);
5404 }
5405
5406 return iccTransmitApduBasicChannelWithPermission(
5407 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5408 p2, p3, data);
5409 }
5410
5411 // open APDU basic channel assuming the caller has sufficient permissions
5412 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5413 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414 final long identity = Binder.clearCallingIdentity();
5415 try {
5416 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5417 && TextUtils.equals(ISDR_AID, data)) {
5418 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005419 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5420 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 if (bestComponent == null
5422 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5423 loge("The calling package is not allowed to select ISD-R.");
5424 throw new SecurityException(
5425 "The calling package is not allowed to select ISD-R.");
5426 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005427 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005430 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5431 null /* workSource */);
5432 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005434 // Append the returned status code to the end of the response payload.
5435 String s = Integer.toHexString(
5436 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5437 if (response.payload != null) {
5438 s = IccUtils.bytesToHexString(response.payload) + s;
5439 }
5440 return s;
5441 } finally {
5442 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005443 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005444 }
5445
5446 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005447 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005448 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5450 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452 final long identity = Binder.clearCallingIdentity();
5453 try {
5454 if (DBG) {
5455 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5456 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5457 }
5458
5459 IccIoResult response =
5460 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5461 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5462 subId);
5463
5464 if (DBG) {
5465 log("Exchange SIM_IO [R]" + response);
5466 }
5467
5468 byte[] result = null;
5469 int length = 2;
5470 if (response.payload != null) {
5471 length = 2 + response.payload.length;
5472 result = new byte[length];
5473 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5474 } else {
5475 result = new byte[length];
5476 }
5477
5478 result[length - 1] = (byte) response.sw2;
5479 result[length - 2] = (byte) response.sw1;
5480 return result;
5481 } finally {
5482 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005483 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005484 }
5485
Nathan Haroldb3014052017-01-25 15:57:32 -08005486 /**
5487 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5488 * on a particular subscription
5489 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005490 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5491 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005492 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005493 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005494 return null;
5495 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496
5497 final long identity = Binder.clearCallingIdentity();
5498 try {
5499 if (appType != TelephonyManager.APPTYPE_USIM
5500 && appType != TelephonyManager.APPTYPE_SIM) {
5501 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5502 return null;
5503 }
5504 Object response = sendRequest(
5505 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5506 if (response instanceof String[]) {
5507 return (String[]) response;
5508 }
yincheng zhao2737e882019-09-06 17:06:54 -07005509 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005511 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 } finally {
5513 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005514 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005515 }
5516
yincheng zhao2737e882019-09-06 17:06:54 -07005517 /**
5518 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5519 * subscription.
5520 *
5521 * @param subId the id of the subscription.
5522 * @param appType the uicc app type, must be USIM or SIM.
5523 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5524 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005525 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005526 * @return number of fplmns that is successfully written to the SIM.
5527 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005528 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5529 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5531 mApp, subId, "setForbiddenPlmns");
5532
yincheng zhao2737e882019-09-06 17:06:54 -07005533 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5534 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5535 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5536 }
5537 if (fplmns == null) {
5538 throw new IllegalArgumentException("Fplmn List provided is null");
5539 }
5540 for (String fplmn : fplmns) {
5541 if (!CellIdentity.isValidPlmn(fplmn)) {
5542 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5543 }
5544 }
5545 final long identity = Binder.clearCallingIdentity();
5546 try {
5547 Object response = sendRequest(
5548 CMD_SET_FORBIDDEN_PLMNS,
5549 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5550 subId);
5551 return (int) response;
5552 } finally {
5553 Binder.restoreCallingIdentity(identity);
5554 }
5555 }
5556
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005557 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005558 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5560 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562 final long identity = Binder.clearCallingIdentity();
5563 try {
5564 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5565 if (response.payload == null) {
5566 return "";
5567 }
Evan Charltonc66da362014-05-16 14:06:40 -07005568
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005569 // Append the returned status code to the end of the response payload.
5570 String s = Integer.toHexString(
5571 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5572 s = IccUtils.bytesToHexString(response.payload) + s;
5573 return s;
5574 } finally {
5575 Binder.restoreCallingIdentity(identity);
5576 }
Evan Charltonc66da362014-05-16 14:06:40 -07005577 }
5578
Jake Hambye994d462014-02-03 13:10:13 -08005579 /**
5580 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5581 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5582 *
5583 * @param itemID the ID of the item to read
5584 * @return the NV item as a String, or null on error.
5585 */
5586 @Override
5587 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005588 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5590 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591
5592 final long identity = Binder.clearCallingIdentity();
5593 try {
5594 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005595 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5597 return value;
5598 } finally {
5599 Binder.restoreCallingIdentity(identity);
5600 }
Jake Hambye994d462014-02-03 13:10:13 -08005601 }
5602
5603 /**
5604 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5605 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5606 *
5607 * @param itemID the ID of the item to read
5608 * @param itemValue the value to write, as a String
5609 * @return true on success; false on any failure
5610 */
5611 @Override
5612 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005613 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5615 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005616
5617 final long identity = Binder.clearCallingIdentity();
5618 try {
5619 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5620 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005621 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005622 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5623 return success;
5624 } finally {
5625 Binder.restoreCallingIdentity(identity);
5626 }
Jake Hambye994d462014-02-03 13:10:13 -08005627 }
5628
5629 /**
5630 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5631 * Used for device configuration by some CDMA operators.
5632 *
5633 * @param preferredRoamingList byte array containing the new PRL
5634 * @return true on success; false on any failure
5635 */
5636 @Override
5637 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5639 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640
5641 final long identity = Binder.clearCallingIdentity();
5642 try {
5643 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5644 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5645 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5646 return success;
5647 } finally {
5648 Binder.restoreCallingIdentity(identity);
5649 }
Jake Hambye994d462014-02-03 13:10:13 -08005650 }
5651
5652 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005653 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005654 * Used for device configuration by some CDMA operators.
5655 *
chen xu6dac5ab2018-10-26 17:39:23 -07005656 * @param slotIndex - device slot.
5657 *
Jake Hambye994d462014-02-03 13:10:13 -08005658 * @return true on success; false on any failure
5659 */
5660 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005661 public boolean resetModemConfig(int slotIndex) {
5662 Phone phone = PhoneFactory.getPhone(slotIndex);
5663 if (phone != null) {
5664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5665 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666
chen xu6dac5ab2018-10-26 17:39:23 -07005667 final long identity = Binder.clearCallingIdentity();
5668 try {
5669 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5670 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5671 return success;
5672 } finally {
5673 Binder.restoreCallingIdentity(identity);
5674 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675 }
chen xu6dac5ab2018-10-26 17:39:23 -07005676 return false;
5677 }
5678
5679 /**
5680 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5681 *
5682 * @param slotIndex - device slot.
5683 *
5684 * @return true on success; false on any failure
5685 */
5686 @Override
5687 public boolean rebootModem(int slotIndex) {
5688 Phone phone = PhoneFactory.getPhone(slotIndex);
5689 if (phone != null) {
5690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5691 mApp, phone.getSubId(), "rebootModem");
5692
5693 final long identity = Binder.clearCallingIdentity();
5694 try {
5695 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5696 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5697 return success;
5698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
5701 }
5702 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005703 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005704
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005705 public String[] getPcscfAddress(String apnType, String callingPackage,
5706 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005707 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005708 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5709 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005710 return new String[0];
5711 }
5712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713 final long identity = Binder.clearCallingIdentity();
5714 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005715 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 } finally {
5717 Binder.restoreCallingIdentity(identity);
5718 }
Wink Saville36469e72014-06-11 15:17:00 -07005719 }
5720
Brad Ebinger51f743a2017-01-23 13:50:20 -08005721 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005722 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5723 * {@link #disableIms(int)}.
5724 * @param slotIndex device slot.
5725 */
5726 public void resetIms(int slotIndex) {
5727 enforceModifyPermission();
5728
5729 final long identity = Binder.clearCallingIdentity();
5730 try {
5731 if (mImsResolver == null) {
5732 // may happen if the does not support IMS.
5733 return;
5734 }
5735 mImsResolver.disableIms(slotIndex);
5736 mImsResolver.enableIms(slotIndex);
5737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
5740 }
5741
5742 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005743 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5744 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005745 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005746 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005747 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748
5749 final long identity = Binder.clearCallingIdentity();
5750 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005751 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005752 // may happen if the device does not support IMS.
5753 return;
5754 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005755 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756 } finally {
5757 Binder.restoreCallingIdentity(identity);
5758 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005759 }
5760
5761 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005762 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5763 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005764 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005765 public void disableIms(int slotId) {
5766 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767
5768 final long identity = Binder.clearCallingIdentity();
5769 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005770 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005771 // may happen if the device does not support IMS.
5772 return;
5773 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005774 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005778 }
5779
5780 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005781 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5782 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005783 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005784 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005785 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005786 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787
5788 final long identity = Binder.clearCallingIdentity();
5789 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005790 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005791 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5792 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005793 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005794 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 } finally {
5796 Binder.restoreCallingIdentity(identity);
5797 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005798 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005799 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005800 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5801 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005802 @Override
5803 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005804 enforceModifyPermission();
5805
5806 final long identity = Binder.clearCallingIdentity();
5807 try {
5808 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005809 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005810 } finally {
5811 Binder.restoreCallingIdentity(identity);
5812 }
5813 }
5814
5815 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005816 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005817 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005818 */
5819 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5820 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005821
5822 final long identity = Binder.clearCallingIdentity();
5823 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005824 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005825 // may happen if the device does not support IMS.
5826 return null;
5827 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005828 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005829 } finally {
5830 Binder.restoreCallingIdentity(identity);
5831 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005832 }
5833
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005834 /**
5835 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005836 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005837 */
5838 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5839 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005840
5841 final long identity = Binder.clearCallingIdentity();
5842 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005843 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005844 // may happen if the device does not support IMS.
5845 return null;
5846 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005847 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848 } finally {
5849 Binder.restoreCallingIdentity(identity);
5850 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005851 }
5852
Brad Ebinger884c07b2018-02-15 16:17:40 -08005853 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005854 * Sets the ImsService Package Name that Telephony will bind to.
5855 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005856 * @param slotIndex the slot ID that the ImsService should bind for.
5857 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005858 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005859 * @param featureTypes An integer array of feature types associated with a packageName.
5860 * @param packageName The name of the package that the current configuration will be replaced
5861 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005862 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005863 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005864 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5865 int[] featureTypes, String packageName) {
5866 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5867 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5869 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005870 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005871
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872 final long identity = Binder.clearCallingIdentity();
5873 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005874 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005875 // may happen if the device does not support IMS.
5876 return false;
5877 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005878 Map<Integer, String> featureConfig = new HashMap<>();
5879 for (int featureType : featureTypes) {
5880 featureConfig.put(featureType, packageName);
5881 }
5882 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5883 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005884 } finally {
5885 Binder.restoreCallingIdentity(identity);
5886 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005887 }
5888
5889 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005890 * Clears any carrier ImsService overrides for the slot index specified that were previously
5891 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5892 *
5893 * This should only be used for testing.
5894 *
5895 * @param slotIndex the slot ID that the ImsService should bind for.
5896 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5897 */
5898 @Override
5899 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5900 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5901 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5902 "clearCarrierImsServiceOverride");
5903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5904 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5905 "clearCarrierImsServiceOverride");
5906
5907 final long identity = Binder.clearCallingIdentity();
5908 try {
5909 if (mImsResolver == null) {
5910 // may happen if the device does not support IMS.
5911 return false;
5912 }
5913 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5914 } finally {
5915 Binder.restoreCallingIdentity(identity);
5916 }
5917 }
5918
5919 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005920 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005921 *
5922 * @param slotId The slot that the ImsService is associated with.
5923 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5924 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005925 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005926 * @return the package name of the ImsService configuration.
5927 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005928 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5929 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005930 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005931 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005932 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005933 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5934 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936 final long identity = Binder.clearCallingIdentity();
5937 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005938 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005939 // may happen if the device does not support IMS.
5940 return "";
5941 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005942 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005943 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5944 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 } finally {
5946 Binder.restoreCallingIdentity(identity);
5947 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005948 }
5949
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005950 /**
5951 * Get the MmTelFeature state associated with the requested subscription id.
5952 * @param subId The subscription that the MmTelFeature is associated with.
5953 * @param callback A callback with an integer containing the
5954 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5955 */
5956 @Override
5957 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5958 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5959 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5960 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5961 "IMS not available on device.");
5962 }
5963 final long token = Binder.clearCallingIdentity();
5964 try {
5965 int slotId = getSlotIndex(subId);
5966 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5967 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5968 + subId + "'");
5969 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5970 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005971 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005972 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5973 try {
5974 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5975 } catch (RemoteException e) {
5976 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5977 + "Ignore");
5978 }
5979 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005980 } catch (ImsException e) {
5981 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005982 } finally {
5983 Binder.restoreCallingIdentity(token);
5984 }
5985 }
5986
Daniel Brightbb5840b2021-01-12 15:48:18 -08005987 /**
5988 * Sets the ims registration state on all valid {@link Phone}s.
5989 */
5990 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005991 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992
5993 final long identity = Binder.clearCallingIdentity();
5994 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005995 // NOTE: Before S, this method only set the default phone.
5996 for (final Phone phone : PhoneFactory.getPhones()) {
5997 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5998 phone.setImsRegistrationState(registered);
5999 }
6000 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 } finally {
6002 Binder.restoreCallingIdentity(identity);
6003 }
Wink Saville36469e72014-06-11 15:17:00 -07006004 }
6005
6006 /**
Stuart Scott54788802015-03-30 13:18:01 -07006007 * Set the network selection mode to automatic.
6008 *
6009 */
6010 @Override
6011 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6013 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014
6015 final long identity = Binder.clearCallingIdentity();
6016 try {
shilufc958392020-01-20 11:36:01 -08006017 if (!isActiveSubscription(subId)) {
6018 return;
6019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006021 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6022 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006023 } finally {
6024 Binder.restoreCallingIdentity(identity);
6025 }
Stuart Scott54788802015-03-30 13:18:01 -07006026 }
6027
Jack Yud10cdd42020-09-28 20:28:01 -07006028 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006029 * Ask the radio to connect to the input network and change selection mode to manual.
6030 *
6031 * @param subId the id of the subscription.
6032 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6033 * the operator to attach to.
6034 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6035 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6036 * normal network selection next time.
6037 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006038 */
6039 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006040 public boolean setNetworkSelectionModeManual(
6041 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6043 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006044
6045 if (!isActiveSubscription(subId)) {
6046 return false;
6047 }
6048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049 final long identity = Binder.clearCallingIdentity();
6050 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006051 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006053 if (DBG) {
6054 log("setNetworkSelectionModeManual: subId: " + subId
6055 + " operator: " + operatorInfo);
6056 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6058 } finally {
6059 Binder.restoreCallingIdentity(identity);
6060 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006061 }
shilu84f6e8b2019-12-19 13:58:01 -08006062 /**
6063 * Get the manual network selection
6064 *
6065 * @param subId the id of the subscription.
6066 *
6067 * @return the previously saved user selected PLMN
6068 */
6069 @Override
6070 public String getManualNetworkSelectionPlmn(int subId) {
6071 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006072 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006073 mApp, subId, "getManualNetworkSelectionPlmn");
6074
6075 final long identity = Binder.clearCallingIdentity();
6076 try {
6077 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006078 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006079 }
6080
6081 final Phone phone = getPhone(subId);
6082 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006083 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006084 }
6085 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6086 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6087 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6088 } finally {
6089 Binder.restoreCallingIdentity(identity);
6090 }
6091 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006092
6093 /**
6094 * Scans for available networks.
6095 */
6096 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006097 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6098 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6100 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006101 LocationAccessPolicy.LocationPermissionResult locationResult =
6102 LocationAccessPolicy.checkLocationPermission(mApp,
6103 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6104 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006105 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006106 .setCallingPid(Binder.getCallingPid())
6107 .setCallingUid(Binder.getCallingUid())
6108 .setMethod("getCellNetworkScanResults")
6109 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006110 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6111 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006112 .build());
6113 switch (locationResult) {
6114 case DENIED_HARD:
6115 throw new SecurityException("Not allowed to access scan results -- location");
6116 case DENIED_SOFT:
6117 return null;
6118 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006119
Pengquan Menga1bb6272018-09-06 09:59:22 -07006120 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121 try {
6122 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006123 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006124 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006125 } finally {
6126 Binder.restoreCallingIdentity(identity);
6127 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006128 }
6129
6130 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006131 * Get the call forwarding info, given the call forwarding reason.
6132 */
6133 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006134 public void getCallForwarding(int subId, int callForwardingReason,
6135 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006136 enforceReadPrivilegedPermission("getCallForwarding");
6137 long identity = Binder.clearCallingIdentity();
6138 try {
6139 if (DBG) {
6140 log("getCallForwarding: subId " + subId
6141 + " callForwardingReason" + callForwardingReason);
6142 }
Hall Liu27d24262020-09-18 19:04:59 -07006143
6144 Phone phone = getPhone(subId);
6145 if (phone == null) {
6146 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006147 callback.onError(
6148 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006149 } catch (RemoteException e) {
6150 // ignore
6151 }
6152 return;
6153 }
6154
6155 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6156 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6157 @Override
6158 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6159 try {
6160 callback.onCallForwardingInfoAvailable(info);
6161 } catch (RemoteException e) {
6162 // ignore
6163 }
6164 }
6165
6166 @Override
6167 public void onError(int error) {
6168 try {
6169 callback.onError(error);
6170 } catch (RemoteException e) {
6171 // ignore
6172 }
6173 }
6174 });
6175 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006176 } finally {
6177 Binder.restoreCallingIdentity(identity);
6178 }
6179 }
6180
6181 /**
6182 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6183 * reason, the number to forward, and the timeout before the forwarding is attempted.
6184 */
6185 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006186 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6187 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006188 enforceModifyPermission();
6189 long identity = Binder.clearCallingIdentity();
6190 try {
6191 if (DBG) {
6192 log("setCallForwarding: subId " + subId
6193 + " callForwardingInfo" + callForwardingInfo);
6194 }
Hall Liu27d24262020-09-18 19:04:59 -07006195
6196 Phone phone = getPhone(subId);
6197 if (phone == null) {
6198 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006199 callback.accept(
6200 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006201 } catch (RemoteException e) {
6202 // ignore
6203 }
6204 return;
6205 }
6206
6207 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6208 FunctionalUtils.ignoreRemoteException(callback::accept));
6209
6210 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006211 } finally {
6212 Binder.restoreCallingIdentity(identity);
6213 }
6214 }
6215
6216 /**
Hall Liu27d24262020-09-18 19:04:59 -07006217 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006218 */
6219 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006220 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006221 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006222 long identity = Binder.clearCallingIdentity();
6223 try {
Hall Liu27d24262020-09-18 19:04:59 -07006224 Phone phone = getPhone(subId);
6225 if (phone == null) {
6226 try {
6227 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6228 } catch (RemoteException e) {
6229 // ignore
6230 }
6231 return;
6232 }
SongFerngWang0e767992021-03-31 22:08:45 +08006233 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6234 PersistableBundle c = configManager.getConfigForSubId(subId);
6235 boolean requireUssd = c.getBoolean(
6236 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006237
Shuo Qian4a594052020-01-23 11:59:30 -08006238 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006239 if (requireUssd) {
6240 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6241 getSubscriptionCarrierId(subId));
6242 String newUssdCommand = "";
6243 try {
6244 newUssdCommand = carrierXmlParser.getFeature(
6245 CarrierXmlParser.FEATURE_CALL_WAITING)
6246 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6247 } catch (NullPointerException e) {
6248 loge("Failed to generate USSD number" + e);
6249 }
6250 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6251 mMainThreadHandler, callback, carrierXmlParser,
6252 CarrierXmlParser.SsEntry.SSAction.QUERY);
6253 final String ussdCommand = newUssdCommand;
6254 Executors.newSingleThreadExecutor().execute(() -> {
6255 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6256 });
6257 } else {
6258 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6259 callback::accept);
6260 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6261 }
Shuo Qian4a594052020-01-23 11:59:30 -08006262 } finally {
6263 Binder.restoreCallingIdentity(identity);
6264 }
6265 }
6266
6267 /**
Hall Liu27d24262020-09-18 19:04:59 -07006268 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006269 */
6270 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006271 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006272 enforceModifyPermission();
6273 long identity = Binder.clearCallingIdentity();
6274 try {
Hall Liu27d24262020-09-18 19:04:59 -07006275 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6276
6277 Phone phone = getPhone(subId);
6278 if (phone == null) {
6279 try {
6280 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6281 } catch (RemoteException e) {
6282 // ignore
6283 }
6284 return;
6285 }
6286
SongFerngWang0e767992021-03-31 22:08:45 +08006287 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6288 PersistableBundle c = configManager.getConfigForSubId(subId);
6289 boolean requireUssd = c.getBoolean(
6290 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006291
SongFerngWang0e767992021-03-31 22:08:45 +08006292 if (DBG) log("getCallWaitingStatus: subId " + subId);
6293 if (requireUssd) {
6294 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6295 getSubscriptionCarrierId(subId));
6296 CarrierXmlParser.SsEntry.SSAction ssAction =
6297 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6298 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6299 String newUssdCommand = "";
6300 try {
6301 newUssdCommand = carrierXmlParser.getFeature(
6302 CarrierXmlParser.FEATURE_CALL_WAITING)
6303 .makeCommand(ssAction, null);
6304 } catch (NullPointerException e) {
6305 loge("Failed to generate USSD number" + e);
6306 }
6307 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6308 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6309 final String ussdCommand = newUssdCommand;
6310 Executors.newSingleThreadExecutor().execute(() -> {
6311 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6312 });
6313 } else {
6314 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6315 FunctionalUtils.ignoreRemoteException(callback::accept));
6316
6317 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6318 }
Shuo Qian4a594052020-01-23 11:59:30 -08006319 } finally {
6320 Binder.restoreCallingIdentity(identity);
6321 }
6322 }
6323
6324 /**
yinxub1bed742017-04-17 11:45:04 -07006325 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006326 *
yinxub1bed742017-04-17 11:45:04 -07006327 * @param subId id of the subscription
6328 * @param request contains the radio access networks with bands/channels to scan
6329 * @param messenger callback messenger for scan results or errors
6330 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006331 * @return the id of the requested scan which can be used to stop the scan.
6332 */
6333 @Override
6334 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006335 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6337 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006338 LocationAccessPolicy.LocationPermissionResult locationResult =
6339 LocationAccessPolicy.checkLocationPermission(mApp,
6340 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6341 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006342 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006343 .setCallingPid(Binder.getCallingPid())
6344 .setCallingUid(Binder.getCallingUid())
6345 .setMethod("requestNetworkScan")
6346 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006347 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6348 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006349 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006350 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006351 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6352 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006353 if (e != null) {
6354 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6355 throw e;
6356 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006357 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006358 return TelephonyScanManager.INVALID_SCAN_ID;
6359 }
6360 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006361 }
Hall Liu912dfd32019-04-25 14:02:26 -07006362 int callingUid = Binder.getCallingUid();
6363 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006364 final long identity = Binder.clearCallingIdentity();
6365 try {
6366 return mNetworkScanRequestTracker.startNetworkScan(
6367 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006368 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006369 } finally {
6370 Binder.restoreCallingIdentity(identity);
6371 }
yinxu504e1392017-04-12 16:03:22 -07006372 }
6373
Hall Liub2ac8ef2019-02-28 15:56:23 -08006374 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006375 NetworkScanRequest request, int subId, String callingPackage) {
6376 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006377 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6378 boolean hasNetworkScanPermission =
6379 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6380 == PERMISSION_GRANTED;
6381
6382 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6383 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6384 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006385 }
6386
6387 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6388 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006389 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6390 return new SecurityException("Specific channels must not be"
6391 + " scanned without location access.");
6392 }
6393 }
6394 }
6395
Hall Liub2ac8ef2019-02-28 15:56:23 -08006396 return null;
6397 }
6398
yinxu504e1392017-04-12 16:03:22 -07006399 /**
6400 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006401 *
6402 * @param subId id of the subscription
6403 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006404 */
6405 @Override
6406 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6408 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409
Hall Liu912dfd32019-04-25 14:02:26 -07006410 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 final long identity = Binder.clearCallingIdentity();
6412 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006413 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 } finally {
6415 Binder.restoreCallingIdentity(identity);
6416 }
yinxu504e1392017-04-12 16:03:22 -07006417 }
6418
6419 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006420 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006421 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006422 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006423 */
6424 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006425 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006426 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006427 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006428 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429
6430 final long identity = Binder.clearCallingIdentity();
6431 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006432 if (DBG) log("getAllowedNetworkTypesBitmask");
6433 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6434 int networkTypesBitmask = (result != null ? result[0] : -1);
6435 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6436 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006437 } finally {
6438 Binder.restoreCallingIdentity(identity);
6439 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006440 }
6441
6442 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006443 * Get the allowed network types for certain reason.
6444 *
6445 * @param subId the id of the subscription.
6446 * @param reason the reason the allowed network type change is taking place
6447 * @return the allowed network types.
6448 */
6449 @Override
6450 public long getAllowedNetworkTypesForReason(int subId,
6451 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006452 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006453 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006454 final long identity = Binder.clearCallingIdentity();
6455 try {
6456 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6457 } finally {
6458 Binder.restoreCallingIdentity(identity);
6459 }
6460 }
6461
6462 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006463 * Enable/Disable E-UTRA-NR Dual Connectivity
6464 * @param subId subscription id of the sim card
6465 * @param nrDualConnectivityState expected NR dual connectivity state
6466 * This can be passed following states
6467 * <ol>
6468 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6469 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6470 * <li>Disable NR dual connectivity and force secondary cell to be released
6471 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6472 * </ol>
6473 * @return operation result.
6474 */
6475 @Override
6476 public int setNrDualConnectivityState(int subId,
6477 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6479 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006480 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006481 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6482 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6483 }
6484
Sooraj Sasindran37444802020-08-11 10:40:43 -07006485 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6486 final long identity = Binder.clearCallingIdentity();
6487 try {
6488 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6489 nrDualConnectivityState, subId,
6490 workSource);
6491 if (DBG) log("enableNRDualConnectivity result: " + result);
6492 return result;
6493 } finally {
6494 Binder.restoreCallingIdentity(identity);
6495 }
6496 }
6497
6498 /**
6499 * Is E-UTRA-NR Dual Connectivity enabled
6500 * @return true if dual connectivity is enabled else false
6501 */
6502 @Override
6503 public boolean isNrDualConnectivityEnabled(int subId) {
6504 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006505 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006506 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006507 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006508 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6509 return false;
6510 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006511 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6512 final long identity = Binder.clearCallingIdentity();
6513 try {
6514 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6515 null, subId, workSource);
6516 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6517 return isEnabled;
6518 } finally {
6519 Binder.restoreCallingIdentity(identity);
6520 }
6521 }
6522
6523 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006524 * Set the allowed network types of the device and
6525 * provide the reason triggering the allowed network change.
6526 *
6527 * @param subId the id of the subscription.
6528 * @param reason the reason the allowed network type change is taking place
6529 * @param allowedNetworkTypes the allowed network types.
6530 * @return true on success; false on any failure.
6531 */
6532 @Override
6533 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006534 @TelephonyManager.AllowedNetworkTypesReason int reason,
6535 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6537 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006538 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006539 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6540 return false;
6541 }
6542 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6543 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006544 return false;
6545 }
6546
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006547 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6548 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6549
6550
6551 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6552 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6553 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006554 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006555
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006556 final long identity = Binder.clearCallingIdentity();
6557 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006558 Boolean success = (Boolean) sendRequest(
6559 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6560 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6561
6562 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6563 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006564 } finally {
6565 Binder.restoreCallingIdentity(identity);
6566 }
6567 }
6568
6569 /**
Miaoa84611c2019-03-15 09:21:10 +08006570 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006571 *
Miaoa84611c2019-03-15 09:21:10 +08006572 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006573 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006574 * @hide
6575 */
6576 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006577 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006578 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006579 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006580 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581 try {
Miaoa84611c2019-03-15 09:21:10 +08006582 if (phone != null) {
6583 return phone.hasMatchedTetherApnSetting();
6584 } else {
6585 return false;
6586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006587 } finally {
6588 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006589 }
Junda Liu475951f2014-11-07 16:45:03 -08006590 }
6591
6592 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006593 * Enable or disable always reporting signal strength changes from radio.
6594 *
6595 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6596 */
6597 @Override
6598 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6599 enforceModifyPermission();
6600 enforceSystemCaller();
6601
6602 final long identity = Binder.clearCallingIdentity();
6603 final Phone phone = getPhone(subId);
6604 try {
6605 if (phone != null) {
6606 if (DBG) {
6607 log("setAlwaysReportSignalStrength: subId=" + subId
6608 + " isEnable=" + isEnable);
6609 }
6610 phone.setAlwaysReportSignalStrength(isEnable);
6611 } else {
6612 loge("setAlwaysReportSignalStrength: no phone found for subId="
6613 + subId);
6614 }
6615 } finally {
6616 Binder.restoreCallingIdentity(identity);
6617 }
6618 }
6619
6620 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006621 * Get the user enabled state of Mobile Data.
6622 *
6623 * TODO: remove and use isUserDataEnabled.
6624 * This can't be removed now because some vendor codes
6625 * calls through ITelephony directly while they should
6626 * use TelephonyManager.
6627 *
6628 * @return true on enabled
6629 */
6630 @Override
6631 public boolean getDataEnabled(int subId) {
6632 return isUserDataEnabled(subId);
6633 }
6634
6635 /**
6636 * Get whether mobile data is enabled per user setting.
6637 *
6638 * There are other factors deciding whether mobile data is actually enabled, but they are
6639 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006640 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006641 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006642 *
6643 * @return {@code true} if data is enabled else {@code false}
6644 */
6645 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006646 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006647 try {
6648 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6649 null);
6650 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6652 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006653 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654
6655 final long identity = Binder.clearCallingIdentity();
6656 try {
6657 int phoneId = mSubscriptionController.getPhoneId(subId);
6658 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6659 Phone phone = PhoneFactory.getPhone(phoneId);
6660 if (phone != null) {
6661 boolean retVal = phone.isUserDataEnabled();
6662 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6663 return retVal;
6664 } else {
6665 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6666 return false;
6667 }
6668 } finally {
6669 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006670 }
6671 }
6672
6673 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006674 * Checks if the device is capable of mobile data by considering whether whether the
6675 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6676 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006677 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006678 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006679 */
6680 @Override
6681 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006682 try {
6683 try {
6684 mApp.enforceCallingOrSelfPermission(
6685 android.Manifest.permission.ACCESS_NETWORK_STATE,
6686 null);
6687 } catch (Exception e) {
6688 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6689 "isDataEnabled");
6690 }
6691 } catch (Exception e) {
6692 enforceReadPrivilegedPermission("isDataEnabled");
6693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694
6695 final long identity = Binder.clearCallingIdentity();
6696 try {
6697 int phoneId = mSubscriptionController.getPhoneId(subId);
6698 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6699 Phone phone = PhoneFactory.getPhone(phoneId);
6700 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006701 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006702 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6703 return retVal;
6704 } else {
6705 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6706 return false;
6707 }
6708 } finally {
6709 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006710 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006711 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006712
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006713 /**
6714 * Check if data is enabled for a specific reason
6715 * @param subId Subscription index
6716 * @param reason the reason the data enable change is taking place
6717 * @return {@code true} if the overall data is enabled; {@code false} if not.
6718 */
6719 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006720 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006721 @TelephonyManager.DataEnabledReason int reason) {
6722 try {
6723 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6724 null);
6725 } catch (Exception e) {
6726 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006727 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006728 }
6729
6730
6731 final long identity = Binder.clearCallingIdentity();
6732 try {
6733 int phoneId = mSubscriptionController.getPhoneId(subId);
6734 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006735 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006736 + " reason=" + reason);
6737 }
6738 Phone phone = PhoneFactory.getPhone(phoneId);
6739 if (phone != null) {
6740 boolean retVal;
6741 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6742 retVal = phone.isUserDataEnabled();
6743 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006744 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006745 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006746 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006747 return retVal;
6748 } else {
6749 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006750 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006751 + subId + " retVal=false");
6752 }
6753 return false;
6754 }
6755 } finally {
6756 Binder.restoreCallingIdentity(identity);
6757 }
6758 }
6759
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006760 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006761 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006762 if (uid == Process.PHONE_UID) {
6763 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6764 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006765 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6766 }
6767
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006768 //load access rules from carrier configs, and check those as well: b/139133814
6769 SubscriptionController subController = SubscriptionController.getInstance();
6770 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6771 || subController == null) return privilegeFromSim;
6772
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006773 PackageManager pkgMgr = phone.getContext().getPackageManager();
6774 String[] packages = pkgMgr.getPackagesForUid(uid);
6775
6776 final long identity = Binder.clearCallingIdentity();
6777 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006778 int subId = phone.getSubId();
6779 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6780 // A test override is in place for the privileges for this subId, so don't try to
6781 // read the subscription privileges.
6782 return privilegeFromSim;
6783 }
6784 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006785 SubscriptionManager subManager = (SubscriptionManager)
6786 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6787 for (String pkg : packages) {
6788 if (subManager.canManageSubscription(subInfo, pkg)) {
6789 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6790 }
6791 }
6792 return privilegeFromSim;
6793 } finally {
6794 Binder.restoreCallingIdentity(identity);
6795 }
6796 }
6797
6798 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6799 String pkgName) {
6800 //load access rules from carrier configs, and check those as well: b/139133814
6801 SubscriptionController subController = SubscriptionController.getInstance();
6802 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6803 || subController == null) return privilegeFromSim;
6804
6805 final long identity = Binder.clearCallingIdentity();
6806 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006807 int subId = phone.getSubId();
6808 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6809 // A test override is in place for the privileges for this subId, so don't try to
6810 // read the subscription privileges.
6811 return privilegeFromSim;
6812 }
6813 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006814 SubscriptionManager subManager = (SubscriptionManager)
6815 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6816 return subManager.canManageSubscription(subInfo, pkgName)
6817 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6818 } finally {
6819 Binder.restoreCallingIdentity(identity);
6820 }
6821 }
6822
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006823 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006824 public int getCarrierPrivilegeStatus(int subId) {
6825 final Phone phone = getPhone(subId);
6826 if (phone == null) {
6827 loge("getCarrierPrivilegeStatus: Invalid subId");
6828 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6829 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006830 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6831 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006832 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006833 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6834 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006835
6836 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006837 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006838 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006839 }
Junda Liu29340342014-07-10 15:23:27 -07006840
6841 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006842 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006843 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006844 final Phone phone = getPhone(subId);
6845 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006846 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006847 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6848 }
6849 UiccProfile profile =
6850 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6851 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006852 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006853 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6854 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006855 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006856 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006857 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006858 }
6859
6860 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006861 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006862 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006863 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006864 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006865 }
6866
6867 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006868 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6869 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006870 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006871 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6872 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006873 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006874 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006875 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006876 }
6877
6878 @Override
6879 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006880 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006881 if (TextUtils.isEmpty(pkgName))
6882 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006883 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6884 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006885 UiccPort port = UiccController.getInstance().getUiccPort(i);
6886 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006887 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006888 continue;
6889 }
6890
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006891 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006892 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006893 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006894 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6895 break;
6896 }
6897 }
6898
6899 return result;
Junda Liu29340342014-07-10 15:23:27 -07006900 }
Derek Tan89e89d42014-07-08 17:00:10 -07006901
6902 @Override
Junda Liue64de782015-04-16 17:19:16 -07006903 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006904 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006905 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6906 loge("phoneId " + phoneId + " is not valid.");
6907 return null;
6908 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006909 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6910 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006911 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006912 return null ;
6913 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006914 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006915 }
6916
Amith Yamasani6e118872016-02-19 12:53:51 -08006917 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006918 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006919 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006920 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006921 List<String> privilegedPackages = new ArrayList<>();
6922 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006923 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006924 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006925 if (port != null) {
6926 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006927 if (packages == null) {
6928 // Only check packages in user 0 for now
6929 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006930 PackageManager.MATCH_DISABLED_COMPONENTS
6931 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006932 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006933 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006934 }
6935 for (int p = packages.size() - 1; p >= 0; p--) {
6936 PackageInfo pkgInfo = packages.get(p);
6937 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00006938 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6939 port.getCarrierPrivilegeStatus(pkgInfo),
6940 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006941 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006942 privilegedPackages.add(pkgInfo.packageName);
6943 }
6944 }
6945 }
6946 }
6947 return privilegedPackages;
6948 }
6949
chen xuf7e9fe82019-05-09 19:31:02 -07006950 @Override
6951 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006952 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6953
6954 final long identity = Binder.clearCallingIdentity();
6955
chen xuf7e9fe82019-05-09 19:31:02 -07006956 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006957 try {
6958 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6959 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6960 }
6961 } finally {
6962 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006963 }
6964 return privilegedPackages;
6965 }
6966
Wink Savilleb564aae2014-10-23 10:18:09 -07006967 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006968 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006969 UiccPort port = phone == null ? null : phone.getUiccPort();
6970 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006971 return null;
6972 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006973 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006974 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006975 return null;
6976 }
6977 return iccId;
6978 }
6979
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006980 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006981 public void setCallComposerStatus(int subId, int status) {
6982 enforceModifyPermission();
6983
6984 final long identity = Binder.clearCallingIdentity();
6985 try {
6986 Phone phone = getPhone(subId);
6987 if (phone != null) {
6988 Phone defaultPhone = phone.getImsPhone();
6989 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6990 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6991 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006992 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6993 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006994 }
6995 }
Shuo Qian284ae752020-12-22 19:10:14 -08006996 } catch (ImsException e) {
6997 throw new ServiceSpecificException(e.getCode());
6998 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006999 Binder.restoreCallingIdentity(identity);
7000 }
7001 }
7002
7003 @Override
7004 public int getCallComposerStatus(int subId) {
7005 enforceReadPrivilegedPermission("getCallComposerStatus");
7006
7007 final long identity = Binder.clearCallingIdentity();
7008 try {
7009 Phone phone = getPhone(subId);
7010 if (phone != null) {
7011 Phone defaultPhone = phone.getImsPhone();
7012 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7013 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7014 return imsPhone.getCallComposerStatus();
7015 }
7016 }
7017 } finally {
7018 Binder.restoreCallingIdentity(identity);
7019 }
7020 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7021 }
7022
7023 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007024 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7025 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007026 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007027 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007028
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 final long identity = Binder.clearCallingIdentity();
7030 try {
7031 final String iccId = getIccId(subId);
7032 final Phone phone = getPhone(subId);
7033 if (phone == null) {
7034 return false;
7035 }
7036 final String subscriberId = phone.getSubscriberId();
7037
7038 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007039 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 + subscriberId + " to " + number);
7041 }
7042
7043 if (TextUtils.isEmpty(iccId)) {
7044 return false;
7045 }
7046
7047 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7048
7049 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7050 if (alphaTag == null) {
7051 editor.remove(alphaTagPrefKey);
7052 } else {
7053 editor.putString(alphaTagPrefKey, alphaTag);
7054 }
7055
7056 // Record both the line number and IMSI for this ICCID, since we need to
7057 // track all merged IMSIs based on line number
7058 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7059 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7060 if (number == null) {
7061 editor.remove(numberPrefKey);
7062 editor.remove(subscriberPrefKey);
7063 } else {
7064 editor.putString(numberPrefKey, number);
7065 editor.putString(subscriberPrefKey, subscriberId);
7066 }
7067
7068 editor.commit();
7069 return true;
7070 } finally {
7071 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007072 }
Derek Tan7226c842014-07-02 17:42:23 -07007073 }
7074
7075 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007076 public String getLine1NumberForDisplay(int subId, String callingPackage,
7077 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007078 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007079 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007080 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007081 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007082 return null;
7083 }
Derek Tan97ebb422014-09-05 16:55:38 -07007084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007085 final long identity = Binder.clearCallingIdentity();
7086 try {
7087 String iccId = getIccId(subId);
7088 if (iccId != null) {
7089 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7090 if (DBG_MERGE) {
7091 log("getLine1NumberForDisplay returning "
7092 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7093 }
7094 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007095 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007096 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7097 return null;
7098 } finally {
7099 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007100 }
Derek Tan7226c842014-07-02 17:42:23 -07007101 }
7102
7103 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007104 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7105 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007106 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007107 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007108 return null;
7109 }
Derek Tan97ebb422014-09-05 16:55:38 -07007110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111 final long identity = Binder.clearCallingIdentity();
7112 try {
7113 String iccId = getIccId(subId);
7114 if (iccId != null) {
7115 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7116 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7117 }
7118 return null;
7119 } finally {
7120 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007121 }
Derek Tan7226c842014-07-02 17:42:23 -07007122 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007123
7124 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007125 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7126 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007127 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7128 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007129 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007130 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007131 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007132 return null;
7133 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007134
Jordan Liub49b04b2019-05-06 14:45:15 -07007135 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7136 // the process, where TelephonyManager was instantiated.
7137 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007138 final long identity = Binder.clearCallingIdentity();
7139 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007140 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141 final TelephonyManager tele = TelephonyManager.from(context);
7142 final SubscriptionManager sub = SubscriptionManager.from(context);
7143
7144 // Figure out what subscribers are currently active
7145 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007146
Jordan Liub49b04b2019-05-06 14:45:15 -07007147 // Only consider subs which match the current subId
7148 // This logic can be simplified. See b/131189269 for progress.
7149 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007150 activeSubscriberIds.add(tele.getSubscriberId(subId));
7151 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007152
7153 // First pass, find a number override for an active subscriber
7154 String mergeNumber = null;
7155 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7156 for (String key : prefs.keySet()) {
7157 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7158 final String subscriberId = (String) prefs.get(key);
7159 if (activeSubscriberIds.contains(subscriberId)) {
7160 final String iccId = key.substring(
7161 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7162 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7163 mergeNumber = (String) prefs.get(numberKey);
7164 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007165 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007166 + " for active subscriber " + subscriberId);
7167 }
7168 if (!TextUtils.isEmpty(mergeNumber)) {
7169 break;
7170 }
7171 }
7172 }
7173 }
7174
7175 // Shortcut when no active merged subscribers
7176 if (TextUtils.isEmpty(mergeNumber)) {
7177 return null;
7178 }
7179
7180 // Second pass, find all subscribers under that line override
7181 final ArraySet<String> result = new ArraySet<>();
7182 for (String key : prefs.keySet()) {
7183 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7184 final String number = (String) prefs.get(key);
7185 if (mergeNumber.equals(number)) {
7186 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7187 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7188 final String subscriberId = (String) prefs.get(subscriberKey);
7189 if (!TextUtils.isEmpty(subscriberId)) {
7190 result.add(subscriberId);
7191 }
7192 }
7193 }
7194 }
7195
7196 final String[] resultArray = result.toArray(new String[result.size()]);
7197 Arrays.sort(resultArray);
7198 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007199 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007200 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7201 }
7202 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007203 } finally {
7204 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007205 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007206 }
7207
7208 @Override
zoey chen38003472019-12-13 17:16:31 +08007209 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7210 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007211
7212 final long identity = Binder.clearCallingIdentity();
7213 try {
7214 final TelephonyManager telephonyManager = mApp.getSystemService(
7215 TelephonyManager.class);
7216 String subscriberId = telephonyManager.getSubscriberId(subId);
7217 if (subscriberId == null) {
7218 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007219 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007220 + subId);
7221 }
7222 return null;
7223 }
7224
7225 final SubscriptionInfo info = SubscriptionController.getInstance()
7226 .getSubscriptionInfo(subId);
7227 final ParcelUuid groupUuid = info.getGroupUuid();
7228 // If it doesn't belong to any group, return just subscriberId of itself.
7229 if (groupUuid == null) {
7230 return new String[]{subscriberId};
7231 }
7232
7233 // Get all subscriberIds from the group.
7234 final List<String> mergedSubscriberIds = new ArrayList<>();
7235 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007236 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007237 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007238 for (SubscriptionInfo subInfo : groupInfos) {
7239 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7240 if (subscriberId != null) {
7241 mergedSubscriberIds.add(subscriberId);
7242 }
7243 }
7244
7245 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7246 } finally {
7247 Binder.restoreCallingIdentity(identity);
7248
7249 }
7250 }
7251
7252 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007253 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007254 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007255 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007256
7257 final long identity = Binder.clearCallingIdentity();
7258 try {
7259 final Phone phone = getPhone(subId);
7260 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7261 } finally {
7262 Binder.restoreCallingIdentity(identity);
7263 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007264 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007265
7266 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007267 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007268 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7269 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007270 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7271 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272
7273 final long identity = Binder.clearCallingIdentity();
7274 try {
7275 final Phone phone = getPhone(subId);
7276 if (phone == null) {
7277 return false;
7278 }
7279 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7280 cdmaNonRoamingList);
7281 } finally {
7282 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007283 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007284 }
7285
7286 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007287 @Deprecated
7288 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7289 enforceModifyPermission();
7290
7291 int returnValue = 0;
7292 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007293 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007294 if(result.exception == null) {
7295 if (result.result != null) {
7296 byte[] responseData = (byte[])(result.result);
7297 if(responseData.length > oemResp.length) {
7298 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7299 responseData.length + "bytes. Buffer Size is " +
7300 oemResp.length + "bytes.");
7301 }
7302 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7303 returnValue = responseData.length;
7304 }
7305 } else {
7306 CommandException ex = (CommandException) result.exception;
7307 returnValue = ex.getCommandError().ordinal();
7308 if(returnValue > 0) returnValue *= -1;
7309 }
7310 } catch (RuntimeException e) {
7311 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7312 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7313 if(returnValue > 0) returnValue *= -1;
7314 }
7315
7316 return returnValue;
7317 }
7318
7319 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007320 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007321 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007322 try {
7323 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007324 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007325 mApp, phone.getSubId(), "getRadioAccessFamily");
7326 } catch (SecurityException e) {
7327 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7328 throw e;
7329 }
chen xub97461a2018-10-26 14:17:57 -07007330 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007331 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007332 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007333 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007334 final long identity = Binder.clearCallingIdentity();
7335 try {
chen xub97461a2018-10-26 14:17:57 -07007336 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007337 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007338 mApp, phone.getSubId(), "getRadioAccessFamily");
7339 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007340 } finally {
7341 Binder.restoreCallingIdentity(identity);
7342 }
chen xub97461a2018-10-26 14:17:57 -07007343 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007344 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007345
7346 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007347 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007348 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007349 try {
7350 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7351 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007352 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007353 }
7354 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007355 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007356 }
7357 RoleManager rm = mApp.getSystemService(RoleManager.class);
7358 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7359 if (!dialerRoleHolders.contains(callingPackage)) {
7360 throw new SecurityException("App must be the dialer role holder to"
7361 + " upload a call composer pic");
7362 }
7363
7364 Executors.newSingleThreadExecutor().execute(() -> {
7365 ByteArrayOutputStream output = new ByteArrayOutputStream(
7366 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7367 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7368 boolean readUntilEnd = false;
7369 int totalBytesRead = 0;
7370 byte[] buffer = new byte[16 * 1024];
7371 while (true) {
7372 int numRead;
7373 try {
7374 numRead = input.read(buffer);
7375 } catch (IOException e) {
7376 try {
7377 fd.checkError();
7378 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7379 null);
7380 } catch (IOException e1) {
7381 // This means that the other side closed explicitly with an error. If this
7382 // happens, log and ignore.
7383 loge("Remote end of call composer picture pipe closed: " + e1);
7384 }
7385 break;
7386 }
7387 if (numRead == -1) {
7388 readUntilEnd = true;
7389 break;
7390 }
7391 totalBytesRead += numRead;
7392 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7393 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7394 try {
7395 input.close();
7396 } catch (IOException e) {
7397 // ignore
7398 }
7399 break;
7400 }
7401 output.write(buffer, 0, numRead);
7402 }
7403 // Generally, the remote end will close the file descriptors. The only case where we
7404 // close is above, where the picture size is too big.
7405
7406 try {
7407 fd.checkError();
7408 } catch (IOException e) {
7409 loge("Remote end for call composer closed with an error: " + e);
7410 return;
7411 }
7412
Hall Liuaa4211e2021-01-20 15:43:39 -08007413 if (!readUntilEnd) {
7414 loge("Did not finish reading entire image; aborting");
7415 return;
7416 }
Hall Liu82694d52020-12-11 18:22:04 -08007417
Hall Liuaa4211e2021-01-20 15:43:39 -08007418 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7419 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7420 new CallComposerPictureTransfer.Factory() {},
7421 imageData,
7422 (result) -> {
7423 if (result.first != null) {
7424 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7425 Bundle outputResult = new Bundle();
7426 outputResult.putParcelable(
7427 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7428 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7429 outputResult);
7430 } else {
7431 callback.send(result.second, null);
7432 }
7433 }
7434 );
Hall Liu82694d52020-12-11 18:22:04 -08007435 });
7436 }
7437
7438 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007439 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007440 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007441 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442
7443 final long identity = Binder.clearCallingIdentity();
7444 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007445 ImsManager.getInstance(defaultPhone.getContext(),
7446 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 } finally {
7448 Binder.restoreCallingIdentity(identity);
7449 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007450 }
7451
7452 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007453 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007454 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007455 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7456 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007457 return false;
7458 }
Svet Ganovb320e182015-04-16 12:30:10 -07007459
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 final long identity = Binder.clearCallingIdentity();
7461 try {
7462 // Check the user preference and the system-level IMS setting. Even if the user has
7463 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7464 // In the long run, we may instead need to check if there exists a connection service
7465 // which can support video calling.
7466 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007467 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 return imsManager.isVtEnabledByPlatform()
7469 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7470 && imsManager.isVtEnabledByUser();
7471 } finally {
7472 Binder.restoreCallingIdentity(identity);
7473 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007474 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007475
Andrew Leea1239f22015-03-02 17:44:07 -08007476 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007477 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7478 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007480 mApp, subId, callingPackage, callingFeatureId,
7481 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 return false;
7483 }
7484
7485 final long identity = Binder.clearCallingIdentity();
7486 try {
7487 CarrierConfigManager configManager =
7488 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007489 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7491 } finally {
7492 Binder.restoreCallingIdentity(identity);
7493 }
Andrew Leea1239f22015-03-02 17:44:07 -08007494 }
7495
7496 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007497 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007499 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 return false;
7501 }
7502
7503 final long identity = Binder.clearCallingIdentity();
7504 try {
7505 CarrierConfigManager configManager =
7506 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007507 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
Andrew Leea1239f22015-03-02 17:44:07 -08007512 }
7513
Andrew Lee9431b832015-03-09 18:46:45 -07007514 @Override
7515 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007516 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007517 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007518 }
7519
7520 @Override
7521 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 final long identity = Binder.clearCallingIdentity();
7523 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007524 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 } finally {
7526 Binder.restoreCallingIdentity(identity);
7527 }
Andrew Lee9431b832015-03-09 18:46:45 -07007528 }
7529
Hall Liuf6668912018-10-31 17:05:23 -07007530 /**
7531 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7532 * support for the feature and device firmware support.
7533 *
7534 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7535 */
7536 @Override
7537 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007539 final Phone phone = getPhone(subscriptionId);
7540 if (phone == null) {
7541 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7542 return false;
7543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007545 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007546 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7547 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007548 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007549 return isCarrierSupported && isDeviceSupported;
7550 } finally {
7551 Binder.restoreCallingIdentity(identity);
7552 }
Hall Liu98187582018-01-22 19:15:32 -08007553 }
7554
Hall Liuf6668912018-10-31 17:05:23 -07007555 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007556 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7557 * RTT setting, will return true if the device and carrier both support RTT.
7558 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007559 */
7560 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007561 final long identity = Binder.clearCallingIdentity();
7562 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007563 boolean isRttSupported = isRttSupported(subscriptionId);
7564 boolean isUserRttSettingOn = Settings.Secure.getInt(
7565 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7566 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7567 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7568 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007569 } finally {
7570 Binder.restoreCallingIdentity(identity);
7571 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007572 }
7573
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007574 @Deprecated
7575 @Override
7576 public String getDeviceId(String callingPackage) {
7577 return getDeviceIdWithFeature(callingPackage, null);
7578 }
7579
Sanket Padawe7310cc72015-01-14 09:53:20 -08007580 /**
7581 * Returns the unique device ID of phone, for example, the IMEI for
7582 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7583 *
7584 * <p>Requires Permission:
7585 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7586 */
7587 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007588 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007589 try {
7590 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7591 } catch (SecurityException se) {
7592 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7593 throw new SecurityException("Package " + callingPackage + " does not belong to "
7594 + Binder.getCallingUid());
7595 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007596 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007597 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007598 return null;
7599 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007600 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007601 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007602 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007603 return null;
7604 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007605
7606 final long identity = Binder.clearCallingIdentity();
7607 try {
7608 return phone.getDeviceId();
7609 } finally {
7610 Binder.restoreCallingIdentity(identity);
7611 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007612 }
7613
Ping Sunc67b7c22016-03-02 19:16:45 +08007614 /**
7615 * {@hide}
7616 * Returns the IMS Registration Status on a particular subid
7617 *
7618 * @param subId
7619 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007620 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007621 Phone phone = getPhone(subId);
7622 if (phone != null) {
7623 return phone.isImsRegistered();
7624 } else {
7625 return false;
7626 }
7627 }
7628
Santos Cordon7a1885b2015-02-03 11:15:19 -08007629 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007630 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007631 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007633 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007634 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7635 }
7636 final long identity = Binder.clearCallingIdentity();
7637 try {
7638 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7639 } finally {
7640 Binder.restoreCallingIdentity(identity);
7641 }
7642 }
7643
7644 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007645 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007646 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007647 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007648 mApp,
7649 subscriptionId,
7650 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007651 final long identity = Binder.clearCallingIdentity();
7652 try {
7653 Phone phone = getPhone(subscriptionId);
7654 if (phone == null) {
7655 return null;
7656 }
7657 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
7660 }
7661 }
7662
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007663 /**
7664 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007665 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007666 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007667 final long identity = Binder.clearCallingIdentity();
7668 try {
7669 Phone phone = getPhone(subId);
7670 if (phone != null) {
7671 return phone.isWifiCallingEnabled();
7672 } else {
7673 return false;
7674 }
7675 } finally {
7676 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007677 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007678 }
7679
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007680 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007681 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007682 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007683 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007684 final long identity = Binder.clearCallingIdentity();
7685 try {
7686 Phone phone = getPhone(subId);
7687 if (phone != null) {
7688 return phone.isVideoEnabled();
7689 } else {
7690 return false;
7691 }
7692 } finally {
7693 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007694 }
7695 }
7696
7697 /**
7698 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7699 * defined in {@link ImsRegistrationImplBase}.
7700 */
7701 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007702 final long identity = Binder.clearCallingIdentity();
7703 try {
7704 Phone phone = getPhone(subId);
7705 if (phone != null) {
7706 return phone.getImsRegistrationTech();
7707 } else {
7708 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7709 }
7710 } finally {
7711 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007712 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007713 }
7714
Stuart Scott8eef64f2015-04-08 15:13:54 -07007715 @Override
7716 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007717 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007718 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7719 return;
7720 }
Kai Shif70f46f2021-03-03 13:59:46 -08007721 Phone defaultPhone = getDefaultPhone();
7722 if (defaultPhone != null) {
7723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7724 mApp, getDefaultPhone().getSubId(), "factoryReset");
7725 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007726 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007727
Svet Ganovcc087f82015-05-12 20:35:54 -07007728 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007729 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7730 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007731 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007732 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007733 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007734 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007735 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007736 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007737 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007738 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007739 // There has been issues when Sms raw table somehow stores orphan
7740 // fragments. They lead to garbled message when new fragments come
7741 // in and combined with those stale ones. In case this happens again,
7742 // user can reset all network settings which will clean up this table.
7743 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007744 // Clean up IMS settings as well here.
7745 int slotId = getSlotIndex(subId);
7746 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7747 ImsManager.getInstance(mApp, slotId).factoryReset();
7748 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007749
Kai Shif70f46f2021-03-03 13:59:46 -08007750 if (defaultPhone == null) {
7751 return;
7752 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007753 // Erase modem config if erase modem on network setting is enabled.
7754 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7755 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7756 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007757 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007758 }
Kai Shif70f46f2021-03-03 13:59:46 -08007759
7760 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007761 } finally {
7762 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007763 }
7764 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007765
SongFerngWangfd89b102021-05-27 22:44:54 +08007766 @VisibleForTesting
7767 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7768 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7769 return;
7770 }
7771 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7772 RILConstants.PREFERRED_NETWORK_MODE);
7773 SubscriptionManager.setSubscriptionProperty(subId,
7774 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7775 "user=" + defaultNetworkType);
7776 phone.loadAllowedNetworksFromSubscriptionDatabase();
7777 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7778 defaultNetworkType, null);
7779 }
7780
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007781 private void cleanUpSmsRawTable(Context context) {
7782 ContentResolver resolver = context.getContentResolver();
7783 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7784 resolver.delete(uri, null, null);
7785 }
7786
Narayan Kamath1c496c22015-04-16 14:40:19 +01007787 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007788 public String getSimLocaleForSubscriber(int subId) {
7789 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7790 final Phone phone = getPhone(subId);
7791 if (phone == null) {
7792 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007793 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007794 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007795 final long identity = Binder.clearCallingIdentity();
7796 try {
chen xu5d3637b2019-01-21 23:31:38 -08007797 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007798 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007799 if (info == null) {
7800 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7801 return null;
7802 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803 // Try and fetch the locale from the carrier properties or from the SIM language
7804 // preferences (EF-PL and EF-LI)...
7805 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007806 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007807 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7808 if (localeFromDefaultSim != null) {
7809 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7810 if (DBG) log("Using locale from subId: " + subId + " locale: "
7811 + localeFromDefaultSim);
7812 return localeFromDefaultSim.toLanguageTag();
7813 } else {
7814 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007815 }
7816 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 // The SIM language preferences only store a language (e.g. fr = French), not an
7819 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7820 // the SIM and carrier preferences does not include a country we add the country
7821 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007822 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007823 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007824 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007825 return mccLocale.toLanguageTag();
7826 }
7827
7828 if (DBG) log("No locale found - returning null");
7829 return null;
7830 } finally {
7831 Binder.restoreCallingIdentity(identity);
7832 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007833 }
7834
7835 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007836 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007837 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007838 }
7839
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007840 /**
7841 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7842 */
7843 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007844 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007845 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007846 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007847
Chenjie Yu1ba97252018-01-11 18:16:20 -08007848 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007849 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007850
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007851 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007852 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7853 * representing the state of the modem.
7854 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007855 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7856 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007857 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007858 */
7859 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007860 public void requestModemActivityInfo(ResultReceiver result) {
7861 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007862 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007863
7864 final long identity = Binder.clearCallingIdentity();
7865 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007866 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007867 } finally {
7868 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007869 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007870 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007871
Siddharth Rayb8114062018-06-17 15:02:38 -07007872 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7873 // less than total activity duration.
7874 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7875 if (info == null) {
7876 return false;
7877 }
7878 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007879 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7880 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7881
Siddharth Rayb8114062018-06-17 15:02:38 -07007882 return (info.isValid()
7883 && (info.getSleepTimeMillis() <= activityDurationMs)
7884 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007885 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007886 && (totalTxTimeMs <= activityDurationMs));
7887 }
7888
Jack Yu85bd38a2015-11-09 11:34:32 -08007889 /**
7890 * {@hide}
7891 * Returns the service state information on specified subscription.
7892 */
7893 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007894 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7895 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007896 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007897 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007898 return null;
7899 }
7900
Hall Liuf19c44f2018-11-27 14:38:17 -08007901 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7902 LocationAccessPolicy.checkLocationPermission(mApp,
7903 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7904 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007905 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007906 .setCallingPid(Binder.getCallingPid())
7907 .setCallingUid(Binder.getCallingUid())
7908 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007909 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007910 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007911 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7912 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007913 .build());
7914
7915 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7916 LocationAccessPolicy.checkLocationPermission(mApp,
7917 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7918 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007919 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007920 .setCallingPid(Binder.getCallingPid())
7921 .setCallingUid(Binder.getCallingUid())
7922 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007923 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007924 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007925 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7926 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007927 .build());
7928 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7929 boolean hasFinePermission =
7930 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7931 boolean hasCoarsePermission =
7932 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7933
Jack Yu479f40e2020-10-27 21:29:25 -07007934 final Phone phone = getPhone(subId);
7935 if (phone == null) {
7936 return null;
7937 }
7938
Jordan Liu0f2bc442020-11-18 16:47:37 -08007939 final long identity = Binder.clearCallingIdentity();
7940
Jack Yu479f40e2020-10-27 21:29:25 -07007941 boolean isCallingPackageDataService = phone.getDataServicePackages()
7942 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007943 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007944 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7945 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7946 Rlog.d(LOG_TAG,
7947 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7948 return null;
7949 }
7950
Hall Liuf19c44f2018-11-27 14:38:17 -08007951 ServiceState ss = phone.getServiceState();
7952
7953 // Scrub out the location info in ServiceState depending on what level of access
7954 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007955 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007956 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7957 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958 } finally {
7959 Binder.restoreCallingIdentity(identity);
7960 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007961 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007962
7963 /**
7964 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7965 *
7966 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7967 * voicemail ringtone.
7968 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7969 * PhoneAccount.
7970 */
7971 @Override
7972 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007973 final long identity = Binder.clearCallingIdentity();
7974 try {
7975 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7976 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007977 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007978 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007980 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7981 } finally {
7982 Binder.restoreCallingIdentity(identity);
7983 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007984 }
7985
7986 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007987 * Sets the per-account voicemail ringtone.
7988 *
7989 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7990 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7991 *
7992 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7993 * voicemail ringtone.
7994 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7995 * PhoneAccount.
7996 */
7997 @Override
7998 public void setVoicemailRingtoneUri(String callingPackage,
7999 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008000 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008001 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008002 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8003 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8005 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8006 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008008
8009 final long identity = Binder.clearCallingIdentity();
8010 try {
8011 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8012 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008013 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008014 }
8015 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8016 } finally {
8017 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008018 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008019 }
8020
8021 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008022 * Returns whether vibration is set for voicemail notification in Phone settings.
8023 *
8024 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8025 * voicemail vibration setting.
8026 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8027 */
8028 @Override
8029 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008030 final long identity = Binder.clearCallingIdentity();
8031 try {
8032 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8033 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008034 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008036
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008037 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8038 } finally {
8039 Binder.restoreCallingIdentity(identity);
8040 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008041 }
8042
Youhan Wange64578a2016-05-02 15:32:42 -07008043 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008044 * Sets the per-account voicemail vibration.
8045 *
8046 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8047 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8048 *
8049 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8050 * voicemail vibration setting.
8051 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8052 * specific PhoneAccount.
8053 */
8054 @Override
8055 public void setVoicemailVibrationEnabled(String callingPackage,
8056 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008057 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008058 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008059 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8060 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8062 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8063 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008064 }
8065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008066 final long identity = Binder.clearCallingIdentity();
8067 try {
8068 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8069 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008070 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008071 }
8072 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8073 } finally {
8074 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008075 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008076 }
8077
8078 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008079 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8080 *
8081 * @throws SecurityException if the caller does not have the required permission
8082 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008083 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008084 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008085 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008086 }
8087
8088 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008089 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8090 * permission.
8091 *
8092 * @throws SecurityException if the caller does not have the required permission
8093 */
8094 private void enforceSendSmsPermission() {
8095 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8096 }
8097
8098 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008099 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008100 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008101 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008102 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008103 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104 final long identity = Binder.clearCallingIdentity();
8105 try {
8106 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008107 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108 if (componentName == null) {
8109 throw new SecurityException(
8110 "Caller not current active visual voicemail package[null]");
8111 }
8112 String vvmPackage = componentName.getPackageName();
8113 if (!callingPackage.equals(vvmPackage)) {
8114 throw new SecurityException("Caller not current active visual voicemail package["
8115 + vvmPackage + "]");
8116 }
8117 } finally {
8118 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008119 }
8120 }
8121
8122 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008123 * Return the application ID for the app type.
8124 *
8125 * @param subId the subscription ID that this request applies to.
8126 * @param appType the uicc app type.
8127 * @return Application ID for specificied app type, or null if no uicc.
8128 */
8129 @Override
8130 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008131 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008132 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133
8134 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008135 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008136 if (phone == null) {
8137 return null;
8138 }
8139 String aid = null;
8140 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008141 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008142 .getApplicationByType(appType).getAid();
8143 } catch (Exception e) {
8144 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8145 }
8146 return aid;
8147 } finally {
8148 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008149 }
Youhan Wange64578a2016-05-02 15:32:42 -07008150 }
8151
Youhan Wang4001d252016-05-11 10:29:41 -07008152 /**
8153 * Return the Electronic Serial Number.
8154 *
8155 * @param subId the subscription ID that this request applies to.
8156 * @return ESN or null if error.
8157 */
8158 @Override
8159 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008160 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008161 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162
8163 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008164 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008165 if (phone == null) {
8166 return null;
8167 }
8168 String esn = null;
8169 try {
8170 esn = phone.getEsn();
8171 } catch (Exception e) {
8172 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8173 }
8174 return esn;
8175 } finally {
8176 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008177 }
Youhan Wang4001d252016-05-11 10:29:41 -07008178 }
8179
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008180 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008181 * Return the Preferred Roaming List Version.
8182 *
8183 * @param subId the subscription ID that this request applies to.
8184 * @return PRLVersion or null if error.
8185 */
8186 @Override
8187 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008188 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008189 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008190
8191 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008192 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008193 if (phone == null) {
8194 return null;
8195 }
8196 String cdmaPrlVersion = null;
8197 try {
8198 cdmaPrlVersion = phone.getCdmaPrlVersion();
8199 } catch (Exception e) {
8200 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8201 }
8202 return cdmaPrlVersion;
8203 } finally {
8204 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008205 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008206 }
8207
8208 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008209 * Get snapshot of Telephony histograms
8210 * @return List of Telephony histograms
8211 * @hide
8212 */
8213 @Override
8214 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8216 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008217
8218 final long identity = Binder.clearCallingIdentity();
8219 try {
8220 return RIL.getTelephonyRILTimingHistograms();
8221 } finally {
8222 Binder.restoreCallingIdentity(identity);
8223 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008224 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008225
8226 /**
8227 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008228 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8229 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008230 * Require system privileges. In the future we may add this to carrier APIs.
8231 *
Michele Berionne482f8202018-11-27 18:57:59 -08008232 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008233 */
8234 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008235 @TelephonyManager.SetCarrierRestrictionResult
8236 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008237 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008238 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008239
Michele Berionne482f8202018-11-27 18:57:59 -08008240 if (carrierRestrictionRules == null) {
8241 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008242 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008244 final long identity = Binder.clearCallingIdentity();
8245 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008246 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008247 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248 } finally {
8249 Binder.restoreCallingIdentity(identity);
8250 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008251 }
8252
8253 /**
8254 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008255 * Get the allowed carrier list and the excluded carrier list, including the priority between
8256 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008257 * Require system privileges. In the future we may add this to carrier APIs.
8258 *
Michele Berionne482f8202018-11-27 18:57:59 -08008259 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008260 */
8261 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008262 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008263 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008264 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008265
8266 final long identity = Binder.clearCallingIdentity();
8267 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008268 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8269 if (response instanceof CarrierRestrictionRules) {
8270 return (CarrierRestrictionRules) response;
8271 }
8272 // Response is an Exception of some kind,
8273 // which is signalled to the user as a NULL retval
8274 return null;
8275 } catch (Exception e) {
8276 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8277 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 } finally {
8279 Binder.restoreCallingIdentity(identity);
8280 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008281 }
8282
fionaxu59545b42016-05-25 15:53:37 -07008283 /**
fionaxu59545b42016-05-25 15:53:37 -07008284 * Action set from carrier signalling broadcast receivers to enable/disable radio
8285 * @param subId the subscription ID that this action applies to.
8286 * @param enabled control enable or disable radio.
8287 * {@hide}
8288 */
8289 @Override
8290 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8291 enforceModifyPermission();
8292 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293
8294 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008295 if (phone == null) {
8296 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8297 return;
8298 }
8299 try {
8300 phone.carrierActionSetRadioEnabled(enabled);
8301 } catch (Exception e) {
8302 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 } finally {
8304 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008305 }
8306 }
8307
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008308 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008309 * Enable or disable Voice over NR (VoNR)
8310 * @param subId the subscription ID that this action applies to.
8311 * @param enabled enable or disable VoNR.
8312 * @return operation result.
8313 */
8314 @Override
8315 public int setVoNrEnabled(int subId, boolean enabled) {
8316 enforceModifyPermission();
8317 final Phone phone = getPhone(subId);
8318
8319 final long identity = Binder.clearCallingIdentity();
8320 if (phone == null) {
8321 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8322 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8323 }
8324
8325 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8326 try {
8327 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8328 workSource);
8329 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008330
8331 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8332 if (DBG) {
8333 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8334 }
8335 SubscriptionManager.setSubscriptionProperty(
8336 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8337 (enabled ? "1" : "0"));
8338 }
8339
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008340 return result;
8341 } finally {
8342 Binder.restoreCallingIdentity(identity);
8343 }
8344 }
8345
8346 /**
8347 * Is voice over NR enabled
8348 * @return true if VoNR is enabled else false
8349 */
8350 @Override
8351 public boolean isVoNrEnabled(int subId) {
8352 enforceReadPrivilegedPermission("isVoNrEnabled");
8353 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8354 final long identity = Binder.clearCallingIdentity();
8355 try {
8356 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8357 null, subId, workSource);
8358 if (DBG) log("isVoNrEnabled: " + isEnabled);
8359 return isEnabled;
8360 } finally {
8361 Binder.restoreCallingIdentity(identity);
8362 }
8363 }
8364
8365 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008366 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8367 * network status based on which carrier apps could apply actions accordingly,
8368 * enable/disable default url handler for example.
8369 *
8370 * @param subId the subscription ID that this action applies to.
8371 * @param report control start/stop reporting the default network status.
8372 * {@hide}
8373 */
8374 @Override
8375 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8376 enforceModifyPermission();
8377 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008378
8379 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008380 if (phone == null) {
8381 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8382 return;
8383 }
8384 try {
8385 phone.carrierActionReportDefaultNetworkStatus(report);
8386 } catch (Exception e) {
8387 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008388 } finally {
8389 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008390 }
8391 }
8392
8393 /**
fionaxud9622282017-07-17 17:51:30 -07008394 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8395 * @param subId the subscription ID that this action applies to.
8396 * {@hide}
8397 */
8398 @Override
8399 public void carrierActionResetAll(int subId) {
8400 enforceModifyPermission();
8401 final Phone phone = getPhone(subId);
8402 if (phone == null) {
8403 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8404 return;
8405 }
8406 try {
8407 phone.carrierActionResetAll();
8408 } catch (Exception e) {
8409 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8410 }
8411 }
8412
8413 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008414 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8415 * bug report is being generated.
8416 */
8417 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008418 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008419 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8420 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008421 writer.println("Permission Denial: can't dump Phone from pid="
8422 + Binder.getCallingPid()
8423 + ", uid=" + Binder.getCallingUid()
8424 + "without permission "
8425 + android.Manifest.permission.DUMP);
8426 return;
8427 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008428 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008429 }
Jack Yueb89b242016-06-22 13:27:47 -07008430
Brad Ebingerdac2f002018-04-03 15:17:52 -07008431 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008432 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8433 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8434 @NonNull String[] args) {
8435 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8436 this, in.getFileDescriptor(), out.getFileDescriptor(),
8437 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008438 }
8439
Jack Yueb89b242016-06-22 13:27:47 -07008440 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008441 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008442 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008443 * @param reason the reason the data enable change is taking place
8444 * @param enabled True if enabling the data, otherwise disabling.
8445 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008446 */
8447 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008448 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008449 boolean enabled) {
8450 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8451 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8452 try {
8453 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008454 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008455 } catch (SecurityException se) {
8456 enforceModifyPermission();
8457 }
8458 } else {
8459 enforceModifyPermission();
8460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008461
8462 final long identity = Binder.clearCallingIdentity();
8463 try {
8464 Phone phone = getPhone(subId);
8465 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008466 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8467 phone.carrierActionSetMeteredApnsEnabled(enabled);
8468 } else {
8469 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8470 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008471 }
8472 } finally {
8473 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008474 }
8475 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008476
8477 /**
8478 * Get Client request stats
8479 * @return List of Client Request Stats
8480 * @hide
8481 */
8482 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008483 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8484 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008485 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008486 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008487 return null;
8488 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008489 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008490
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008491 final long identity = Binder.clearCallingIdentity();
8492 try {
8493 if (phone != null) {
8494 return phone.getClientRequestStats();
8495 }
8496
8497 return null;
8498 } finally {
8499 Binder.restoreCallingIdentity(identity);
8500 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008501 }
8502
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008503 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008504 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008505 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008506 }
Jack Yueb4124c2017-02-16 15:32:43 -08008507
8508 /**
Grace Chen70990072017-03-24 17:21:30 -07008509 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008510 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008511 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008512 * @param state State of SIM (power down, power up, pass through)
8513 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8514 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8515 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008516 *
8517 **/
8518 @Override
Grace Chen70990072017-03-24 17:21:30 -07008519 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008520 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008521 Phone phone = PhoneFactory.getPhone(slotIndex);
8522
vagdeviaf9a5b92018-08-15 16:01:53 -07008523 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8524
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008525 final long identity = Binder.clearCallingIdentity();
8526 try {
8527 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008528 phone.setSimPowerState(state, null, workSource);
8529 }
8530 } finally {
8531 Binder.restoreCallingIdentity(identity);
8532 }
8533 }
8534
8535 /**
8536 * Set SIM card power state.
8537 *
8538 * @param slotIndex SIM slot id.
8539 * @param state State of SIM (power down, power up, pass through)
8540 * @param callback callback to trigger after success or failure
8541 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8542 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8543 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8544 *
8545 **/
8546 @Override
8547 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8548 IIntegerConsumer callback) {
8549 enforceModifyPermission();
8550 Phone phone = PhoneFactory.getPhone(slotIndex);
8551
8552 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8553
8554 final long identity = Binder.clearCallingIdentity();
8555 try {
8556 if (phone != null) {
8557 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8558 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008559 }
8560 } finally {
8561 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008562 }
8563 }
Shuo Qiandd210312017-04-12 22:11:33 +00008564
Tyler Gunn65d45c22017-06-05 11:22:26 -07008565 private boolean isUssdApiAllowed(int subId) {
8566 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008567 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008568 if (configManager == null) {
8569 return false;
8570 }
8571 PersistableBundle pb = configManager.getConfigForSubId(subId);
8572 if (pb == null) {
8573 return false;
8574 }
8575 return pb.getBoolean(
8576 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8577 }
8578
Shuo Qiandd210312017-04-12 22:11:33 +00008579 /**
8580 * Check if phone is in emergency callback mode
8581 * @return true if phone is in emergency callback mode
8582 * @param subId sub id
8583 */
goneil9c5f4872017-12-05 14:07:56 -08008584 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008585 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008586 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008587 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008588
8589 final long identity = Binder.clearCallingIdentity();
8590 try {
8591 if (phone != null) {
8592 return phone.isInEcm();
8593 } else {
8594 return false;
8595 }
8596 } finally {
8597 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008598 }
8599 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008600
8601 /**
8602 * Get the current signal strength information for the given subscription.
8603 * Because this information is not updated when the device is in a low power state
8604 * it should not be relied-upon to be current.
8605 * @param subId Subscription index
8606 * @return the most recent cached signal strength info from the modem
8607 */
8608 @Override
8609 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008610 final long identity = Binder.clearCallingIdentity();
8611 try {
8612 Phone p = getPhone(subId);
8613 if (p == null) {
8614 return null;
8615 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008616
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008617 return p.getSignalStrength();
8618 } finally {
8619 Binder.restoreCallingIdentity(identity);
8620 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008621 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008622
Pengquan Meng77b7f132018-08-22 14:49:57 -07008623 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008624 * Get the current modem radio state for the given slot.
8625 * @param slotIndex slot index.
8626 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008627 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008628 * @return the current radio power state from the modem
8629 */
8630 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008631 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008632 Phone phone = PhoneFactory.getPhone(slotIndex);
8633 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8635 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008636 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8637 }
8638
8639 final long identity = Binder.clearCallingIdentity();
8640 try {
8641 return phone.getRadioPowerState();
8642 } finally {
8643 Binder.restoreCallingIdentity(identity);
8644 }
8645 }
8646 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8647 }
8648
8649 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008650 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8651 *
8652 * <p>Requires one of the following permissions:
8653 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8654 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8655 * privileges.
8656 *
8657 * @param subId subscription id
8658 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8659 * {@code false}.
8660 */
8661 @Override
8662 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008663 try {
8664 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8665 null);
8666 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008667 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008668 mApp, subId, "isDataRoamingEnabled");
8669 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008670
Pengquan Menga1bb6272018-09-06 09:59:22 -07008671 boolean isEnabled = false;
8672 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008673 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008674 Phone phone = getPhone(subId);
8675 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008676 } finally {
8677 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008678 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008679 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008680 }
8681
8682
8683 /**
8684 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8685 *
8686 * <p> Requires permission:
8687 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8688 * privileges.
8689 *
8690 * @param subId subscription id
8691 * @param isEnabled {@code true} means enable, {@code false} means disable.
8692 */
8693 @Override
8694 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8696 mApp, subId, "setDataRoamingEnabled");
8697
Pengquan Menga1bb6272018-09-06 09:59:22 -07008698 final long identity = Binder.clearCallingIdentity();
8699 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008700 Phone phone = getPhone(subId);
8701 if (phone != null) {
8702 phone.setDataRoamingEnabled(isEnabled);
8703 }
8704 } finally {
8705 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008706 }
8707 }
8708
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008709 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008710 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008711 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008712 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008713 mApp, subId, "isManualNetworkSelectionAllowed");
8714
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008715 boolean isAllowed = true;
8716 final long identity = Binder.clearCallingIdentity();
8717 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008718 Phone phone = getPhone(subId);
8719 if (phone != null) {
8720 isAllowed = phone.isCspPlmnEnabled();
8721 }
8722 } finally {
8723 Binder.restoreCallingIdentity(identity);
8724 }
8725 return isAllowed;
8726 }
8727
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008728 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8729 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8730 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8731 // Update each UiccPort object based on privilege access
8732 UiccPort[] uiccPorts = card.getUiccPortList();
8733 for (UiccPort port : uiccPorts) {
8734 UiccProfile profile = port.getUiccProfile();
8735 if (profile == null ||
8736 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8737 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8738 return false;
8739 }
8740 }
8741 return true;
8742 }
8743
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008744 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008745 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008746 // Verify that tha callingPackage belongs to the calling UID
8747 mApp.getSystemService(AppOpsManager.class)
8748 .checkPackage(Binder.getCallingUid(), callingPackage);
8749
Jordan Liu1e142fc2019-04-22 15:10:43 -07008750 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008751 try {
8752 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008753 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008754 } catch (SecurityException e) {
8755 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8756 // has carrier privileges on an active UICC
8757 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8758 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008759 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008760 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008761 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008762
8763 final long identity = Binder.clearCallingIdentity();
8764 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008765 UiccController uiccController = UiccController.getInstance();
8766 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008767 if (hasReadPermission) {
8768 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008769 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008770
8771 // Remove private info if the caller doesn't have access
8772 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8773 for (UiccCardInfo cardInfo : cardInfos) {
8774 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8775 // is available
8776 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008777 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8778 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8779 if (card == null || card.getUiccPortList().length == 0) {
8780 // assume no access if the card or ports are unavailable
Jordan Liu1e142fc2019-04-22 15:10:43 -07008781 filteredInfos.add(cardInfo.getUnprivileged());
8782 continue;
8783 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008784
8785 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008786 filteredInfos.add(cardInfo);
8787 } else {
8788 filteredInfos.add(cardInfo.getUnprivileged());
8789 }
8790 }
8791 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008792 } finally {
8793 Binder.restoreCallingIdentity(identity);
8794 }
8795 }
8796
8797 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008798 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008799 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008800
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008801 final long identity = Binder.clearCallingIdentity();
8802 try {
8803 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8804 if (slots == null) {
8805 Rlog.i(LOG_TAG, "slots is null.");
8806 return null;
8807 }
8808
8809 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8810 for (int i = 0; i < slots.length; i++) {
8811 UiccSlot slot = slots[i];
8812 if (slot == null) {
8813 continue;
8814 }
8815
Jordan Liu7be7e652019-05-06 18:55:02 +00008816 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008817 UiccCard card = slot.getUiccCard();
8818 if (card != null) {
8819 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008820 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008821 cardId = slot.getEid();
8822 if (TextUtils.isEmpty(cardId)) {
8823 cardId = slot.getIccId();
8824 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008825 }
8826
Jordan Liu857451f2019-05-09 16:35:35 -07008827 if (cardId != null) {
8828 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8829 // if cardId is an EID, it's all digits so this is fine
8830 cardId = IccUtils.stripTrailingFs(cardId);
8831 }
8832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008833 int cardState = 0;
8834 switch (slot.getCardState()) {
8835 case CARDSTATE_ABSENT:
8836 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8837 break;
8838 case CARDSTATE_PRESENT:
8839 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8840 break;
8841 case CARDSTATE_ERROR:
8842 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8843 break;
8844 case CARDSTATE_RESTRICTED:
8845 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8846 break;
8847 default:
8848 break;
8849
8850 }
8851
8852 infos[i] = new UiccSlotInfo(
8853 slot.isActive(),
8854 slot.isEuicc(),
8855 cardId,
8856 cardState,
8857 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008858 slot.isExtendedApduSupported(),
8859 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008860 }
8861 return infos;
8862 } finally {
8863 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008864 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008865 }
8866
8867 @Override
8868 public boolean switchSlots(int[] physicalSlots) {
8869 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008870
8871 final long identity = Binder.clearCallingIdentity();
8872 try {
8873 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8874 } finally {
8875 Binder.restoreCallingIdentity(identity);
8876 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008877 }
Jack Yu4c988042018-02-27 15:30:01 -08008878
8879 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008880 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008881 final long identity = Binder.clearCallingIdentity();
8882 try {
8883 return UiccController.getInstance().getCardIdForDefaultEuicc();
8884 } finally {
8885 Binder.restoreCallingIdentity(identity);
8886 }
8887 }
8888
Pengquan Meng85728fb2018-03-12 16:31:21 -07008889 /**
goneil47ffb6e2018-04-06 15:40:58 -07008890 * A test API to reload the UICC profile.
8891 *
8892 * <p>Requires that the calling app has permission
8893 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8894 * @hide
8895 */
8896 @Override
8897 public void refreshUiccProfile(int subId) {
8898 enforceModifyPermission();
8899
8900 final long identity = Binder.clearCallingIdentity();
8901 try {
8902 Phone phone = getPhone(subId);
8903 if (phone == null) {
8904 return;
8905 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008906 UiccPort uiccPort = phone.getUiccPort();
8907 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008908 return;
8909 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008910 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008911 if (uiccProfile == null) {
8912 return;
8913 }
8914 uiccProfile.refresh();
8915 } finally {
8916 Binder.restoreCallingIdentity(identity);
8917 }
8918 }
8919
8920 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008921 * Returns false if the mobile data is disabled by default, otherwise return true.
8922 */
8923 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008924 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008925 }
8926
8927 /**
8928 * Returns true if the data roaming is enabled by default, i.e the system property
8929 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8930 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8931 */
8932 private boolean getDefaultDataRoamingEnabled(int subId) {
8933 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008934 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008935 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008936 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8937 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8938 return isDataRoamingEnabled;
8939 }
8940
8941 /**
8942 * Returns the default network type for the given {@code subId}, if the default network type is
8943 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8944 */
8945 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008946 List<Integer> list = TelephonyProperties.default_network();
8947 int phoneId = mSubscriptionController.getPhoneId(subId);
8948 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8949 return list.get(phoneId);
8950 }
8951 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008952 }
fionaxua13278b2018-03-21 00:08:13 -07008953
8954 @Override
8955 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008956 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008957 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008958
8959 final long identity = Binder.clearCallingIdentity();
8960 try {
8961 final Phone phone = getPhone(subId);
8962 if (phone == null) {
8963 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8964 return;
8965 }
chen xueaba88a2019-03-15 13:15:10 -07008966 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8967 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008968 if (carrierPrivilegeRules == null) {
8969 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8970 } else {
8971 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8972 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008973 } finally {
8974 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008975 }
fionaxua13278b2018-03-21 00:08:13 -07008976 }
8977
8978 @Override
8979 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008980 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008981
8982 final long identity = Binder.clearCallingIdentity();
8983 try {
8984 final Phone phone = getPhone(subId);
8985 if (phone == null) {
8986 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8987 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8988 }
8989 return phone.getCarrierIdListVersion();
8990 } finally {
8991 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008992 }
fionaxua13278b2018-03-21 00:08:13 -07008993 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008994
8995 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008996 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8997 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008998 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008999 mApp, subId, callingPackage, callingFeatureId,
9000 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009001 return -1;
9002 }
9003
9004 final long identity = Binder.clearCallingIdentity();
9005 try {
9006 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9007 } finally {
9008 Binder.restoreCallingIdentity(identity);
9009 }
9010 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009011
9012 @Override
9013 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009014 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009015 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009016 mApp, subId, "getCdmaRoamingMode");
9017
9018 final long identity = Binder.clearCallingIdentity();
9019 try {
9020 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
9023 }
9024 }
9025
9026 @Override
9027 public boolean setCdmaRoamingMode(int subId, int mode) {
9028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9029 mApp, subId, "setCdmaRoamingMode");
9030
9031 final long identity = Binder.clearCallingIdentity();
9032 try {
9033 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9034 } finally {
9035 Binder.restoreCallingIdentity(identity);
9036 }
9037 }
9038
9039 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009040 public int getCdmaSubscriptionMode(int subId) {
9041 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009042 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009043 mApp, subId, "getCdmaSubscriptionMode");
9044
9045 final long identity = Binder.clearCallingIdentity();
9046 try {
9047 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9048 } finally {
9049 Binder.restoreCallingIdentity(identity);
9050 }
9051 }
9052
9053 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009054 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9056 mApp, subId, "setCdmaSubscriptionMode");
9057
9058 final long identity = Binder.clearCallingIdentity();
9059 try {
9060 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9061 } finally {
9062 Binder.restoreCallingIdentity(identity);
9063 }
9064 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009065
sqianc5eccab2018-10-19 18:46:41 -07009066 @Override
sqian8c685422019-02-22 15:55:18 -08009067 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009068 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009070 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9071 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009072 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9073 }
9074 final long identity = Binder.clearCallingIdentity();
9075 try {
sqian854d44b2018-12-12 16:48:18 -08009076 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9077 for (Phone phone: PhoneFactory.getPhones()) {
9078 if (phone.getEmergencyNumberTracker() != null
9079 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9080 emergencyNumberListInternal.put(
9081 phone.getSubId(),
9082 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9083 }
sqian11b7a0e2018-12-05 18:48:28 -08009084 }
sqian854d44b2018-12-12 16:48:18 -08009085 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009086 } finally {
9087 Binder.restoreCallingIdentity(identity);
9088 }
sqianc5eccab2018-10-19 18:46:41 -07009089 }
9090
9091 @Override
sqian8c685422019-02-22 15:55:18 -08009092 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009093 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009094 if (!exactMatch) {
9095 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009096 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009097 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009098 }
9099 final long identity = Binder.clearCallingIdentity();
9100 try {
sqian854d44b2018-12-12 16:48:18 -08009101 for (Phone phone: PhoneFactory.getPhones()) {
9102 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009103 && phone.getEmergencyNumberTracker()
9104 .isEmergencyNumber(number, exactMatch)) {
9105 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009106 }
sqian11b7a0e2018-12-05 18:48:28 -08009107 }
9108 return false;
9109 } finally {
9110 Binder.restoreCallingIdentity(identity);
9111 }
9112 }
9113
sqianf4ca7ed2019-01-15 18:32:07 -08009114 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009115 * Start emergency callback mode for GsmCdmaPhone for testing.
9116 */
9117 @Override
9118 public void startEmergencyCallbackMode() {
9119 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9120 "startEmergencyCallbackMode");
9121 enforceModifyPermission();
9122 final long identity = Binder.clearCallingIdentity();
9123 try {
9124 for (Phone phone : PhoneFactory.getPhones()) {
9125 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9126 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9127 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9128 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9129 gsmCdmaPhone.obtainMessage(
9130 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9131 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9132 }
9133 }
9134 } finally {
9135 Binder.restoreCallingIdentity(identity);
9136 }
9137 }
9138
9139 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009140 * Update emergency number list for test mode.
9141 */
9142 @Override
9143 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9144 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9145 "updateEmergencyNumberListTestMode");
9146
9147 final long identity = Binder.clearCallingIdentity();
9148 try {
9149 for (Phone phone: PhoneFactory.getPhones()) {
9150 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9151 if (tracker != null) {
9152 tracker.executeEmergencyNumberTestModeCommand(action, num);
9153 }
9154 }
9155 } finally {
9156 Binder.restoreCallingIdentity(identity);
9157 }
9158 }
9159
9160 /**
9161 * Get the full emergency number list for test mode.
9162 */
9163 @Override
9164 public List<String> getEmergencyNumberListTestMode() {
9165 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9166 "getEmergencyNumberListTestMode");
9167
9168 final long identity = Binder.clearCallingIdentity();
9169 try {
9170 Set<String> emergencyNumbers = new HashSet<>();
9171 for (Phone phone: PhoneFactory.getPhones()) {
9172 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9173 if (tracker != null) {
9174 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9175 emergencyNumbers.add(num.getNumber());
9176 }
9177 }
9178 }
9179 return new ArrayList<>(emergencyNumbers);
9180 } finally {
9181 Binder.restoreCallingIdentity(identity);
9182 }
9183 }
9184
chen xud6b45bd2018-10-30 22:27:10 -07009185 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009186 public int getEmergencyNumberDbVersion(int subId) {
9187 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9188
9189 final long identity = Binder.clearCallingIdentity();
9190 try {
9191 final Phone phone = getPhone(subId);
9192 if (phone == null) {
9193 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9194 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9195 }
9196 return phone.getEmergencyNumberDbVersion();
9197 } finally {
9198 Binder.restoreCallingIdentity(identity);
9199 }
9200 }
9201
9202 @Override
9203 public void notifyOtaEmergencyNumberDbInstalled() {
9204 enforceModifyPermission();
9205
9206 final long identity = Binder.clearCallingIdentity();
9207 try {
9208 for (Phone phone: PhoneFactory.getPhones()) {
9209 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9210 if (tracker != null) {
9211 tracker.updateOtaEmergencyNumberDatabase();
9212 }
9213 }
9214 } finally {
9215 Binder.restoreCallingIdentity(identity);
9216 }
9217 }
9218
9219 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009220 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009221 enforceActiveEmergencySessionPermission();
9222
9223 final long identity = Binder.clearCallingIdentity();
9224 try {
9225 for (Phone phone: PhoneFactory.getPhones()) {
9226 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9227 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009228 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9229 }
9230 }
9231 } finally {
9232 Binder.restoreCallingIdentity(identity);
9233 }
9234 }
9235
9236 @Override
9237 public void resetOtaEmergencyNumberDbFilePath() {
9238 enforceActiveEmergencySessionPermission();
9239
9240 final long identity = Binder.clearCallingIdentity();
9241 try {
9242 for (Phone phone: PhoneFactory.getPhones()) {
9243 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9244 if (tracker != null) {
9245 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009246 }
9247 }
9248 } finally {
9249 Binder.restoreCallingIdentity(identity);
9250 }
9251 }
9252
9253 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009254 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9255 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9256 Phone phone = getPhone(subId);
9257 if (phone == null) {
9258 return null;
9259 }
9260 final long identity = Binder.clearCallingIdentity();
9261 try {
9262 UiccProfile profile = UiccController.getInstance()
9263 .getUiccProfileForPhone(phone.getPhoneId());
9264 if (profile != null) {
9265 return profile.getCertsFromCarrierPrivilegeAccessRules();
9266 }
9267 } finally {
9268 Binder.restoreCallingIdentity(identity);
9269 }
9270 return null;
9271 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009272
9273 /**
9274 * Enable or disable a modem stack.
9275 */
9276 @Override
9277 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9278 enforceModifyPermission();
9279
9280 final long identity = Binder.clearCallingIdentity();
9281 try {
9282 Phone phone = PhoneFactory.getPhone(slotIndex);
9283 if (phone == null) {
9284 return false;
9285 } else {
9286 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9287 }
9288 } finally {
9289 Binder.restoreCallingIdentity(identity);
9290 }
9291 }
Michelecea4cf22018-12-21 15:00:11 -08009292
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009293 /**
9294 * Whether a modem stack is enabled or not.
9295 */
9296 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009297 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9298 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009299 Phone phone = PhoneFactory.getPhone(slotIndex);
9300 if (phone == null) return false;
9301
9302 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009303 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9304 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009305 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9306 }
9307
9308 final long identity = Binder.clearCallingIdentity();
9309 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009310 try {
9311 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9312 } catch (NoSuchElementException ex) {
9313 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9314 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009315 } finally {
9316 Binder.restoreCallingIdentity(identity);
9317 }
9318 }
9319
Michelecea4cf22018-12-21 15:00:11 -08009320 @Override
Michele0ea7d782019-03-19 14:58:42 -07009321 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009322 enforceModifyPermission();
9323
9324 final long identity = Binder.clearCallingIdentity();
9325 try {
9326 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009327 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009328 .commit();
9329 } finally {
9330 Binder.restoreCallingIdentity(identity);
9331 }
9332 }
9333
9334 @Override
Michele0ea7d782019-03-19 14:58:42 -07009335 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009336 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009338 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9339 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009340 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009341 }
Michelecea4cf22018-12-21 15:00:11 -08009342
9343 final long identity = Binder.clearCallingIdentity();
9344 try {
Michele0ea7d782019-03-19 14:58:42 -07009345 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009346 } finally {
9347 Binder.restoreCallingIdentity(identity);
9348 }
9349 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009350
Michele0ea7d782019-03-19 14:58:42 -07009351 @TelephonyManager.IsMultiSimSupportedResult
9352 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009353 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9354 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9355 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009356 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9357 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009358 }
9359 // Check if the hardware supports multisim functionality. If usage of multisim is not
9360 // supported by the modem, indicate that it is restricted.
9361 PhoneCapability staticCapability =
9362 mPhoneConfigurationManager.getStaticPhoneCapability();
9363 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009364 loge("isMultiSimSupportedInternal: no static configuration available");
9365 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009366 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009367 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009368 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9369 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009370 }
9371 // Check if support of multiple SIMs is restricted by carrier
9372 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009373 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009374 }
9375
Michele0ea7d782019-03-19 14:58:42 -07009376 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009377 }
9378
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009379 /**
9380 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009381 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9382 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9383 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009384 * @param numOfSims number of active sims we want to switch to
9385 */
9386 @Override
9387 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009388 if (numOfSims == 1) {
9389 enforceModifyPermission();
9390 } else {
9391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9392 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9393 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009394 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009395
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009396 try {
Michele30b57b22019-03-01 12:01:14 -08009397 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009398 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009399 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9400 return;
9401 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009402 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9403 } finally {
9404 Binder.restoreCallingIdentity(identity);
9405 }
9406 }
9407
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009408 @Override
9409 public boolean isApplicationOnUicc(int subId, int appType) {
9410 enforceReadPrivilegedPermission("isApplicationOnUicc");
9411 Phone phone = getPhone(subId);
9412 if (phone == null) {
9413 return false;
9414 }
9415 final long identity = Binder.clearCallingIdentity();
9416 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009417 UiccPort uiccPort = phone.getUiccPort();
9418 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009419 return false;
9420 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009421 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009422 if (uiccProfile == null) {
9423 return false;
9424 }
9425 if (TelephonyManager.APPTYPE_SIM <= appType
9426 && appType <= TelephonyManager.APPTYPE_ISIM) {
9427 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9428 }
9429 return false;
9430 } finally {
9431 Binder.restoreCallingIdentity(identity);
9432 }
9433 }
9434
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009435 /**
chen xub4baa772019-04-03 10:23:41 -07009436 * Get whether making changes to modem configurations will trigger reboot.
9437 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009438 */
9439 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009440 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9441 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009443 mApp, subId, callingPackage, callingFeatureId,
9444 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009445 return false;
9446 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009447 final long identity = Binder.clearCallingIdentity();
9448 try {
9449 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9450 } finally {
9451 Binder.restoreCallingIdentity(identity);
9452 }
9453 }
9454
Nathan Harold29f5f052019-02-15 13:41:57 -08009455 private void updateModemStateMetrics() {
9456 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9457 // TODO: check the state for each modem if the api is ready.
9458 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9459 }
9460
Pengquan Meng3889a572019-01-23 11:16:29 -08009461 @Override
9462 public int[] getSlotsMapping() {
9463 enforceReadPrivilegedPermission("getSlotsMapping");
9464
9465 final long identity = Binder.clearCallingIdentity();
9466 try {
9467 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9468 // All logical slots should have a mapping to a physical slot.
9469 int[] logicalSlotsMapping = new int[phoneCount];
9470 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9471 for (int i = 0; i < slotInfos.length; i++) {
9472 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9473 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9474 }
9475 }
9476 return logicalSlotsMapping;
9477 } finally {
9478 Binder.restoreCallingIdentity(identity);
9479 }
9480 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009481
9482 /**
9483 * Get the IRadio HAL Version
9484 */
9485 @Override
9486 public int getRadioHalVersion() {
9487 Phone phone = getDefaultPhone();
9488 if (phone == null) return -1;
9489 HalVersion hv = phone.getHalVersion();
9490 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9491 return hv.major * 100 + hv.minor;
9492 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009493
9494 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009495 * Get the current calling package name.
9496 * @return the current calling package name
9497 */
9498 @Override
9499 public String getCurrentPackageName() {
9500 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9501 }
9502
9503 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009504 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9505 * corresponding network requests on a subId.
9506 *
9507 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009508 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009509 * 2) APN is un-metered for this subscription, or
9510 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009511 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009512 *
9513 * @return whether data is allowed for a apn type.
9514 *
9515 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009516 */
9517 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009518 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009519 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9520 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009521
9522 // Now that all security checks passes, perform the operation as ourselves.
9523 final long identity = Binder.clearCallingIdentity();
9524 try {
9525 Phone phone = getPhone(subId);
9526 if (phone == null) return false;
9527
Jack Yu41407ee2019-05-13 16:54:09 -07009528 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009529 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9530 } finally {
9531 Binder.restoreCallingIdentity(identity);
9532 }
9533 }
9534
9535 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009536 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009537 enforceReadPrivilegedPermission("isApnMetered");
9538
9539 // Now that all security checks passes, perform the operation as ourselves.
9540 final long identity = Binder.clearCallingIdentity();
9541 try {
9542 Phone phone = getPhone(subId);
9543 if (phone == null) return true; // By default return true.
9544
Jack Yu41407ee2019-05-13 16:54:09 -07009545 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009546 } finally {
9547 Binder.restoreCallingIdentity(identity);
9548 }
9549 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009550
9551 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009552 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9553 int subscriptionId, IBooleanConsumer resultCallback) {
9554 enforceModifyPermission();
9555 long token = Binder.clearCallingIdentity();
9556 try {
9557 Phone phone = getPhone(subscriptionId);
9558 if (phone == null) {
9559 try {
9560 if (resultCallback != null) {
9561 resultCallback.accept(false);
9562 }
9563 } catch (RemoteException e) {
9564 // ignore
9565 }
9566 return;
9567 }
9568 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9569 Pair.create(specifiers, (x) -> {
9570 try {
9571 if (resultCallback != null) {
9572 resultCallback.accept(x);
9573 }
9574 } catch (RemoteException e) {
9575 // ignore
9576 }
9577 });
9578 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9579 } finally {
9580 Binder.restoreCallingIdentity(token);
9581 }
9582 }
9583
9584 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009585 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9586 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009587 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009588 mApp, subId, "getSystemSelectionChannels");
9589 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9590 final long identity = Binder.clearCallingIdentity();
9591 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009592 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9593 if (result instanceof IllegalStateException) {
9594 throw (IllegalStateException) result;
9595 }
9596 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009597 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9598 return specifiers;
9599 } finally {
9600 Binder.restoreCallingIdentity(identity);
9601 }
9602 }
9603
9604 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009605 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009606 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009607 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9608 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9609 if (iccRecords == null) {
9610 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9611 return false;
9612 }
9613 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9614 }
9615
9616 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009617 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9618 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009619 if (callingPackage == null) {
9620 callingPackage = getCurrentPackageName();
9621 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009622 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9623 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009624 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9625 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009626 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9627 }
9628 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9629 Intent intent = new Intent();
9630 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9631 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9632 // Bring up choose default SMS subscription dialog right now
9633 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9634 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9635 mApp.startActivity(intent);
9636 }
chen xud5ca2d52019-05-28 15:20:57 -07009637
9638 @Override
9639 public String getMmsUAProfUrl(int subId) {
9640 //TODO investigate if this API should require proper permission check in R b/133791609
9641 final long identity = Binder.clearCallingIdentity();
9642 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009643 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9644 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9645 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9646 return carrierUAProfUrl;
9647 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009648 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9649 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009650 } finally {
9651 Binder.restoreCallingIdentity(identity);
9652 }
9653 }
9654
9655 @Override
9656 public String getMmsUserAgent(int subId) {
9657 //TODO investigate if this API should require proper permission check in R b/133791609
9658 final long identity = Binder.clearCallingIdentity();
9659 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009660 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9661 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9662 if (!TextUtils.isEmpty(carrierUserAgent)) {
9663 return carrierUserAgent;
9664 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009665 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9666 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009667 } finally {
9668 Binder.restoreCallingIdentity(identity);
9669 }
9670 }
Jack Yub07d4972019-05-28 16:12:25 -07009671
9672 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009673 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9674 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009675
Jack Yub07d4972019-05-28 16:12:25 -07009676 final long identity = Binder.clearCallingIdentity();
9677 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009678 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009679 if (phone == null) return false;
9680
Hall Liua62f5da2020-09-25 10:42:19 -07009681 switch (policy) {
9682 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9683 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9684 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9685 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9686 default:
9687 throw new IllegalArgumentException(policy + " is not a valid policy");
9688 }
Jack Yub07d4972019-05-28 16:12:25 -07009689 } finally {
9690 Binder.restoreCallingIdentity(identity);
9691 }
9692 }
9693
9694 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009695 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009696 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009697 enforceModifyPermission();
9698
changbettyd5c246e2019-12-24 15:40:37 +08009699 final long identity = Binder.clearCallingIdentity();
9700 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009701 Phone phone = getPhone(subscriptionId);
9702 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009703
Hall Liua62f5da2020-09-25 10:42:19 -07009704 switch (policy) {
9705 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9706 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9707 break;
9708 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9709 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9710 break;
9711 default:
9712 throw new IllegalArgumentException(policy + " is not a valid policy");
9713 }
changbettyd5c246e2019-12-24 15:40:37 +08009714 } finally {
9715 Binder.restoreCallingIdentity(identity);
9716 }
9717 }
9718
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009719 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009720 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009721 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9722 * otherwise.
9723 */
9724 @Override
9725 public void setCepEnabled(boolean isCepEnabled) {
9726 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9727
9728 final long identity = Binder.clearCallingIdentity();
9729 try {
9730 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9731 for (Phone phone : PhoneFactory.getPhones()) {
9732 Phone defaultPhone = phone.getImsPhone();
9733 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9734 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9735 ImsPhoneCallTracker imsPhoneCallTracker =
9736 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9737 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9738 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9739 + imsPhone.getMsisdn());
9740 }
9741 }
9742 } finally {
9743 Binder.restoreCallingIdentity(identity);
9744 }
9745 }
allenwtsu46dcc572020-01-08 18:24:03 +08009746
9747 /**
9748 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9749 *
9750 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9751 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9752 * before being read.
9753 */
9754 @Override
9755 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9756 isCompressed) {
9757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9758 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9760 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9761 }
9762 if (!isImsAvailableOnDevice()) {
9763 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9764 "IMS not available on device.");
9765 }
9766
9767 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009768 try {
Hui Wang761a6682020-10-31 05:12:53 +00009769 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9770 } finally {
9771 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009772 }
9773 }
zoey chene02881a2019-12-30 16:11:23 +08009774
9775 @Override
9776 public boolean isIccLockEnabled(int subId) {
9777 enforceReadPrivilegedPermission("isIccLockEnabled");
9778
9779 // Now that all security checks passes, perform the operation as ourselves.
9780 final long identity = Binder.clearCallingIdentity();
9781 try {
9782 Phone phone = getPhone(subId);
9783 if (phone != null && phone.getIccCard() != null) {
9784 return phone.getIccCard().getIccLockEnabled();
9785 } else {
9786 return false;
9787 }
9788 } finally {
9789 Binder.restoreCallingIdentity(identity);
9790 }
9791 }
9792
9793 /**
9794 * Set the ICC pin lock enabled or disabled.
9795 *
9796 * @return an integer representing the status of IccLock enabled or disabled in the following
9797 * three cases:
9798 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9799 * successfully.
9800 * - Positive number and zero for remaining password attempts.
9801 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9802 *
9803 */
9804 @Override
9805 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9806 enforceModifyPermission();
9807
9808 Phone phone = getPhone(subId);
9809 if (phone == null) {
9810 return 0;
9811 }
9812 // Now that all security checks passes, perform the operation as ourselves.
9813 final long identity = Binder.clearCallingIdentity();
9814 try {
9815 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9816 new Pair<Boolean, String>(enabled, password), phone, null);
9817 return attemptsRemaining;
9818
9819 } catch (Exception e) {
9820 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9821 } finally {
9822 Binder.restoreCallingIdentity(identity);
9823 }
9824 return 0;
9825 }
9826
9827 /**
9828 * Change the ICC password used in ICC pin lock.
9829 *
9830 * @return an integer representing the status of IccLock changed in the following three cases:
9831 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9832 * - Positive number and zero for remaining password attempts.
9833 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9834 *
9835 */
9836 @Override
9837 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9838 enforceModifyPermission();
9839
9840 Phone phone = getPhone(subId);
9841 if (phone == null) {
9842 return 0;
9843 }
9844 // Now that all security checks passes, perform the operation as ourselves.
9845 final long identity = Binder.clearCallingIdentity();
9846 try {
9847 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9848 new Pair<String, String>(oldPassword, newPassword), phone, null);
9849 return attemptsRemaining;
9850
9851 } catch (Exception e) {
9852 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9853 } finally {
9854 Binder.restoreCallingIdentity(identity);
9855 }
9856 return 0;
9857 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009858
9859 /**
9860 * Request for receiving user activity notification
9861 */
9862 @Override
9863 public void requestUserActivityNotification() {
9864 if (!mNotifyUserActivity.get()
9865 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9866 mNotifyUserActivity.set(true);
9867 }
9868 }
9869
9870 /**
9871 * Called when userActivity is signalled in the power manager.
9872 * This is safe to call from any thread, with any window manager locks held or not.
9873 */
9874 @Override
9875 public void userActivity() {
9876 // ***************************************
9877 // * Inherited from PhoneWindowManager *
9878 // ***************************************
9879 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9880 // WITH ITS LOCKS HELD.
9881 //
9882 // This code must be VERY careful about the locks
9883 // it acquires.
9884 // In fact, the current code acquires way too many,
9885 // and probably has lurking deadlocks.
9886
9887 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9888 throw new SecurityException("Only the OS may call notifyUserActivity()");
9889 }
9890
9891 if (mNotifyUserActivity.getAndSet(false)) {
9892 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9893 USER_ACTIVITY_NOTIFICATION_DELAY);
9894 }
9895 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009896
9897 @Override
9898 public boolean canConnectTo5GInDsdsMode() {
9899 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9900 }
Jack Yud10cdd42020-09-28 20:28:01 -07009901
9902 @Override
9903 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9904 String callingFeatureId) {
9905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9906 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9907 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9908 }
9909
9910 Phone phone = getPhone(subId);
9911 if (phone == null) {
9912 throw new RuntimeException("phone is not available");
9913 }
9914 // Now that all security checks passes, perform the operation as ourselves.
9915 final long identity = Binder.clearCallingIdentity();
9916 try {
9917 return phone.getEquivalentHomePlmns();
9918 } finally {
9919 Binder.restoreCallingIdentity(identity);
9920 }
9921 }
Daniel Bright59e67312020-11-13 11:49:37 -08009922
9923 @Override
9924 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009925 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9926 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009927 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009928 if (radioInterfaceCapabilities == null) {
9929 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009930 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009931 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009932 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009933
Hui Wang641e81c2020-10-12 12:14:23 -07009934 @Override
9935 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9936 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009937 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9938 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9939 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9940 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9941 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009942 if (DBG) {
9943 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9944 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9945 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9946 }
9947
9948 if (!SubscriptionManager.isValidSubscriptionId(subId)
9949 || appType < TelephonyManager.APPTYPE_UNKNOWN
9950 || appType > TelephonyManager.APPTYPE_ISIM
9951 || nafUrl == null || securityProtocol == null || callback == null) {
9952 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9953 if (callback != null) {
9954 try {
9955 callback.onAuthenticationFailure(
9956 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9957 } catch (RemoteException exception) {
9958 log("Fail to notify onAuthenticationFailure due to " + exception);
9959 }
9960 return;
9961 }
9962 }
9963
9964 final long token = Binder.clearCallingIdentity();
9965 try {
9966 getGbaManager(subId).bootstrapAuthenticationRequest(
9967 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9968 forceBootStrapping, callback));
9969 } finally {
9970 Binder.restoreCallingIdentity(token);
9971 }
9972 }
9973
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009974 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009975 * Attempts to set the radio power state for all phones for thermal reason.
9976 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009977 * requested radio power state will actually be set. See {@link
9978 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9979 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009980 * @param enable {@code true} if trying to turn radio on.
9981 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9982 * false}.
9983 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009984 private boolean setRadioPowerForThermal(boolean enable) {
9985 boolean isPhoneAvailable = false;
9986 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9987 Phone phone = PhoneFactory.getPhone(i);
9988 if (phone != null) {
9989 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9990 isPhoneAvailable = true;
9991 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009992 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009993
9994 // return true if successfully informed the phone object about the thermal radio power
9995 // request.
9996 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009997 }
9998
9999 private int handleDataThrottlingRequest(int subId,
10000 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010001 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10002 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10003 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10004 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10005 throw new IllegalArgumentException("modem does not support data throttling");
10006 }
10007
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010008 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10009 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010010 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010011 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10012 }
10013
10014 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10015
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010016 if (isDataThrottlingSupported) {
10017 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010018 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010019 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10020 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10021 } else if (thermalMitigationResult
10022 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010023 log("Modem likely does not support data throttling on secondary carrier. Data " +
10024 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10025 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010026 }
10027 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010028 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010029
10030 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010031 }
10032
Jack Nudelman644b91a2021-03-12 14:09:48 -080010033 private static List<String> getThermalMitigationAllowlist(Context context) {
10034 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10035 for (String pckg : context.getResources()
10036 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10037 sThermalMitigationAllowlistedPackages.add(pckg);
10038 }
10039 }
10040
10041 return sThermalMitigationAllowlistedPackages;
10042 }
10043
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010044 private boolean isAnyPhoneInEmergencyState() {
10045 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10046 if (tm.isInEmergencyCall()) {
10047 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10048 return true;
10049 }
10050 for (Phone phone : PhoneFactory.getPhones()) {
10051 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10052 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10053 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10054 + phone.isInEcm());
10055 return true;
10056 }
10057 }
10058
10059 return false;
10060 }
10061
Jack Nudelman644b91a2021-03-12 14:09:48 -080010062 /**
10063 * Used by shell commands to add an authorized package name for thermal mitigation.
10064 * @param packageName name of package to be allowlisted
10065 * @param context
10066 */
10067 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10068 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10069 sThermalMitigationAllowlistedPackages.add(packageName);
10070 }
10071
10072 /**
10073 * Used by shell commands to remove an authorized package name for thermal mitigation.
10074 * @param packageName name of package to remove from allowlist
10075 * @param context
10076 */
10077 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10078 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10079 sThermalMitigationAllowlistedPackages.remove(packageName);
10080 }
10081
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010082 /**
10083 * Thermal mitigation request to control functionalities at modem.
10084 *
10085 * @param subId the id of the subscription.
10086 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010087 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010088 *
10089 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10090 */
10091 @Override
10092 @ThermalMitigationResult
10093 public int sendThermalMitigationRequest(
10094 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010095 ThermalMitigationRequest thermalMitigationRequest,
10096 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010097 enforceModifyPermission();
10098
Jack Nudelman644b91a2021-03-12 14:09:48 -080010099 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10100 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10101 .contains(callingPackage)) {
10102 throw new SecurityException("Calling package must be configured in the device config. "
10103 + "calling package: " + callingPackage);
10104 }
10105
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010106 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10107 final long identity = Binder.clearCallingIdentity();
10108
10109 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10110 try {
10111 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10112 switch (thermalMitigationAction) {
10113 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10114 thermalMitigationResult =
10115 handleDataThrottlingRequest(subId,
10116 thermalMitigationRequest.getDataThrottlingRequest());
10117 break;
10118 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10119 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10120 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10121 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10122 }
10123
10124 // Ensure that radio is on. If not able to power on due to phone being
10125 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010126 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010127 thermalMitigationResult =
10128 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10129 break;
10130 }
10131
10132 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10133 false);
10134 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10135 break;
10136 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10137 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10138 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10139 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10140 }
10141
10142 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10143 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010144 Phone phone = getPhone(subId);
10145 if (phone == null) {
10146 thermalMitigationResult =
10147 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10148 break;
10149 }
10150
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010151 TelephonyConnectionService service =
10152 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010153 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010154 Log.e(LOG_TAG, "An emergency call is pending");
10155 thermalMitigationResult =
10156 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10157 break;
10158 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010159 thermalMitigationResult =
10160 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10161 break;
10162 }
10163 } else {
10164 thermalMitigationResult =
10165 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10166 break;
10167 }
10168
10169 // Turn radio off. If not able to power off due to phone being unavailable,
10170 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010171 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010172 thermalMitigationResult =
10173 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10174 break;
10175 }
10176 thermalMitigationResult =
10177 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10178 break;
10179 default:
10180 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10181 + "not exist. Requested action: " + thermalMitigationAction);
10182 }
10183 } catch (IllegalArgumentException e) {
10184 throw e;
10185 } catch (Exception e) {
10186 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10187 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10188 } finally {
10189 Binder.restoreCallingIdentity(identity);
10190 }
10191
10192 if (DBG) {
10193 log("thermalMitigationRequest returning with thermalMitigationResult: "
10194 + thermalMitigationResult);
10195 }
10196
10197 return thermalMitigationResult;
10198 }
Hui Wang641e81c2020-10-12 12:14:23 -070010199
10200 /**
10201 * Set the GbaService Package Name that Telephony will bind to.
10202 *
10203 * @param subId The sim that the GbaService is associated with.
10204 * @param packageName The name of the package to be replaced with.
10205 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10206 */
10207 @Override
10208 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10209 enforceModifyPermission();
10210
10211 final long identity = Binder.clearCallingIdentity();
10212 try {
10213 return getGbaManager(subId).overrideServicePackage(packageName);
10214 } finally {
10215 Binder.restoreCallingIdentity(identity);
10216 }
10217 }
10218
10219 /**
10220 * Return the package name of the currently bound GbaService.
10221 *
10222 * @param subId The sim that the GbaService is associated with.
10223 * @return the package name of the GbaService configuration, null if GBA is not supported.
10224 */
10225 @Override
10226 public String getBoundGbaService(int subId) {
10227 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10228
10229 final long identity = Binder.clearCallingIdentity();
10230 try {
10231 return getGbaManager(subId).getServicePackage();
10232 } finally {
10233 Binder.restoreCallingIdentity(identity);
10234 }
10235 }
10236
10237 /**
10238 * Set the release time for telephony to unbind GbaService.
10239 *
10240 * @param subId The sim that the GbaService is associated with.
10241 * @param interval The release time to unbind GbaService by millisecond.
10242 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10243 */
10244 @Override
10245 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10246 enforceModifyPermission();
10247
10248 final long identity = Binder.clearCallingIdentity();
10249 try {
10250 return getGbaManager(subId).overrideReleaseTime(interval);
10251 } finally {
10252 Binder.restoreCallingIdentity(identity);
10253 }
10254 }
10255
10256 /**
10257 * Return the release time for telephony to unbind GbaService.
10258 *
10259 * @param subId The sim that the GbaService is associated with.
10260 * @return The release time to unbind GbaService by millisecond.
10261 */
10262 @Override
10263 public int getGbaReleaseTime(int subId) {
10264 enforceReadPrivilegedPermission("getGbaReleaseTime");
10265
10266 final long identity = Binder.clearCallingIdentity();
10267 try {
10268 return getGbaManager(subId).getReleaseTime();
10269 } finally {
10270 Binder.restoreCallingIdentity(identity);
10271 }
10272 }
10273
10274 private GbaManager getGbaManager(int subId) {
10275 GbaManager instance = GbaManager.getInstance(subId);
10276 if (instance == null) {
10277 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10278 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10279 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10280 }
10281 return instance;
10282 }
Hui Wang761a6682020-10-31 05:12:53 +000010283
10284 /**
10285 * indicate whether the device and the carrier can support
10286 * RCS VoLTE single registration.
10287 */
10288 @Override
10289 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010290 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10291 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10292 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10293 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010294
10295 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10296 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10297 }
10298
10299 final long identity = Binder.clearCallingIdentity();
10300 try {
10301 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10302 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010303 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10304 if (isCapable != null) {
10305 return isCapable;
10306 }
Hui Wang761a6682020-10-31 05:12:53 +000010307 }
Hui Wang67af90e2021-06-04 16:57:15 -070010308 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10309 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010310 } finally {
10311 Binder.restoreCallingIdentity(identity);
10312 }
10313 }
10314
10315 /**
10316 * Register RCS provisioning callback.
10317 */
10318 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010319 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010320 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010321 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010322 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010323 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10324 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010325
10326 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10327 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10328 }
10329 if (!isImsAvailableOnDevice()) {
10330 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10331 "IMS not available on device.");
10332 }
10333
10334 final long identity = Binder.clearCallingIdentity();
10335 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010336 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010337 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010338 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10339 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010340 }
Hui Wang761a6682020-10-31 05:12:53 +000010341 } finally {
10342 Binder.restoreCallingIdentity(identity);
10343 }
10344 }
10345
10346 /**
10347 * Unregister RCS provisioning callback.
10348 */
10349 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010350 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010351 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010352 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010353 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010354 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10355 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010356
10357 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10358 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10359 }
10360 if (!isImsAvailableOnDevice()) {
10361 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10362 "IMS not available on device.");
10363 }
10364
10365 final long identity = Binder.clearCallingIdentity();
10366 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010367 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010368 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010369 } finally {
10370 Binder.restoreCallingIdentity(identity);
10371 }
10372 }
10373
10374 /**
10375 * trigger RCS reconfiguration.
10376 */
10377 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010378 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10379 "triggerRcsReconfiguration",
10380 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010381
10382 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10383 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10384 }
10385 if (!isImsAvailableOnDevice()) {
10386 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10387 "IMS not available on device.");
10388 }
10389
10390 final long identity = Binder.clearCallingIdentity();
10391 try {
10392 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10393 } finally {
10394 Binder.restoreCallingIdentity(identity);
10395 }
10396 }
10397
10398 /**
10399 * Provide the client configuration parameters of the RCS application.
10400 */
10401 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010402 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10403 "setRcsClientConfiguration",
10404 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010405
10406 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10407 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10408 }
10409 if (!isImsAvailableOnDevice()) {
10410 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10411 "IMS not available on device.");
10412 }
10413
10414 final long identity = Binder.clearCallingIdentity();
10415
10416 try {
10417 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10418 if (configBinder == null) {
10419 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010420 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10421 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010422 } else {
10423 configBinder.setRcsClientConfiguration(rcc);
10424 }
10425 } catch (RemoteException e) {
10426 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010427 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10428 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010429 } finally {
10430 Binder.restoreCallingIdentity(identity);
10431 }
10432 }
10433
10434 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010435 * Enables or disables the test mode for RCS VoLTE single registration.
10436 */
10437 @Override
10438 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10439 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10440 "setRcsSingleRegistrationTestModeEnabled");
10441
10442 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10443 }
10444
10445 /**
10446 * Gets the test mode for RCS VoLTE single registration.
10447 */
10448 @Override
10449 public boolean getRcsSingleRegistrationTestModeEnabled() {
10450 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10451 "getRcsSingleRegistrationTestModeEnabled");
10452
10453 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10454 }
10455
10456 /**
Hui Wang761a6682020-10-31 05:12:53 +000010457 * Overrides the config of RCS VoLTE single registration enabled for the device.
10458 */
10459 @Override
10460 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10461 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10462 "setDeviceSingleRegistrationEnabledOverride");
10463 enforceModifyPermission();
10464
10465 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10466 : Boolean.parseBoolean(enabledStr);
10467 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010468 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010469 }
10470
10471 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010472 * Sends a device to device communication message. Only usable via shell.
10473 * @param message message to send.
10474 * @param value message value.
10475 */
10476 @Override
10477 public void sendDeviceToDeviceMessage(int message, int value) {
10478 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010479 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010480 enforceModifyPermission();
10481
10482 final long identity = Binder.clearCallingIdentity();
10483 try {
10484 TelephonyConnectionService service =
10485 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10486 if (service == null) {
10487 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10488 return;
10489 }
10490 service.sendTestDeviceToDeviceMessage(message, value);
10491 } finally {
10492 Binder.restoreCallingIdentity(identity);
10493 }
10494 }
10495
Tyler Gunnbabbda02021-02-10 11:05:02 -080010496 /**
10497 * Sets the specified device to device transport active.
10498 * @param transport The transport to set active.
10499 */
10500 @Override
10501 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10502 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10503 "setActiveDeviceToDeviceTransport");
10504 enforceModifyPermission();
10505
10506 final long identity = Binder.clearCallingIdentity();
10507 try {
10508 TelephonyConnectionService service =
10509 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10510 if (service == null) {
10511 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10512 return;
10513 }
10514 service.setActiveDeviceToDeviceTransport(transport);
10515 } finally {
10516 Binder.restoreCallingIdentity(identity);
10517 }
10518 }
Tyler Gunn92479152021-01-20 16:30:10 -080010519
Tyler Gunnd4339262021-05-03 14:46:49 -070010520 @Override
10521 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10522 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10523 "setDeviceToDeviceForceEnabled");
10524
10525 final long identity = Binder.clearCallingIdentity();
10526 try {
10527 Arrays.stream(PhoneFactory.getPhones()).forEach(
10528 p -> {
10529 Phone thePhone = p.getImsPhone();
10530 if (thePhone != null && thePhone instanceof ImsPhone) {
10531 ImsPhone imsPhone = (ImsPhone) thePhone;
10532 CallTracker tracker = imsPhone.getCallTracker();
10533 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10534 ImsPhoneCallTracker imsPhoneCallTracker =
10535 (ImsPhoneCallTracker) tracker;
10536 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10537 }
10538 }
10539 }
10540 );
10541 } finally {
10542 Binder.restoreCallingIdentity(identity);
10543 }
10544 }
10545
Tyler Gunn92479152021-01-20 16:30:10 -080010546 /**
Hui Wang761a6682020-10-31 05:12:53 +000010547 * Gets the config of RCS VoLTE single registration enabled for the device.
10548 */
10549 @Override
10550 public boolean getDeviceSingleRegistrationEnabled() {
10551 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10552 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10553 }
10554
10555 /**
10556 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10557 */
10558 @Override
10559 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10560 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10561 "setCarrierSingleRegistrationEnabledOverride");
10562 enforceModifyPermission();
10563
10564 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10565 : Boolean.parseBoolean(enabledStr);
10566 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10567 subId, enabled);
10568 }
10569
10570 /**
10571 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10572 */
10573 @Override
10574 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10575 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10576 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10577 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010578
10579 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010580 * Overrides the ims feature validation result
10581 */
10582 @Override
10583 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10584 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10585 "setImsFeatureValidationOverride");
10586
10587 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10588 : Boolean.parseBoolean(enabledStr);
10589 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10590 subId, enabled);
10591 }
10592
10593 /**
10594 * Gets the ims feature validation override value
10595 */
10596 @Override
10597 public boolean getImsFeatureValidationOverride(int subId) {
10598 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10599 "getImsFeatureValidationOverride");
10600 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10601 }
10602
10603 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010604 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10605 * their mobile plan.
10606 */
10607 @Override
10608 public String getMobileProvisioningUrl() {
10609 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10610 final long identity = Binder.clearCallingIdentity();
10611 try {
10612 return getDefaultPhone().getMobileProvisioningUrl();
10613 } finally {
10614 Binder.restoreCallingIdentity(identity);
10615 }
10616 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010617
James.cf Linbcdf8b32021-01-14 16:44:13 +080010618 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010619 * Get the EAB contact from the EAB database.
10620 */
10621 @Override
10622 public String getContactFromEab(String contact) {
10623 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10624 enforceModifyPermission();
10625 final long identity = Binder.clearCallingIdentity();
10626 try {
10627 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10628 } finally {
10629 Binder.restoreCallingIdentity(identity);
10630 }
10631 }
10632
10633 /**
Calvin Pana1434322021-07-01 19:27:01 +080010634 * Get the EAB capability from the EAB database.
10635 */
10636 @Override
10637 public String getCapabilityFromEab(String contact) {
10638 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10639 enforceModifyPermission();
10640 final long identity = Binder.clearCallingIdentity();
10641 try {
10642 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10643 } finally {
10644 Binder.restoreCallingIdentity(identity);
10645 }
10646 }
10647
10648 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010649 * Remove the EAB contacts from the EAB database.
10650 */
10651 @Override
10652 public int removeContactFromEab(int subId, String contacts) {
10653 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10654 enforceModifyPermission();
10655 final long identity = Binder.clearCallingIdentity();
10656 try {
10657 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10658 } finally {
10659 Binder.restoreCallingIdentity(identity);
10660 }
10661 }
10662
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010663 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010664 public boolean getDeviceUceEnabled() {
10665 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10666 final long identity = Binder.clearCallingIdentity();
10667 try {
10668 return mApp.getDeviceUceEnabled();
10669 } finally {
10670 Binder.restoreCallingIdentity(identity);
10671 }
10672 }
10673
10674 @Override
10675 public void setDeviceUceEnabled(boolean isEnabled) {
10676 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10677 final long identity = Binder.clearCallingIdentity();
10678 try {
10679 mApp.setDeviceUceEnabled(isEnabled);
10680 } finally {
10681 Binder.restoreCallingIdentity(identity);
10682 }
10683 }
10684
Brad Ebinger14d467f2021-02-12 06:18:28 +000010685 /**
10686 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10687 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10688 */
10689 // Used for SHELL command only right now.
10690 @Override
10691 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10692 List<String> featureTags) {
10693 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10694 "addUceRegistrationOverrideShell");
10695 final long identity = Binder.clearCallingIdentity();
10696 try {
10697 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10698 new ArraySet<>(featureTags));
10699 } catch (ImsException e) {
10700 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10701 } finally {
10702 Binder.restoreCallingIdentity(identity);
10703 }
10704 }
10705
10706 /**
10707 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10708 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10709 */
10710 // Used for SHELL command only right now.
10711 @Override
10712 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10713 List<String> featureTags) {
10714 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10715 "removeUceRegistrationOverrideShell");
10716 final long identity = Binder.clearCallingIdentity();
10717 try {
10718 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10719 new ArraySet<>(featureTags));
10720 } catch (ImsException e) {
10721 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10722 } finally {
10723 Binder.restoreCallingIdentity(identity);
10724 }
10725 }
10726
10727 /**
10728 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10729 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10730 */
10731 // Used for SHELL command only right now.
10732 @Override
10733 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10734 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10735 "clearUceRegistrationOverrideShell");
10736 final long identity = Binder.clearCallingIdentity();
10737 try {
10738 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10739 } catch (ImsException e) {
10740 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10741 } finally {
10742 Binder.restoreCallingIdentity(identity);
10743 }
10744 }
10745
10746 /**
10747 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10748 */
10749 // Used for SHELL command only right now.
10750 @Override
10751 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10752 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10753 "getLatestRcsContactUceCapabilityShell");
10754 final long identity = Binder.clearCallingIdentity();
10755 try {
10756 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10757 } catch (ImsException e) {
10758 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10759 } finally {
10760 Binder.restoreCallingIdentity(identity);
10761 }
10762 }
10763
10764 /**
10765 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10766 * device does not have an active PUBLISH.
10767 */
10768 // Used for SHELL command only right now.
10769 @Override
10770 public String getLastUcePidfXmlShell(int subId) {
10771 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10772 final long identity = Binder.clearCallingIdentity();
10773 try {
10774 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10775 } catch (ImsException e) {
10776 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10777 } finally {
10778 Binder.restoreCallingIdentity(identity);
10779 }
10780 }
10781
James.cf Line8713a42021-04-29 16:04:26 +080010782 /**
10783 * Remove UCE requests cannot be sent to the network status.
10784 */
10785 // Used for SHELL command only right now.
10786 @Override
10787 public boolean removeUceRequestDisallowedStatus(int subId) {
10788 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10789 final long identity = Binder.clearCallingIdentity();
10790 try {
10791 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10792 } catch (ImsException e) {
10793 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10794 } finally {
10795 Binder.restoreCallingIdentity(identity);
10796 }
10797 }
10798
James.cf Lin18bb9002021-05-25 01:37:38 +080010799 /**
10800 * Remove UCE requests cannot be sent to the network status.
10801 */
10802 // Used for SHELL command only.
10803 @Override
10804 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10805 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10806 final long identity = Binder.clearCallingIdentity();
10807 try {
10808 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10809 } catch (ImsException e) {
10810 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10811 } finally {
10812 Binder.restoreCallingIdentity(identity);
10813 }
10814 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010815
James.cf Lin4b784aa2021-01-31 03:25:15 +080010816 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010817 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10818 String callingPackage) {
10819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10820 mApp, subId, "setSignalStrengthUpdateRequest");
10821
10822 final int callingUid = Binder.getCallingUid();
10823 // Verify that tha callingPackage belongs to the calling UID
10824 mApp.getSystemService(AppOpsManager.class)
10825 .checkPackage(callingUid, callingPackage);
10826
10827 validateSignalStrengthUpdateRequest(request, callingUid);
10828
10829 final long identity = Binder.clearCallingIdentity();
10830 try {
10831 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10832 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10833
10834 if (result instanceof IllegalStateException) {
10835 throw (IllegalStateException) result;
10836 }
10837 } finally {
10838 Binder.restoreCallingIdentity(identity);
10839 }
10840 }
10841
10842 @Override
10843 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10844 String callingPackage) {
10845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10846 mApp, subId, "clearSignalStrengthUpdateRequest");
10847
10848 final int callingUid = Binder.getCallingUid();
10849 // Verify that tha callingPackage belongs to the calling UID
10850 mApp.getSystemService(AppOpsManager.class)
10851 .checkPackage(callingUid, callingPackage);
10852
10853 final long identity = Binder.clearCallingIdentity();
10854 try {
10855 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10856 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10857
10858 if (result instanceof IllegalStateException) {
10859 throw (IllegalStateException) result;
10860 }
10861 } finally {
10862 Binder.restoreCallingIdentity(identity);
10863 }
10864 }
10865
10866 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10867 int callingUid) {
10868 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10869 // phone/system process do not have further restriction on request
10870 return;
10871 }
10872
10873 // Applications has restrictions on how to use the request:
10874 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10875 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10876 // This is not system caller which has been checked above
10877 throw new IllegalArgumentException(
10878 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10879 }
10880
10881 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10882 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10883 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10884 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10885 || info.isEnabled()) {
10886 throw new IllegalArgumentException(
10887 "Only system can set hide fields in SignalThresholdInfo");
10888 }
10889
10890 // Thresholds length for each RAN need in range. This has been validated in
10891 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10892 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10893 final int[] thresholds = info.getThresholds();
10894 Objects.requireNonNull(thresholds);
10895 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10896 || thresholds.length
10897 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10898 throw new IllegalArgumentException(
10899 "thresholds length is out of range: " + thresholds.length);
10900 }
10901 }
10902 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010903
10904 /**
10905 * Gets the current phone capability.
10906 *
10907 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10908 * @return the PhoneCapability which describes the data connection capability of modem.
10909 * It's used to evaluate possible phone config change, for example from single
10910 * SIM device to multi-SIM device.
10911 */
10912 @Override
10913 public PhoneCapability getPhoneCapability() {
10914 enforceReadPrivilegedPermission("getPhoneCapability");
10915 final long identity = Binder.clearCallingIdentity();
10916 try {
10917 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10918 } finally {
10919 Binder.restoreCallingIdentity(identity);
10920 }
10921 }
Michele Berionne5e411512020-11-13 02:36:59 +000010922
10923 /**
10924 * Prepare TelephonyManager for an unattended reboot. The reboot is
10925 * required to be done shortly after the API is invoked.
10926 */
10927 @Override
10928 @TelephonyManager.PrepareUnattendedRebootResult
10929 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010930 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000010931 enforceRebootPermission();
10932
10933 final long identity = Binder.clearCallingIdentity();
10934 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010935 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000010936 } finally {
10937 Binder.restoreCallingIdentity(identity);
10938 }
10939 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010940
10941 /**
10942 * Request to get the current slicing configuration including URSP rules and
10943 * NSSAIs (configured, allowed and rejected).
10944 *
10945 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10946 */
10947 @Override
10948 public void getSlicingConfig(ResultReceiver callback) {
10949 enforceReadPrivilegedPermission("getSlicingConfig");
10950
10951 final long identity = Binder.clearCallingIdentity();
10952 try {
10953 Phone phone = getDefaultPhone();
10954 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10955 } finally {
10956 Binder.restoreCallingIdentity(identity);
10957 }
10958 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000010959
10960 /**
10961 * Register an IMS connection state callback
10962 */
10963 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000010964 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
10965 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000010966 if (feature == ImsFeature.FEATURE_MMTEL) {
10967 // ImsMmTelManager
10968 // The following also checks READ_PRIVILEGED_PHONE_STATE.
10969 TelephonyPermissions
10970 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
10971 mApp, subId, "registerImsStateCallback");
10972 } else if (feature == ImsFeature.FEATURE_RCS) {
10973 // ImsRcsManager or SipDelegateManager
10974 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10975 Binder.getCallingUid(), "registerImsStateCallback",
10976 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
10977 Manifest.permission.READ_PRECISE_PHONE_STATE,
10978 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
10979 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
10980 }
10981
10982 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
10983 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10984 "IMS not available on device.");
10985 }
10986
10987 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
10988 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
10989 }
10990
10991 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
10992 if (controller == null) {
10993 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10994 "IMS not available on device.");
10995 }
10996
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000010997 if (callingPackage == null) {
10998 callingPackage = getCurrentPackageName();
10999 }
11000
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011001 final long token = Binder.clearCallingIdentity();
11002 try {
11003 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011004 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011005 } catch (ImsException e) {
11006 throw new ServiceSpecificException(e.getCode());
11007 } finally {
11008 Binder.restoreCallingIdentity(token);
11009 }
11010 }
11011
11012 /**
11013 * Unregister an IMS connection state callback
11014 */
11015 @Override
11016 public void unregisterImsStateCallback(IImsStateCallback cb) {
11017 final long token = Binder.clearCallingIdentity();
11018 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11019 if (controller == null) {
11020 return;
11021 }
11022 try {
11023 controller.unregisterImsStateCallback(cb);
11024 } finally {
11025 Binder.restoreCallingIdentity(token);
11026 }
11027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011028}